Search in sources :

Example 6 with ClientRegistrationException

use of org.springframework.security.oauth2.provider.ClientRegistrationException in project spring-security-oauth by spring-projects.

the class AbstractDefaultTokenServicesTests method testClientInvalidated.

@Test(expected = InvalidTokenException.class)
public void testClientInvalidated() throws Exception {
    final AtomicBoolean deleted = new AtomicBoolean();
    getTokenServices().setClientDetailsService(new ClientDetailsService() {

        public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
            if (deleted.get()) {
                throw new ClientRegistrationException("No such client: " + clientId);
            }
            BaseClientDetails client = new BaseClientDetails();
            client.setRefreshTokenValiditySeconds(100);
            client.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "refresh_token"));
            return client;
        }
    });
    OAuth2AccessToken token = getTokenServices().createAccessToken(createAuthentication());
    deleted.set(true);
    OAuth2Authentication authentication = getTokenServices().loadAuthentication(token.getValue());
    assertNotNull(authentication.getOAuth2Request());
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) ClientRegistrationException(org.springframework.security.oauth2.provider.ClientRegistrationException) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception) Test(org.junit.Test)

Aggregations

ClientRegistrationException (org.springframework.security.oauth2.provider.ClientRegistrationException)6 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)5 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)3 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)3 Date (java.util.Date)1 HashSet (java.util.HashSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 OAuth2AccessDeniedException (org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException)1 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)1 InvalidTokenException (org.springframework.security.oauth2.common.exceptions.InvalidTokenException)1 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)1 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)1 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)1 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)1