org.acegisecurity.AuthenticationException Java Examples
The following examples show how to use
org.acegisecurity.AuthenticationException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DebugDaoAuthenticationProvider.java From webcurator with Apache License 2.0 | 6 votes |
@Override protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException { Object salt = null; System.out.println("User pwd: "+userDetails.getPassword()); System.out.println("Auth pwd raw: "+authentication.getCredentials().toString()); if (getSaltSource() != null) { salt = getSaltSource().getSalt(userDetails); } System.out.println("Auth pwd: "+getPasswordEncoder().encodePassword(authentication.getCredentials().toString().trim(), salt)); System.out.println("Salt: "+salt); System.out.println("Encoder: "+getPasswordEncoder()); if (!getPasswordEncoder().isPasswordValid(userDetails.getPassword(), authentication.getCredentials().toString(), salt)) { throw new BadCredentialsException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), userDetails); } }
Example #2
Source File: KualiCasAuthenticationProvider.java From rice with Educational Community License v2.0 | 6 votes |
/** * This overridden method is differs from the super method by * populating the user details by passing the full response * * @see org.acegisecurity.providers.cas.CasAuthenticationProvider#authenticateNow(Authentication authentication) */ private CasAuthenticationToken authenticateNow(Authentication authentication) throws AuthenticationException { // Validate KualiTicketResponse response = (KualiTicketResponse)this.getTicketValidator().confirmTicketValid(authentication.getCredentials().toString()); // Check proxy list is trusted this.getCasProxyDecider().confirmProxyListTrusted(response.getProxyList()); if (logger.isDebugEnabled()) { logger.debug("authenticationNOW:" + response); } // Lookup user details logger.debug("\n\npopulating authorities\n\n"); UserDetails userDetails = ((KualiCasAuthoritiesPopulator)this.getCasAuthoritiesPopulator()).getUserDetails(response); // Construct CasAuthenticationToken return new CasAuthenticationToken(this.getKey(), userDetails, authentication.getCredentials(), userDetails.getAuthorities(), userDetails, response.getProxyList(), response.getProxyGrantingTicketIou()); }
Example #3
Source File: GitLabSecurityRealm.java From gitlab-oauth-plugin with MIT License | 5 votes |
@Override public SecurityComponents createSecurityComponents() { return new SecurityComponents(new AuthenticationManager() { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (authentication instanceof GitLabAuthenticationToken) { return authentication; } if (authentication instanceof UsernamePasswordAuthenticationToken) { try { UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication; GitLabAuthenticationToken gitlab = new GitLabAuthenticationToken(token.getCredentials().toString(), getGitlabApiUri(), TokenType.PRIVATE_TOKEN); SecurityContextHolder.getContext().setAuthentication(gitlab); return gitlab; } catch (IOException e) { throw new RuntimeException(e); } } throw new BadCredentialsException("Unexpected authentication type: " + authentication); } }, new UserDetailsService() { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { return GitLabSecurityRealm.this.loadUserByUsername(username); } }); }
Example #4
Source File: RESTRequestParameterProcessingFilter.java From subsonic with GNU General Public License v3.0 | 5 votes |
private RESTController.ErrorCode authenticate(String username, String password, String salt, String token, Authentication previousAuth) { // Previously authenticated and username not overridden? if (username == null && previousAuth != null) { return null; } if (salt != null && token != null) { User user = securityService.getUserByName(username); if (user == null) { return RESTController.ErrorCode.NOT_AUTHENTICATED; } String expectedToken = DigestUtils.md5Hex(user.getPassword() + salt); if (!expectedToken.equals(token)) { return RESTController.ErrorCode.NOT_AUTHENTICATED; } password = user.getPassword(); } if (password != null) { try { UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password); Authentication authResult = authenticationManager.authenticate(authRequest); SecurityContextHolder.getContext().setAuthentication(authResult); return null; } catch (AuthenticationException x) { return RESTController.ErrorCode.NOT_AUTHENTICATED; } } return RESTController.ErrorCode.MISSING_PARAMETER; }
Example #5
Source File: WCTAuthenticationProcessingFilter.java From webcurator with Apache License 2.0 | 5 votes |
/** @see org.acegisecurity.ui.AbstractProcessingFilter#onUnsuccessfulAuthentication(HttpServletRequest,HttpServletResponse, AuthenticationException) . */ @Override protected void onUnsuccessfulAuthentication(HttpServletRequest aReq, HttpServletResponse aRes, AuthenticationException e) throws IOException { super.onUnsuccessfulAuthentication(aReq, aRes, e); String username = aReq.getParameter("j_username"); //audit failed login event auditor.audit(User.class.getName(), Auditor.ACTION_LOGIN_FAILURE, "Failed Login for username: "+username); }
Example #6
Source File: KualiCasAuthoritiesPopulatorImpl.java From rice with Educational Community License v2.0 | 5 votes |
/** * This overridden method should never be used but is required by the * UserDetails interface * * @see org.acegisecurity.providers.cas.CasAuthoritiesPopulator#getUserDetails(java.lang.String) */ public UserDetails getUserDetails(String casUserId) throws AuthenticationException { if (logger.isDebugEnabled()) { logger.debug("getUserDetails(userID)"); } return this.userDetailsService.loadUserByUsername(casUserId); }
Example #7
Source File: KualiCasAuthoritiesPopulatorImpl.java From rice with Educational Community License v2.0 | 5 votes |
/** * This overridden method is used to pass the Distributed Session * Ticket around via the {@link KualiTicketResponse} * * @see org.kuali.rice.kim.client.acegi.KualiCasAuthoritiesPopulator#getUserDetails(org.kuali.rice.kim.client.acegi.KualiTicketResponse) */ public UserDetails getUserDetails(KualiTicketResponse response) throws AuthenticationException { if (logger.isDebugEnabled()) { logger.debug("getUserDetails(response)"); } return this.userDetailsService.loadUserByTicketResponse(response); }
Example #8
Source File: KualiTestAuthenticationProvider.java From rice with Educational Community License v2.0 | 5 votes |
public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (authentication.getPrincipal().equals(authentication.getCredentials())) { Authentication auth = authenticateNow(authentication); return auth; } else { return authentication; } }
Example #9
Source File: KualiDistributedSessionFilter.java From rice with Educational Community License v2.0 | 5 votes |
/** * This overridden method gets called if requiresAuthentication is true. * If Session is Invalid, throw a {@link KualiDistribtedSessionExpiredException}. * The session is determined invalid if the authentication is of type * {@link KualiDistribtedSessionExpiredAuthentication}. Otherwise it * would have to verify if the DST is valid twice. * * @return the authentication result of the super method * @see org.acegisecurity.ui.cas.CasProcessingFilter#attemptAuthentication(javax.servlet.http.HttpServletRequest) */ public Authentication attemptAuthentication(final HttpServletRequest request) throws AuthenticationException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication instanceof KualiDistributedSessionExpiredAuthentication) { logger.debug("Authentication is dead in attemptAuthentication, setting authentication to null and throwing KualiDistributedSessionExpiredException"); SecurityContextHolder.getContext().setAuthentication(null); throw new KualiDistributedSessionExpiredException("Session Expired"); } return super.attemptAuthentication(request); }
Example #10
Source File: Listener.java From blueocean-plugin with MIT License | 4 votes |
@Override protected UserDetails authenticate(String username, String password) throws AuthenticationException { if (username.equals(password)) return loadUserByUsername(username); throw new BadCredentialsException(username); }
Example #11
Source File: JenkinsRule.java From jenkins-test-harness with MIT License | 4 votes |
@Override protected UserDetails authenticate(String username, String password) throws AuthenticationException { if (username.equals(password)) return loadUserByUsername(username); throw new BadCredentialsException(username); }
Example #12
Source File: KualiCasAuthenticationProvider.java From rice with Educational Community License v2.0 | 4 votes |
/** * This overridden method is copied from CAS verbatim. For some reason * {@link authenticateNow} would not override and the super method * would get called until did this method was also overridden. * * @see org.acegisecurity.providers.cas.CasAuthenticationProvider#authenticate(org.acegisecurity.Authentication) */ public Authentication authenticate(Authentication authentication) throws AuthenticationException { StatelessTicketCache statelessTicketCache = this.getStatelessTicketCache(); String key = this.getKey(); if (!supports(authentication.getClass())) { return null; } if (authentication instanceof UsernamePasswordAuthenticationToken && (!CasProcessingFilter.CAS_STATEFUL_IDENTIFIER.equals(authentication.getPrincipal().toString()) && !CasProcessingFilter.CAS_STATELESS_IDENTIFIER.equals(authentication.getPrincipal().toString()))) { // UsernamePasswordAuthenticationToken not CAS related return null; } // If an existing CasAuthenticationToken, just check we created it if (authentication instanceof CasAuthenticationToken) { if (key.hashCode() == ((CasAuthenticationToken) authentication).getKeyHash()) { return authentication; } else { throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.incorrectKey", "The presented CasAuthenticationToken does not contain the expected key")); } } // Ensure credentials are presented if ((authentication.getCredentials() == null) || "".equals(authentication.getCredentials())) { throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.noServiceTicket", "Failed to provide a CAS service ticket to validate")); } boolean stateless = false; if (authentication instanceof UsernamePasswordAuthenticationToken && CasProcessingFilter.CAS_STATELESS_IDENTIFIER.equals(authentication.getPrincipal())) { stateless = true; } CasAuthenticationToken result = null; if (stateless) { // Try to obtain from cache result = statelessTicketCache.getByTicketId(authentication.getCredentials().toString()); } if (result == null) { result = this.authenticateNow(authentication); result.setDetails(authentication.getDetails()); } if (stateless) { // Add to cache statelessTicketCache.putTicketInCache(result); } return result; }
Example #13
Source File: KualiTestAuthenticationProvider.java From rice with Educational Community License v2.0 | 4 votes |
private UsernamePasswordAuthenticationToken authenticateNow(Authentication authentication) throws AuthenticationException { return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_KUALI_USER")}); }
Example #14
Source File: KualiCasAuthoritiesPopulator.java From rice with Educational Community License v2.0 | 2 votes |
/** * Obtains the granted authorities for the specified user.<P>May throw any * <code>AuthenticationException</code> or return <code>null</code> if the authorities are unavailable.</p> * * @param casUserId as obtained from the CAS validation service * * @return the details of the indicated user (at minimum the granted authorities and the username) * * @throws AuthenticationException DOCUMENT ME! */ UserDetails getUserDetails(KualiTicketResponse response) throws AuthenticationException;