List of usage examples for javax.security.auth.callback NameCallback NameCallback
public NameCallback(String prompt)
From source file:org.marketcetera.client.MockLoginModule.java
@Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("Name"); callbacks[1] = new PasswordCallback("Password", false); try {/* w w w.ja v a 2s . c o m*/ callback.handle(callbacks); } catch (UnsupportedCallbackException e) { final LoginException ex = new FailedLoginException(e.getMessage()); ex.initCause(e); throw ex; } catch (IOException e) { final LoginException ex = new FailedLoginException(e.getMessage()); ex.initCause(e); throw ex; } username = ((NameCallback) callbacks[0]).getName(); char[] password = ((PasswordCallback) callbacks[1]).getPassword(); String pass = String.valueOf(password); if (!ObjectUtils.equals(username, pass)) { throw new FailedLoginException(username + "<>" + pass); } SLF4JLoggerProxy.debug(this, "login done for user {}", username); //$NON-NLS-1$ return true; }
From source file:be.fedict.eid.applet.beta.service.AuthorizationLoginModule.java
public boolean login() throws LoginException { NameCallback nameCallback = new NameCallback("Username"); Callback[] callbacks = new Callback[] { nameCallback }; try {/*from ww w . ja v a 2 s. c om*/ this.callbackHandler.handle(callbacks); } catch (Exception e) { throw new LoginException("JAAS callback error: " + e.getMessage()); } String name = nameCallback.getName(); this.principal = new NamePrincipal(name); LOG.debug("login: " + name); return true; }
From source file:org.alejandria.security.auth.JAASLocalAuthModule.java
@Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("user"); callbacks[1] = new PasswordCallback("password", true); try {//from ww w .j a va 2 s .c o m this.handler.handle(callbacks); String user = ((NameCallback) callbacks[0]).getName(); String password = String.valueOf(((PasswordCallback) callbacks[1]).getPassword()); if (user != null && password != null) { //manage user and password with database ApplicationContext ctx = ApplicationContextProvider.getSpringApplicationContext(); userService = ctx.getBean(UsuarioService.class); if (userService.authenticateUser(user, password)) { subject.getPrincipals().add(new UserPrincipal(user)); return true; } } } catch (IOException ex) { ex.printStackTrace(); throw new LoginException(ex.getMessage()); } catch (UnsupportedCallbackException ex) { throw new LoginException(ex.getMessage()); } return false; }
From source file:de.tbosch.tools.googleapps.oauth2.OAuth2SaslClient.java
@Override public byte[] evaluateChallenge(byte[] challenge) throws SaslException { if (isComplete) { // Empty final response from server, just ignore it. return new byte[] {}; }/*from w w w .j av a2 s. c o m*/ NameCallback nameCallback = new NameCallback("Enter name"); Callback[] callbacks = new Callback[] { nameCallback }; try { callbackHandler.handle(callbacks); } catch (UnsupportedCallbackException e) { throw new SaslException("Unsupported callback: " + e); } catch (IOException e) { throw new SaslException("Failed to execute callback: " + e); } String email = nameCallback.getName(); byte[] response = String.format("user=%s\1auth=Bearer %s\1\1", email, oauthToken).getBytes(); isComplete = true; return response; }
From source file:info.magnolia.jaas.sp.jcr.JCRAuthenticationModule.java
/** * Authenticate against magnolia/jcr user repository *//*w w w . jav a 2 s . c o m*/ public boolean login() throws LoginException { if (this.callbackHandler == null) { throw new LoginException("Error: no CallbackHandler available for JCRModule"); } Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("name"); callbacks[1] = new PasswordCallback("pswd", false); this.success = false; try { this.callbackHandler.handle(callbacks); this.name = ((NameCallback) callbacks[0]).getName(); this.pswd = ((PasswordCallback) callbacks[1]).getPassword(); this.success = this.isValidUser(); } catch (IOException ioe) { if (log.isDebugEnabled()) { log.debug("Exception caught", ioe); } throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException ce) { if (log.isDebugEnabled()) { log.debug(ce.getMessage(), ce); } throw new LoginException(ce.getCallback().toString() + " not available"); } if (!this.success) { throw new LoginException("failed to authenticate " + this.name); } return this.success; }
From source file:be.fedict.hsm.model.security.AdministratorLoginModule.java
@Override public boolean login() throws LoginException { LOG.debug("login"); NameCallback nameCallback = new NameCallback("username"); PasswordCallback passwordCallback = new PasswordCallback("password", false); Callback[] callbacks = new Callback[] { nameCallback, passwordCallback }; try {/*w w w . j av a2s . c o m*/ this.callbackHandler.handle(callbacks); } catch (Exception e) { throw new LoginException(e.getMessage()); } String username = nameCallback.getName(); String cardNumber = new String(passwordCallback.getPassword()); String authenticatedAdministrator = this.administratorSecurityBean.getAuthenticatedAdministrator(username, cardNumber); if (null == authenticatedAdministrator) { throw new LoginException("invalid administrator: " + username); } this.authenticatedAdministrator = authenticatedAdministrator; return true; }
From source file:be.fedict.hsm.model.security.ApplicationLoginModule.java
@Override public boolean login() throws LoginException { LOG.debug("login"); NameCallback nameCallback = new NameCallback("username"); PasswordCallback passwordCallback = new PasswordCallback("password", false); Callback[] callbacks = new Callback[] { nameCallback, passwordCallback }; try {//from w w w .j a v a2s. c om this.callbackHandler.handle(callbacks); } catch (Exception e) { throw new LoginException(e.getMessage()); } String username = nameCallback.getName(); char[] credential = passwordCallback.getPassword(); String authenticatedApplication = this.applicationSecurityBean.getAuthenticatedApplication(username, credential); if (null == authenticatedApplication) { throw new LoginException("invalid application: " + username); } this.authenticatedApplication = authenticatedApplication; return true; }
From source file:org.sofun.core.api.security.SofunLoginModule.java
@Override public boolean login() throws LoginException { NameCallback nameCallback = new NameCallback("Username"); PasswordCallback passwordCallback = new PasswordCallback("Password", false); Callback[] callbacks = new Callback[] { nameCallback, passwordCallback }; try {/*w ww.j a v a2 s.c o m*/ callbackHandler.handle(callbacks); } catch (IOException e) { throw new LogConfigurationException(e); } catch (UnsupportedCallbackException e) { throw new LogConfigurationException(e); } username = nameCallback.getName(); /* * Member member; try { member = getMemberService().getMember(username); } catch (CoreException e) { throw new * LoginException(e.getMessage()); } * * final char[] password = passwordCallback.getPassword(); passwordCallback.clearPassword(); * * * if (member.getPassword() != null) { final char[] mPassword = member.getPassword().toCharArray(); if * (mPassword.equals(password)) { user = new SofunPrincipal(username); roles = new SofunPrincipal[] { new * SofunPrincipal(SofunRoles.MEMBER) }; loginSucceeded = true; } else { loginSucceeded = false; } } else { * loginSucceeded = false; } */ // XXX: JAAS authentication. Application level responsibility for the moment // This is principal is not used. We rely on oauth token exchange as well application level credentials for now. user = new SofunPrincipal("admin@sofungaming.com"); roles = new SofunPrincipal[] { new SofunPrincipal(SofunRoles.MEMBER) }; loginSucceeded = true; return loginSucceeded; }
From source file:de.ingrid.admin.security.AbstractLoginModule.java
@Override public boolean login() throws LoginException { NameCallback nameCallback = new NameCallback("user name:"); PasswordCallback passwordCallback = new PasswordCallback("password:", false); try {/*from w w w . ja v a 2 s .com*/ _callbackHandler.handle(new Callback[] { nameCallback, passwordCallback }); String name = nameCallback.getName(); char[] password = passwordCallback.getPassword(); if (name != null) { if (password != null) { IngridPrincipal ingridPrincipal = authenticate(name, new String(password)); if (ingridPrincipal.isAuthenticated()) { setAuthenticated(true); _currentPrincipal = ingridPrincipal; } } } } catch (Exception e) { LOG.error("login failed.", e); throw new LoginException(e.getMessage()); } return isAuthenticated(); }
From source file:com.trailmagic.user.UserLoginModule.java
public boolean login() throws LoginException { s_log.debug("UserLoginModule.login called!!"); if (m_handler == null) { throw new LoginException("Error: no CallbackHandler available"); }//from w ww . j a va2 s.c o m try { Callback[] callbacks = new Callback[] { new NameCallback("User: "), new PasswordCallback("Password: ", false) }; m_handler.handle(callbacks); String username = ((NameCallback) callbacks[0]).getName(); char[] password = ((PasswordCallback) callbacks[1]).getPassword(); ((PasswordCallback) callbacks[1]).clearPassword(); // do app-specific validation m_success = validate(username, password); callbacks[0] = null; callbacks[1] = null; return m_success; } catch (Exception e) { s_log.error("Error processing login", e); throw new LoginException(e.getMessage()); } }