List of usage examples for javax.security.auth.login FailedLoginException FailedLoginException
public FailedLoginException()
From source file:net.shibboleth.idp.cas.authn.PkixProxyAuthenticatorTest.java
@DataProvider(name = "data") public Object[][] buildTestData() { return new Object[][] { new Object[] { "testCase1", 200, null }, new Object[] { "testCase1", 404, new FailedLoginException() }, new Object[] { "testCase2", 200, new CertificateException() }, }; }
From source file:org.jasig.cas.TestOneTimePasswordAuthenticationHandler.java
@Override public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException, PreventedException { final OneTimePasswordCredential otp = (OneTimePasswordCredential) credential; final String valueOnRecord = credentialMap.get(otp.getId()); if (otp.getPassword().equals(credentialMap.get(otp.getId()))) { return new HandlerResult(this, new BasicCredentialMetaData(otp), new SimplePrincipal(otp.getId())); }//from ww w .ja v a 2 s . co m throw new FailedLoginException(); }
From source file:com.connsec.authentication.AcceptJdbcUsersAuthenticationHandler.java
/** * {@inheritDoc}//from w w w. ja v a 2 s . c o m **/ @Override protected HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential) throws GeneralSecurityException, PreventedException { final String username = credential.getUsername(); final UserInfo u = this.userInfoService.loadUserInfo(username); if (u == null) { logger.debug("{} was not found in the map.", username); throw new AccountNotFoundException(username + " not found in backing map."); } final String encodedPassword = this.getPasswordEncoder().encode(credential.getPassword()); if (!u.getPassword().equals(encodedPassword)) { throw new FailedLoginException(); } WebContext.setUserInfo(u); insertLoginHistory(u, "WebLogin", "Web", "100000", "Success"); return createHandlerResult(credential, this.principalFactory.createPrincipal(username), null); }
From source file:com.dtolabs.rundeck.jetty.jaas.JettyCachingLdapLoginModule.java
/** * Gets credentials by calling {@link #getCallBackAuth()}, then performs {@link #authenticate(String, Object)} * * @return true if authenticated//from w w w. ja v a 2 s .co m * @throws LoginException */ @Override public boolean login() throws LoginException { try { Object[] userPass = getCallBackAuth(); if (null == userPass || userPass.length < 2) { setAuthenticated(false); throw new FailedLoginException(); } String name = (String) userPass[0]; Object pass = userPass[1]; boolean authenticated = authenticate(name, pass); setAuthenticated(authenticated); if (!isAuthenticated()) { throw new FailedLoginException(); } return isAuthenticated(); } catch (UnsupportedCallbackException e) { throw new LoginException("Error obtaining callback information."); } catch (IOException e) { if (_debug) { e.printStackTrace(); } throw new LoginException("IO Error performing login."); } }
From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderLdapLoginModule.java
/** * This LoginModule is not to be ignored. So, this method should never return false. * //from ww w .jav a 2 s .c o m * @return true if authentication succeeds, or throw a LoginException such as FailedLoginException if authentication * fails */ public boolean login() throws LoginException { Map<String, String> headerMap = null; loginSucceeded = false; Callback[] callbacks = new Callback[1]; callbacks[0] = new RequestCallback(); try { callbackHandler.handle(callbacks); } catch (IOException ioe) { throw (LoginException) new LoginException().initCause(ioe); } catch (UnsupportedCallbackException uce) { throw (LoginException) new LoginException().initCause(uce); } httpRequest = ((RequestCallback) callbacks[0]).getRequest(); String[] headers = headerNames.split(","); try { headerMap = matchHeaders(httpRequest, headers); } catch (HeaderMismatchException e) { throw (LoginException) new LoginException("Header Mistmatch error").initCause(e); } if (headerMap.isEmpty()) { throw new FailedLoginException(); } if (authenticationAuthority.equalsIgnoreCase("Siteminder")) { HeaderHandler headerHandler = new SiteminderHeaderHandler(); username = headerHandler.getUser(headerMap); } else if (authenticationAuthority.equalsIgnoreCase("Datapower")) { /* To be Done */ } if (username == null || username.equals("")) { username = null; throw new FailedLoginException(); } try { boolean result = authenticate(username); if (!result) { throw new FailedLoginException(); } } catch (LoginException e) { // Clear out the private state username = null; groups.clear(); throw e; } catch (Exception e) { // Clear out the private state username = null; groups.clear(); throw (LoginException) new LoginException("LDAP Error").initCause(e); } loginSucceeded = true; return loginSucceeded; }
From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderLdapLoginModule.java
protected boolean authenticate(String username) throws Exception { DirContext context = open();/*from w w w . ja v a 2s.co m*/ try { String filter = userSearchMatchingFormat.format(new String[] { username }); SearchControls constraints = new SearchControls(); if (userSearchSubtreeBool) { constraints.setSearchScope(SearchControls.SUBTREE_SCOPE); } else { constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE); } // setup attributes String[] attribs; if (userRoleName == null) { attribs = new String[] {}; } else { attribs = new String[] { userRoleName }; } constraints.setReturningAttributes(attribs); NamingEnumeration results = context.search(userBase, filter, constraints); if (results == null || !results.hasMore()) { log.error("No roles associated with user " + username); loginSucceeded = false; throw new FailedLoginException(); } SearchResult result = (SearchResult) results.next(); if (results.hasMore()) { // ignore for now } NameParser parser = context.getNameParser(""); Name contextName = parser.parse(context.getNameInNamespace()); Name baseName = parser.parse(userBase); Name entryName = parser.parse(result.getName()); Name name = contextName.addAll(baseName); name = name.addAll(entryName); String dn = name.toString(); Attributes attrs = result.getAttributes(); if (attrs == null) { return false; } ArrayList<String> roles = null; if (userRoleName != null) { roles = addAttributeValues(userRoleName, attrs, roles); } // check the credentials by binding to server // bindUser(context, dn); // if authenticated add more roles roles = getRoles(context, dn, username, roles); for (String role : roles) { groups.add(role); } if (groups.isEmpty()) { log.error("No roles associated with user " + username); loginSucceeded = false; throw new FailedLoginException(); } else loginSucceeded = true; } catch (CommunicationException e) { close(context); throw (LoginException) new FailedLoginException().initCause(e); } catch (NamingException e) { close(context); throw (LoginException) new FailedLoginException().initCause(e); } return true; }
From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderLdapLoginModule.java
protected void bindUser(DirContext context, String dn) throws NamingException, FailedLoginException { context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn); try {/*from www .j av a2s . c o m*/ context.getAttributes("", null); } catch (AuthenticationException e) { log.debug("Authentication failed for dn=" + dn); throw new FailedLoginException(); } finally { if (connectionUsername != null) { context.addToEnvironment(Context.SECURITY_PRINCIPAL, connectionUsername); } else { context.removeFromEnvironment(Context.SECURITY_PRINCIPAL); } if (connectionPassword != null) { context.addToEnvironment(Context.SECURITY_CREDENTIALS, connectionPassword); } else { context.removeFromEnvironment(Context.SECURITY_CREDENTIALS); } } }
From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderPropertiesFileLoginModule.java
public boolean login() throws LoginException { Map<String, String> headerMap = null; loginSucceeded = false;// www . jav a 2 s. com Callback[] callbacks = new Callback[1]; callbacks[0] = new RequestCallback(); try { callbackHandler.handle(callbacks); } catch (IOException ioe) { throw (LoginException) new LoginException().initCause(ioe); } catch (UnsupportedCallbackException uce) { throw (LoginException) new LoginException().initCause(uce); } httpRequest = ((RequestCallback) callbacks[0]).getRequest(); String[] headers = headerNames.split(","); try { headerMap = matchHeaders(httpRequest, headers); } catch (HeaderMismatchException e) { throw (LoginException) new LoginException("Header Mistmatch error").initCause(e); } if (headerMap.isEmpty()) { throw new FailedLoginException(); } if (authenticationAuthority.equalsIgnoreCase("Siteminder")) { HeaderHandler headerHandler = new SiteminderHeaderHandler(); username = headerHandler.getUser(headerMap); } else if (authenticationAuthority.equalsIgnoreCase("Datapower")) { /* To be Done */ } if (username == null || username.equals("")) { username = null; throw new FailedLoginException(); } if (username != null) { for (Map.Entry<String, Set<String>> entry : roleUsersMap.entrySet()) { String groupName = entry.getKey(); Set<String> users = entry.getValue(); for (String user : users) { if (username.equals(user)) { groups.add(groupName); break; } } } } if (groups.isEmpty()) { log.error("No roles associated with user " + username); loginSucceeded = false; throw new FailedLoginException(); } else loginSucceeded = true; return loginSucceeded; }
From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderSqlLoginmodule.java
public boolean login() throws LoginException { Map<String, String> headerMap = null; loginSucceeded = false;/*from w w w .java2 s. c o m*/ Connection conn = null; ResultSet result = null; PreparedStatement statement = null; Callback[] callbacks = new Callback[1]; callbacks[0] = new RequestCallback(); try { callbackHandler.handle(callbacks); } catch (IOException ioe) { throw (LoginException) new LoginException().initCause(ioe); } catch (UnsupportedCallbackException uce) { throw (LoginException) new LoginException().initCause(uce); } httpRequest = ((RequestCallback) callbacks[0]).getRequest(); String[] headers = headerNames.split(","); try { headerMap = matchHeaders(httpRequest, headers); } catch (HeaderMismatchException e) { throw (LoginException) new LoginException("Header Mistmatch error").initCause(e); } if (headerMap.isEmpty()) { throw new FailedLoginException(); } if (authenticationAuthority.equalsIgnoreCase("Siteminder")) { HeaderHandler headerHandler = new SiteminderHeaderHandler(); username = headerHandler.getUser(headerMap); } else if (authenticationAuthority.equalsIgnoreCase("Datapower")) { /* To be Done */ } if (username == null || username.equals("")) { username = null; throw new FailedLoginException(); } if (dataSource != null) { try { conn = dataSource.getConnection(); try { statement = conn.prepareStatement(groupSelect); int count = countParameters(groupSelect); for (int i = 0; i < count; i++) { statement.setObject(i + 1, username); } result = statement.executeQuery(); while (result.next()) { String userName = result.getString(1); String groupName = result.getString(2); if (userName.equals(username)) groups.add(groupName); } if (groups.isEmpty()) { log.error("No roles associated with user " + username); loginSucceeded = false; throw new FailedLoginException(); } else loginSucceeded = true; } finally { result.close(); statement.close(); conn.close(); } } catch (LoginException e) { // Clear out the private state username = null; groups.clear(); throw e; } catch (SQLException sqle) { // Clear out the private state username = null; groups.clear(); throw (LoginException) new LoginException("SQL error").initCause(sqle); } catch (Exception e) { // Clear out the private state username = null; groups.clear(); throw (LoginException) new LoginException("Could not access datasource").initCause(e); } } return loginSucceeded; }
From source file:org.apache.jackrabbit.core.security.authentication.AbstractLoginModule.java
/** * @param principal Principal used to retrieve the <code>Authentication</code> * object.//from ww w. ja va 2 s .c om * @param credentials Credentials used for the authentication. * @return <code>true</code> if Credentails authenticate, * <code>false</code> if no <code>Authentication</code> can handle * the given <code>Credentials</code> * @throws javax.security.auth.login.FailedLoginException * if the authentication failed. * @throws RepositoryException If another error occurs. * @see AbstractLoginModule#getAuthentication(java.security.Principal, javax.jcr.Credentials) * @see AbstractLoginModule#authenticate(java.security.Principal, javax.jcr.Credentials) */ protected boolean authenticate(Principal principal, Credentials credentials) throws FailedLoginException, RepositoryException { Authentication auth = getAuthentication(principal, credentials); if (auth == null) { return false; } else if (auth.authenticate(credentials)) { return true; } throw new FailedLoginException(); }