List of usage examples for javax.security.auth.callback PasswordCallback PasswordCallback
public PasswordCallback(String prompt, boolean echoOn)
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 . j a 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: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 w w w . j a v a2s. c om 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:info.magnolia.jaas.sp.jcr.JCRAuthenticationModule.java
/** * Authenticate against magnolia/jcr user repository *//*www . j a v a2 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 ww . j av a 2s .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 {/*ww w . jav a 2 s . com*/ 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 w w .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 {// www . j av a2s. c o m _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"); }// w ww .ja v a2s. 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()); } }
From source file:org.apache.felix.karaf.jaas.modules.properties.PropertiesLoginModule.java
public boolean login() throws LoginException { Properties users = new Properties(); File f = new File(usersFile); try {/*from ww w . j a v a2 s . c o m*/ users.load(new java.io.FileInputStream(f)); } catch (IOException ioe) { throw new LoginException("Unable to load user properties file " + f); } Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("Username: "); callbacks[1] = new PasswordCallback("Password: ", false); try { callbackHandler.handle(callbacks); } catch (IOException ioe) { throw new LoginException(ioe.getMessage()); } catch (UnsupportedCallbackException uce) { throw new LoginException(uce.getMessage() + " not available to obtain information from user"); } user = ((NameCallback) callbacks[0]).getName(); char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword(); if (tmpPassword == null) { tmpPassword = new char[0]; } String userInfos = (String) users.get(user); if (userInfos == null) { throw new FailedLoginException("User does not exist"); } String[] infos = userInfos.split(","); if (!new String(tmpPassword).equals(infos[0])) { throw new FailedLoginException("Password does not match"); } principals = new HashSet<Principal>(); principals.add(new UserPrincipal(user)); for (int i = 1; i < infos.length; i++) { principals.add(new RolePrincipal(infos[i])); } users.clear(); if (debug) { LOG.debug("login " + user); } return true; }
From source file:cz.ceskaexpedice.k5.k5jaas.basic.K5LoginModule.java
@Override public boolean login() throws LoginException { try {/*from w ww .j a v a 2s .c om*/ NameCallback nmCallback = new NameCallback("Name"); PasswordCallback pswdCallback = new PasswordCallback("Password", false); this.callbackhandler.handle(new Callback[] { nmCallback, pswdCallback }); String loginName = nmCallback.getName(); this.remoteLoginName = loginName; char[] pswd = pswdCallback.getPassword(); this.remotePassword = new String(pswd); URLConnection connection = openConnection(this.loginAddress, loginName, new String(pswd)); InputStream is = connection.getInputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); copyStreams(is, bos); String str = new String(bos.toByteArray(), "UTF-8"); JSONObject obj = new JSONObject(str); this.logged = testLogged(obj); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (UnsupportedCallbackException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (JSONException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } return this.logged; }