List of usage examples for javax.security.auth.login LoginException LoginException
public LoginException(String msg)
From source file:org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityLoginModule.java
/** * {@inheritDoc}/*w ww . jav a2 s . c o m*/ */ @Override protected void doInit(final CallbackHandler callbackHandler, final Session session, final Map options) throws LoginException { if (options.containsKey(KEY_PRE_AUTHENTICATION_TOKENS)) { String preAuthenticationTokensString = (String) options.get(KEY_PRE_AUTHENTICATION_TOKENS); String[] tokens = preAuthenticationTokensString.split(PRE_AUTHENTICATION_TOKEN_SEPARATOR); if (tokens.length == 0) { throw new LoginException(Messages.getInstance().getString( "AbstractPentahoLoginModule.ERROR_0001_PRE_AUTH_TOKENS_MALFORMED", //$NON-NLS-1$ KEY_PRE_AUTHENTICATION_TOKENS)); } for (String token : tokens) { preAuthenticationTokens.add(token.trim()); } logger.debug("preAuthenticationTokens=" + preAuthenticationTokens); //$NON-NLS-1$ } authenticationManager = getAuthenticationManager(callbackHandler, session, options); }
From source file:org.josso.servlet.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 . j av a 2 s .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("ssoSessionId"); 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()); _requester = ""; // Check for nulls ? SSOAgentRequest request = (SSOAgentRequest) AbstractSSOAgent._currentRequest.get(); if (request != null) _requester = request.getRequester(); else logger.warn("No SSO Agent request found in thread local variable, can't identify requester"); } 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; }
From source file:org.josso.wls92.agent.jaas.SSOGatewayLoginModuleImpl.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.// w w w. ja va 2 s . 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("ssoSessionId"); 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()); _requester = ""; // Check for nulls ? SSOAgentRequest request = AbstractSSOAgent._currentRequest.get(); if (request != null) _requester = request.getRequester(); else logger.warn("No SSO Agent request found in thread local variable, can't identify requester"); } 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 jossoUser = im.findUserInSession(_requester, ssoSessionId); WLSJOSSOUser wlsUser = new WLSJOSSOUser(jossoUser); logger.debug("Session authentication succeeded : " + ssoSessionId); _ssoUserPrincipal = wlsUser; _succeeded = true; } catch (SSOIdentityException e) { // Ignore this ... (user does not exist for this session) logger.debug(e.getMessage()); // Only log if debug is enabled ... if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e); _succeeded = false; return false; } catch (Exception e) { logger.error("Session login failed for Principal : " + _ssoUserPrincipal + e.getMessage()); // Only log if debug is enabled ... if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e); _succeeded = false; clearCredentials(); throw new FailedLoginException( "Fatal error authenticating session : " + _ssoUserPrincipal + " : " + e.getMessage()); } return true; }
From source file:org.josso.wls10.agent.jaas.SSOGatewayLoginModuleImpl.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 ww w. j a v a 2 s . com * 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("ssoSessionId"); 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()); _requester = ""; // Check for nulls ? SSOAgentRequest request = AbstractSSOAgent._currentRequest.get(); if (request != null) _requester = request.getRequester(); else logger.warn("No SSO Agent request found in thread local variable, can't identify requester"); } 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) { if (logger.isDebugEnabled()) logger.debug("Session authentication failed : " + ssoSessionId); _succeeded = false; return false; } _currentSSOSessionId = ssoSessionId; SSOIdentityManagerService im = Lookup.getInstance().lookupSSOAgent().getSSOIdentityManager(); SSOUser jossoUser = im.findUserInSession(_requester, ssoSessionId); WLSJOSSOUser wlsUser = new WLSJOSSOUser(jossoUser); if (logger.isDebugEnabled()) logger.debug("Session authentication succeeded : " + ssoSessionId); _ssoUserPrincipal = wlsUser; _succeeded = true; } catch (SSOIdentityException e) { // Ignore this ... (user does not exist for this session) if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e); _succeeded = false; return false; } catch (Exception e) { logger.error("Session login failed for Principal : " + _ssoUserPrincipal + e.getMessage()); // Only log if debug is enabled ... if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e); _succeeded = false; clearCredentials(); throw new FailedLoginException( "Fatal error authenticating session : " + _ssoUserPrincipal + " : " + e.getMessage()); } 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 ww w . j av a 2 s . 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[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; }
From source file:org.rhq.enterprise.server.core.jaas.JDBCPrincipalCheckLoginModule.java
/** * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#getUsersPassword() *//*from w w w .ja va 2 s. com*/ @Override protected String getUsersPassword() throws LoginException { String username = getUsername(); if ("admin".equals(username)) { throw new FailedLoginException("Cannot log in as overlord"); } String password = getUsernameAndPassword()[1]; // what did the user enter? Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { Properties props = getProperties(); InitialContext ctx = new InitialContext(props); DataSource ds = (DataSource) ctx.lookup(dsJndiName); conn = ds.getConnection(); ps = conn.prepareStatement(principalsQuery); ps.setString(1, username); rs = ps.executeQuery(); if (rs.next() == true) { throw new FailedLoginException("username found in principals - do not continue"); } password = Util.createPasswordHash("MD5", "base64", null, null, password); // return back the string entered by the user as a hash } catch (NamingException ex) { throw new LoginException(ex.toString(true)); } catch (SQLException ex) { throw new LoginException(ex.toString()); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) { } } if (ps != null) { try { ps.close(); } catch (Exception e) { } } if (conn != null) { try { conn.close(); } catch (Exception ex) { } } } return password; }
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 w ww.j av a 2 s . co m*/ 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()); } }
From source file:org.nuxeo.ecm.webengine.jaxrs.login.AuthenticationFilter.java
protected LoginContext doLogin(HttpServletRequest request, HttpServletResponse response) throws LoginException { String[] login = retrieveBasicLogin(request); if (login != null) { return Framework.login(login[0], login[1]); }/* ww w. ja v a 2s . co m*/ // TODO no login provided - use anonymous ? // for now no anonymous user supported - we require a login throw new LoginException("User must login"); // return null; }
From source file:de.adorsys.oauth.loginmodule.DelegatingLoginModule.java
private ClientID resolveClientID() throws LoginException { try {//from w w w . j av a2s .co m AuthorizationRequest authorizationRequest = (AuthorizationRequest) PolicyContext .getContext(AuthorizationRequest.class.getName()); return authorizationRequest.getClientID(); } catch (Exception e) { log.trace("Exception parsing auth request", e); } try { TokenRequest tokenRequest = (TokenRequest) PolicyContext.getContext(TokenRequest.class.getName()); if (tokenRequest.getClientID() == null && tokenRequest.getClientAuthentication() != null) { return tokenRequest.getClientAuthentication().getClientID(); } return tokenRequest.getClientID(); } catch (Exception e) { // } throw new LoginException("ClientID extraction failed"); }
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.jav a 2s .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[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; }