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) {
}
}
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);
}
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);
}
Aggregations