Search in sources :

Example 56 with AuthenticationException

use of org.springframework.security.core.AuthenticationException in project oc-explorer by devgateway.

the class SSAuthenticatedWebSession method authenticate.

@Override
public boolean authenticate(final String username, final String password) {
    boolean authenticated;
    try {
        Authentication authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
        SecurityContextHolder.getContext().setAuthentication(authentication);
        // httpSession.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
        // SecurityContextHolder.getContext());
        authenticated = authentication.isAuthenticated();
        if (authenticated && rememberMeServices != null) {
            rememberMeServices.loginSuccess((HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest(), (HttpServletResponse) RequestCycle.get().getResponse().getContainerResponse(), authentication);
        }
    } catch (AuthenticationException e) {
        this.setAe(e);
        log.warn("User '{}' failed to login. Reason: {}", username, e.getMessage());
        authenticated = false;
    }
    return authenticated;
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Aggregations

AuthenticationException (org.springframework.security.core.AuthenticationException)56 Authentication (org.springframework.security.core.Authentication)30 Test (org.junit.Test)24 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)19 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 HttpServletResponse (javax.servlet.http.HttpServletResponse)12 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)12 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 IOException (java.io.IOException)5 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)5 HashMap (java.util.HashMap)3 ServletException (javax.servlet.ServletException)3 HttpSession (javax.servlet.http.HttpSession)3 LockedException (org.springframework.security.authentication.LockedException)3 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)2 Map (java.util.Map)2 LoginException (javax.security.auth.login.LoginException)2 FilterChain (javax.servlet.FilterChain)2