List of usage examples for javax.security.auth.callback UnsupportedCallbackException getCallback
public Callback getCallback()
From source file:info.magnolia.jaas.sp.jcr.JCRAuthenticationModule.java
/** * Authenticate against magnolia/jcr user repository *///from ww w. j a va2 s . com 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: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. j av a 2s .com 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:info.magnolia.jaas.sp.AbstractLoginModule.java
@Override public boolean login() throws LoginException { if (this.getSkip()) { return true; }/* w ww . j av a 2 s .co m*/ if (this.callbackHandler == null) { throw new LoginException("Error: no CallbackHandler available"); } Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("name"); callbacks[1] = new PasswordCallback("pswd", false); // if the realm is not defined in the jaas configuration // we ask use a callback to get the value if (this.useRealmCallback) { callbacks = (Callback[]) ArrayUtils.add(callbacks, new RealmCallback()); } this.success = false; try { this.callbackHandler.handle(callbacks); this.name = ((NameCallback) callbacks[0]).getName(); this.pswd = ((PasswordCallback) callbacks[1]).getPassword(); if (this.useRealmCallback) { String aRealm = ((RealmCallback) callbacks[2]).getRealm(); this.realm = StringUtils.isBlank(aRealm) ? this.realm : Realm.Factory.newRealm(aRealm); } this.validateUser(); } catch (IOException ioe) { log.debug("Exception caught", ioe); throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException ce) { log.debug(ce.getMessage(), ce); throw new LoginException(ce.getCallback().toString() + " not available"); } // TODO: should not we set success BEFORE calling validateUser to give it chance to decide whether to throw an exception or reset the value to false? this.success = true; this.setSharedStatus(STATUS_SUCCEEDED); return this.success; }
From source file:com.ibm.tivoli.tuna.jaas.sample.SampleLoginModule.java
/** * Authenticate the user by prompting for a user name and password. * //from w w w . j a v a2s . c om * <p> * * @return true in all cases since this <code>LoginModule</code> should not be * ignored. * * @exception FailedLoginException * if the authentication fails. * <p> * * @exception LoginException * if this <code>LoginModule</code> is unable to perform the * authentication. */ public boolean login() throws LoginException { // prompt for a user name and password if (callbackHandler == null) throw new LoginException( "Error: no CallbackHandler available " + "to garner authentication information from the user"); Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("user name: "); callbacks[1] = new PasswordCallback("password: ", false); try { callbackHandler.handle(callbacks); username = ((NameCallback) callbacks[0]).getName(); char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword(); if (tmpPassword == null) { // treat a NULL password as an empty password tmpPassword = new char[0]; } password = new char[tmpPassword.length]; System.arraycopy(tmpPassword, 0, password, 0, tmpPassword.length); ((PasswordCallback) callbacks[1]).clearPassword(); } catch (java.io.IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user"); } // print debugging information if (debug) { log.info("\t\t[SampleLoginModule] " + "user entered user name: " + username); log.info("\t\t[SampleLoginModule] " + "user entered password: "); } // verify the username/password boolean usernameCorrect = false; boolean passwordCorrect = false; if (username.equals("testUser")) usernameCorrect = true; if (usernameCorrect && password.length == 12 && password[0] == 't' && password[1] == 'e' && password[2] == 's' && password[3] == 't' && password[4] == 'P' && password[5] == 'a' && password[6] == 's' && password[7] == 's' && password[8] == 'w' && password[9] == 'o' && password[10] == 'r' && password[11] == 'd') { // authentication succeeded!!! passwordCorrect = true; if (debug) log.info("\t\t[SampleLoginModule] " + "authentication succeeded"); succeeded = true; return true; } else { // authentication failed -- clean out state if (debug) log.info("\t\t[SampleLoginModule] " + "authentication failed"); succeeded = false; username = null; for (int i = 0; i < password.length; i++) password[i] = ' '; password = null; if (!usernameCorrect) { throw new FailedLoginException("User Name Incorrect"); } else { throw new FailedLoginException("Password Incorrect"); } } }
From source file:net.ontopia.topicmaps.nav2.realm.TMLoginModule.java
/** * Prompt the user for username and password, and verify those. *///w w w . j av a 2 s .c o m @Override public boolean login() throws LoginException { log.debug("TMLoginModule: login"); if (callbackHandler == null) throw new LoginException( "Error: no CallbackHandler available " + "to garner authentication information from the user"); // prompt for a user name and password NameCallback nameCallback = new NameCallback("user name: "); PasswordCallback passwordCallback = new PasswordCallback("password: ", false); try { callbackHandler.handle(new Callback[] { nameCallback, passwordCallback }); this.username = nameCallback.getName(); char[] charpassword = passwordCallback.getPassword(); password = (charpassword == null ? "" : new String(charpassword)); passwordCallback.clearPassword(); } catch (java.io.IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback() + " not available to garner authentication information " + "from the user"); } // verify the username/password loginSucceeded = verifyUsernamePassword(username, password); return loginSucceeded; }
From source file:client.SampleLoginModule.java
/** * Authenticate the user by prompting for a user name and password. * //w ww . ja va 2 s .c o m * <p> * * @return true in all cases since this <code>LoginModule</code> should * not be ignored. * * @exception FailedLoginException * if the authentication fails. * <p> * * @exception LoginException * if this <code>LoginModule</code> is unable to perform * the authentication. */ public boolean login() throws LoginException { // prompt for a user name and password if (callbackHandler == null) throw new LoginException( "Error: no CallbackHandler available " + "to garner authentication information from the user"); Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("user name: "); callbacks[1] = new PasswordCallback("password: ", false); try { callbackHandler.handle(callbacks); username = ((NameCallback) callbacks[0]).getName(); String tmpPassword = String.copyValueOf(((PasswordCallback) callbacks[1]).getPassword()); if (tmpPassword == null) { // treat a NULL password as an empty password tmpPassword = ""; } password = tmpPassword; //System.arraycopy(tmpPassword, 0, password, 0, tmpPassword.length()); ((PasswordCallback) callbacks[1]).clearPassword(); } catch (java.io.IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user"); } // print debugging information if (debug) { System.out.println("\t\t[SampleLoginModule] " + "user entered user name: " + username); System.out.print("\t\t[SampleLoginModule] " + "user entered password: "); for (int i = 0; i < password.length(); i++) System.out.print(password.toCharArray()[i]); System.out.println(); } cmdAuthent.setUsern(username); cmdAuthent.setPassw(password); cmdAuthent.execute(); return cmdAuthent.getRes(); }
From source file:com.ibm.tivoli.tuna.jaas.ldap.LdapLoginModule.java
/** * Authenticate the user by prompting for a user name and password. * /*from w ww. j a v a 2 s.c o m*/ * <p> * * @return true in all cases since this <code>LoginModule</code> should not be * ignored. * * @exception FailedLoginException * if the authentication fails. * <p> * * @exception LoginException * if this <code>LoginModule</code> is unable to perform the * authentication. */ public boolean login() throws LoginException { // prompt for a user name and password if (callbackHandler == null) throw new LoginException( "Error: no CallbackHandler available " + "to garner authentication information from the user"); Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("user name: "); callbacks[1] = new PasswordCallback("password: ", false); try { callbackHandler.handle(callbacks); username = ((NameCallback) callbacks[0]).getName(); char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword(); if (tmpPassword == null) { // treat a NULL password as an empty password tmpPassword = new char[0]; } password = new char[tmpPassword.length]; System.arraycopy(tmpPassword, 0, password, 0, tmpPassword.length); ((PasswordCallback) callbacks[1]).clearPassword(); } catch (java.io.IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user"); } // print debugging information log.debug("\t\t[LdapLoginModule] " + "user entered user name: " + username); log.debug("\t\t[LdapLoginModule] " + "user entered password: "); // verify the username/password //LdapServiceDao ldapService = new LdapServiceDao(); boolean usernameCorrect = false; try { ILdapUserDao ldapService = (ILdapUserDao) this.applicationContext.getBean(this.ldapDaoBeanName); String userDn = ldapService.searchUserDNByAccount(username); if (!StringUtil.isNull(userDn)) { usernameCorrect = true; //?? ldapService.authenticateUser(userDn, password); UserDNPrincipal userDNPrincipal = new UserDNPrincipal(userDn); if (!subject.getPrincipals().contains(userDNPrincipal)) subject.getPrincipals().add(userDNPrincipal); log.debug("\t\t[LdapLoginModule] " + "authentication succeeded"); } if (!usernameCorrect) { log.debug("\t\t[LdapLoginModule] " + "authentication failed"); succeeded = false; username = null; for (int i = 0; i < password.length; i++) password[i] = ' '; password = null; throw new FailedLoginException("UserName Incorrect"); } else { succeeded = true; return true; } } catch (EmptyResultDataAccessException e) { succeeded = false; throw new FailedLoginException("user isnot found"); } catch (IncorrectResultSizeDataAccessException e) { succeeded = false; throw new FailedLoginException("user found multi"); } catch (Exception e) { succeeded = false; throw new FailedLoginException("password is wrong"); } }
From source file:org.apache.jackrabbit.core.security.authentication.AbstractLoginModule.java
/** * Method tries to acquire an Impersonator in the follwing order: * <ul>/*w ww.ja v a2s . com*/ * <li> Try to access it from the {@link Credentials} via {@link SimpleCredentials#getAttribute(String)}</li> * <li> Ask CallbackHandler for Impersonator with use of {@link ImpersonationCallback}.</li> * </ul> * * @param credentials which, may contain an impersonation Subject * @return impersonation subject or null if non contained * @see #login() * @see #impersonate(java.security.Principal, javax.jcr.Credentials) */ protected Subject getImpersonatorSubject(Credentials credentials) { Subject impersonator = null; if (credentials == null) { try { ImpersonationCallback impers = new ImpersonationCallback(); callbackHandler.handle(new Callback[] { impers }); impersonator = impers.getImpersonator(); } catch (UnsupportedCallbackException e) { log.warn(e.getCallback().getClass().getName() + " not supported: Unable to perform Impersonation."); } catch (IOException e) { log.error( "Impersonation-Callback failed: " + e.getMessage() + ": Unable to perform Impersonation."); } } else if (credentials instanceof SimpleCredentials) { SimpleCredentials sc = (SimpleCredentials) credentials; impersonator = (Subject) sc.getAttribute(SecurityConstants.IMPERSONATOR_ATTRIBUTE); } return impersonator; }
From source file:org.josso.gl2.agent.jaas.SSOGatewayLoginModule.java
/** * Authenticate the user by prompting for the SSO Session Identifier assigned by the SSO Gateway on logon. * * This method obtains from the gateway, using the provided session identifier, the user associated with * such session identifier.//from w ww . ja v a 2s . c o m * Only the NameCallBack is used, since its not a user/password pair but only one value containing the session * identifier. Any other callback type is ignored. * * @return true in all cases since this LoginModule * should not be ignored. * * @exception javax.security.auth.login.FailedLoginException if the authentication fails. * * @exception javax.security.auth.login.LoginException if this LoginModule * is unable to perform the authentication. */ public boolean login() throws LoginException { if (_callbackHandler == null) throw new LoginException( "Error: no CallbackHandler available " + "to garner authentication information from the user"); Callback[] callbacks = new Callback[2]; // Just ask for the session identifier callbacks[0] = new NameCallback("JOSSO Session Identifier"); callbacks[1] = new PasswordCallback("password", false); String ssoSessionId; String ssoSessionId2 = null; try { _callbackHandler.handle(callbacks); ssoSessionId = ((NameCallback) callbacks[0]).getName(); if (((PasswordCallback) callbacks[1]).getPassword() != null) ssoSessionId2 = String.valueOf(((PasswordCallback) callbacks[1]).getPassword()); } catch (java.io.IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user"); } logger.debug("Session requested authentication to gateway : " + ssoSessionId + "/" + ssoSessionId2); try { if (ssoSessionId2 != null && !ssoSessionId2.equals(ssoSessionId)) ssoSessionId = ssoSessionId2; // If no session is found, ignore this module. if (ssoSessionId == null) { logger.debug("Session authentication failed : " + ssoSessionId); _succeeded = false; return false; } _currentSSOSessionId = ssoSessionId; SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager(); SSOUser ssoUser = im.findUserInSession(ssoSessionId); logger.debug("Session authentication succeeded : " + ssoSessionId); _ssoUserPrincipal = ssoUser; _succeeded = true; } catch (SSOIdentityException e) { // Ignore this ... (user does not exist for this session) //if ( logger.isDebugEnabled()) logger.debug(e.getMessage()); _succeeded = false; return false; } catch (Exception e) { // logger.error("Session authentication failed : " + ssoSessionId, e); _succeeded = false; clearCredentials(); throw new FailedLoginException("Fatal error authenticating session : " + e); } return true; }
From source file:org.josso.jaspi.agent.SSOGatewayLoginModule.java
/** * Authenticate the user by prompting for the SSO Session Identifier assigned by the SSO Gateway on logon. * * This method obtains from the gateway, using the provided session identifier, the user associated with * such session identifier.//from w ww . j a va 2 s .co m * Only the NameCallBack is used, since its not a user/password pair but only one value containing the session * identifier. Any other callback type is ignored. * * @return true in all cases since this LoginModule * should not be ignored. * * @exception javax.security.auth.login.FailedLoginException if the authentication fails. * * @exception javax.security.auth.login.LoginException if this LoginModule * is unable to perform the authentication. */ public boolean login() throws LoginException { if (_callbackHandler == null) throw new LoginException( "Error: no CallbackHandler available " + "to garner authentication information from the user"); Callback[] callbacks = new Callback[3]; // Just ask for the session identifier callbacks[0] = new NameCallback("ssoSessionId"); callbacks[1] = new PasswordCallback("password", false); callbacks[2] = new NameCallback("appID"); String ssoSessionId; String ssoSessionId2 = null; try { _callbackHandler.handle(callbacks); ssoSessionId = ((NameCallback) callbacks[0]).getName(); if (((PasswordCallback) callbacks[1]).getPassword() != null) ssoSessionId2 = String.valueOf(((PasswordCallback) callbacks[1]).getPassword()); _requester = ((NameCallback) callbacks[2]).getName(); } catch (java.io.IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user"); } logger.debug("Requested authentication to gateway by " + _requester + " using sso session " + ssoSessionId + "/" + ssoSessionId2); try { if (ssoSessionId2 != null && !ssoSessionId2.equals(ssoSessionId)) ssoSessionId = ssoSessionId2; // If no session is found, ignore this module. if (ssoSessionId == null) { logger.debug("Session authentication failed : " + ssoSessionId); _succeeded = false; return false; } _currentSSOSessionId = ssoSessionId; SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager(); SSOUser ssoUser = im.findUserInSession(_requester, ssoSessionId); logger.debug("Session authentication succeeded : " + ssoSessionId); _ssoUserPrincipal = ssoUser; _succeeded = true; } catch (SSOIdentityException e) { // Ignore this ... (user does not exist for this session) if (logger.isDebugEnabled()) logger.debug(e.getMessage()); _succeeded = false; return false; } catch (Exception e) { logger.error("Session authentication failed : " + ssoSessionId, e); _succeeded = false; clearCredentials(); throw new FailedLoginException("Fatal error authenticating session : " + e); } return true; }