List of usage examples for javax.security.auth.callback PasswordCallback getPassword
public char[] getPassword()
From source file:org.apache.ranger.authentication.unix.jaas.PamLoginModule.java
private void initPassword(PasswordCallback passwordCallback) { char[] password = passwordCallback.getPassword(); if (password != null) { _password = new String(password); }//from w w w . ja va 2 s .c om passwordCallback.clearPassword(); }
From source file:com.flexive.core.security.FxDefaultLogin.java
/** * Verify the name/password combination. * * @return true always, since this LoginModule should not be ignored. * @throws FailedLoginException if the authentication fails. * @throws LoginException if this LoginModule is unable to perform the authentication. *//*from ww w . j a v a 2s . co m*/ @Override public boolean login() throws LoginException { LoginException le = null; try { // Determine username and password using the callback handler final Callback[] callbacks = new Callback[] { new NameCallback("user: "), new PasswordCallback("password: ", true), new FxCallback() }; callbackHandler.handle(callbacks); FxCallback ac = ((FxCallback) callbacks[2]); final String username = ((NameCallback) callbacks[0]).getName(); final PasswordCallback pc = (PasswordCallback) callbacks[1]; final String password = new String((pc.getPassword())); pc.clearPassword(); UserTicket ticket = FxAuthenticationHandler.login(username, password, ac); // Set the credentials and principals this.tempPrincipals.add(new FxPrincipal(ticket)); // The login was successfull success = true; if (LOG.isInfoEnabled()) LOG.info("User [" + ticket.getUserName() + "] successfully logged in, ticket=" + ticket); } catch (IOException exc) { le = new FxLoginFailedException("IOException: " + exc.getMessage(), FxLoginFailedException.TYPE_UNKNOWN_ERROR); LOG.error(le); } catch (UnsupportedCallbackException exc) { le = new FxLoginFailedException("IOException: " + exc.getMessage(), FxLoginFailedException.TYPE_UNKNOWN_ERROR); LOG.error(le); } // Log and throw exceptions if (le != null) { success = false; throw le; } return true; }
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 www. j a va2s. co 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:cz.ceskaexpedice.k5.k5jaas.basic.K5LoginModule.java
@Override public boolean login() throws LoginException { try {/*from www . ja va 2s. c o m*/ 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; }
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 .j a va 2 s. co m*/ 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: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 a va 2 s. 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:gov.nih.nci.ncicb.cadsr.common.security.jboss.DBLoginModule.java
protected String[] getUsernameAndPassword() throws LoginException { String[] info = { null, null }; if (callbackHandler == null) { throw new LoginException("Error: no CallbackHandler available to collect authentication information"); }/*from w w w . ja v a 2 s . c o m*/ NameCallback nc = new NameCallback("User name: ", "guest"); PasswordCallback pc = new PasswordCallback("Password: ", false); Callback[] callbacks = { nc, pc }; String username = null; String password = null; try { callbackHandler.handle(callbacks); username = nc.getName(); char[] tmpPassword = pc.getPassword(); if (tmpPassword != null) { credential = new char[tmpPassword.length]; System.arraycopy(tmpPassword, 0, credential, 0, tmpPassword.length); pc.clearPassword(); password = new String(credential); } } catch (IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("CallbackHandler does not support: " + uce.getCallback()); } info[0] = username; info[1] = password; logger.debug("Username=" + username); return info; }
From source file:com.redhat.topicindex.security.FedoraAccountSystem.java
public boolean login() throws LoginException { if (callbackHandler == null) throw new LoginException("No CallbackHandler available"); NameCallback nameCallback = new NameCallback("Username"); PasswordCallback passwordCallback = new PasswordCallback("Password", false); Callback[] callbacks = new Callback[] { nameCallback, passwordCallback }; try {/*w w w . j a va2 s .c o m*/ callbackHandler.handle(callbacks); username = nameCallback.getName(); password = passwordCallback.getPassword(); passwordCallback.clearPassword(); } catch (IOException e) { throw new LoginException(e.toString()); } catch (UnsupportedCallbackException e) { throw new LoginException("Error: " + e.getCallback().toString() + "not available"); } if (authenticate()) { loginSucceeded = true; } else { return false; } return true; }
From source file:org.opensc.pkcs11.PKCS11SessionStore.java
/** * This method allows you to authenticate you against the token as the security officer * for read/write access to the token, if the initial call to * {@link #open(LoadStoreParameter)} did not contain a SO * ProtectionParameter./*from w ww . j a v a 2 s. co m*/ * * @param param The protection parameters used to do SO (security officer) authentication. * * @see PKCS11LoadStoreParameter#getSOProtectionParameter() */ public void authenticateSO(ProtectionParameter param) throws IOException { try { if (param instanceof PasswordProtection) { PasswordProtection pp = (PasswordProtection) param; changeEvent(PKCS11EventCallback.SO_PIN_AUTHENTICATION_IN_PROGRESS); this.session.loginSO(pp.getPassword()); changeEvent(PKCS11EventCallback.SO_AUHENTICATION_SUCEEDED); } else if (param instanceof CallbackHandlerProtection) { CallbackHandlerProtection cbhp = (CallbackHandlerProtection) param; char[] pin = null; // do authenticate with the protected auth method of the token, // if this is possible, otherwise use the callback to authenticate. if (this.slot.hasTokenProtectedAuthPath()) { changeEvent(PKCS11EventCallback.SO_HW_AUTHENTICATION_IN_PROGRESS); } else { changeEvent(PKCS11EventCallback.WAITING_FOR_SW_SO_PIN); CallbackHandler cbh = cbhp.getCallbackHandler(); PasswordCallback pcb = new PasswordCallback("Please enter the SO pin:", false); cbh.handle(new Callback[] { pcb }); pin = pcb.getPassword(); changeEvent(PKCS11EventCallback.SO_PIN_AUTHENTICATION_IN_PROGRESS); } this.session.loginSO(pin); changeEvent(PKCS11EventCallback.SO_AUHENTICATION_SUCEEDED); } } catch (UnsupportedCallbackException e) { throw new PKCS11Exception("PasswordCallback is not supported", e); } }
From source file:de.adorsys.oauth.loginmodule.HTTPAuthenticationLoginModule.java
@Override public boolean login() throws LoginException { NameCallback nameCallback = new NameCallback("name"); PasswordCallback passwordCallback = new PasswordCallback("password", false); try {//from ww w. jav a 2s . c om callbackHandler.handle(new Callback[] { nameCallback, passwordCallback }); } catch (Exception x) { throw new LoginException(x.getMessage()); } String username = nameCallback.getName(); char[] passwordChars = passwordCallback.getPassword(); String password = passwordChars == null ? null : new String(passwordChars); LOG.info("login {}", username); try { return authenticate(username, password); } catch (Exception e) { throw new LoginException(e.getMessage()); } }