Search in sources :

Example 1 with AccountExpiredException

use of org.springframework.security.authentication.AccountExpiredException in project spring-security by spring-projects.

the class DaoAuthenticationProviderTests method testAuthenticateFailsIfAccountExpired.

@Test
public void testAuthenticateFailsIfAccountExpired() {
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("peter", "opal");
    DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
    provider.setUserDetailsService(new MockAuthenticationDaoUserPeterAccountExpired());
    provider.setUserCache(new MockUserCache());
    try {
        provider.authenticate(token);
        fail("Should have thrown AccountExpiredException");
    } catch (AccountExpiredException expected) {
    }
}
Also used : AccountExpiredException(org.springframework.security.authentication.AccountExpiredException) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 2 with AccountExpiredException

use of org.springframework.security.authentication.AccountExpiredException in project spring-security-oauth by spring-projects.

the class DefaultTokenServicesWithInMemoryTests method testRefreshTokenWithUnauthenticatedUser.

@Test
public void testRefreshTokenWithUnauthenticatedUser() throws Exception {
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    getTokenServices().setAuthenticationManager(new AuthenticationManager() {

        @Override
        public Authentication authenticate(Authentication authentication) throws AuthenticationException {
            throw new AccountExpiredException("Not valid");
        }
    });
    DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(expectedAuthentication);
    assertNotNull(firstAccessToken.getRefreshToken());
    expected.expect(AccountExpiredException.class);
    TokenRequest tokenRequest = new TokenRequest(Collections.singletonMap("client_id", "id"), "id", null, null);
    getTokenServices().refreshAccessToken(firstAccessToken.getRefreshToken().getValue(), tokenRequest);
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) AuthenticationException(org.springframework.security.core.AuthenticationException) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) AccountExpiredException(org.springframework.security.authentication.AccountExpiredException) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Test(org.junit.Test)

Example 3 with AccountExpiredException

use of org.springframework.security.authentication.AccountExpiredException in project spring-security by spring-projects.

the class DelegatingAuthenticationFailureHandlerTests method handleByDefaultHandler.

@Test
public void handleByDefaultHandler() throws Exception {
    handlers.put(BadCredentialsException.class, handler1);
    handler = new DelegatingAuthenticationFailureHandler(handlers, defaultHandler);
    AuthenticationException exception = new AccountExpiredException("");
    handler.onAuthenticationFailure(request, response, exception);
    verifyZeroInteractions(handler1, handler2);
    verify(defaultHandler).onAuthenticationFailure(request, response, exception);
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) AccountExpiredException(org.springframework.security.authentication.AccountExpiredException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 AccountExpiredException (org.springframework.security.authentication.AccountExpiredException)3 AuthenticationException (org.springframework.security.core.AuthenticationException)2 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)1