Search in sources :

Example 56 with ClientDetails

use of org.springframework.security.oauth2.provider.ClientDetails 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)

Example 57 with ClientDetails

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

the class AbstractDefaultTokenServicesTests method testClientSpecificRefreshTokenExpiry.

@Test
public void testClientSpecificRefreshTokenExpiry() throws Exception {
    getTokenServices().setRefreshTokenValiditySeconds(1000);
    getTokenServices().setClientDetailsService(new ClientDetailsService() {

        public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
            BaseClientDetails client = new BaseClientDetails();
            client.setRefreshTokenValiditySeconds(100);
            client.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "refresh_token"));
            return client;
        }
    });
    OAuth2AccessToken accessToken = getTokenServices().createAccessToken(createAuthentication());
    DefaultExpiringOAuth2RefreshToken refreshToken = (DefaultExpiringOAuth2RefreshToken) accessToken.getRefreshToken();
    Date expectedExpiryDate = new Date(System.currentTimeMillis() + 102 * 1000L);
    assertTrue(expectedExpiryDate.after(refreshToken.getExpiration()));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) DefaultExpiringOAuth2RefreshToken(org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception) Date(java.util.Date) Test(org.junit.Test)

Example 58 with ClientDetails

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

the class JdbcClientDetailsServiceTests method testLoadingClientIdWithNoDetails.

@Test
public void testLoadingClientIdWithNoDetails() {
    jdbcTemplate.update(INSERT_SQL, "clientIdWithNoDetails", null, null, null, null, null, null, null, null, null);
    ClientDetails clientDetails = service.loadClientByClientId("clientIdWithNoDetails");
    assertEquals("clientIdWithNoDetails", clientDetails.getClientId());
    assertFalse(clientDetails.isSecretRequired());
    assertNull(clientDetails.getClientSecret());
    assertFalse(clientDetails.isScoped());
    assertEquals(0, clientDetails.getScope().size());
    assertEquals(2, clientDetails.getAuthorizedGrantTypes().size());
    assertNull(clientDetails.getRegisteredRedirectUri());
    assertEquals(0, clientDetails.getAuthorities().size());
    assertEquals(null, clientDetails.getAccessTokenValiditySeconds());
    assertEquals(null, clientDetails.getAccessTokenValiditySeconds());
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) Test(org.junit.Test)

Example 59 with ClientDetails

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

the class JdbcClientDetailsServiceTests method testFindClients.

@Test
public void testFindClients() {
    BaseClientDetails clientDetails = new BaseClientDetails();
    clientDetails.setClientId("aclient");
    service.addClientDetails(clientDetails);
    int count = service.listClientDetails().size();
    assertEquals(1, count);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Example 60 with ClientDetails

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

the class JdbcClientDetailsServiceTests method testUpdateClientRedirectURI.

@Test
public void testUpdateClientRedirectURI() {
    BaseClientDetails clientDetails = new BaseClientDetails();
    clientDetails.setClientId("newClientIdWithNoDetails");
    service.addClientDetails(clientDetails);
    String[] redirectURI = { "http://localhost:8080", "http://localhost:9090" };
    clientDetails.setRegisteredRedirectUri(new HashSet<String>(Arrays.asList(redirectURI)));
    service.updateClientDetails(clientDetails);
    Map<String, Object> map = jdbcTemplate.queryForMap(SELECT_SQL, "newClientIdWithNoDetails");
    assertEquals("newClientIdWithNoDetails", map.get("client_id"));
    assertTrue(map.containsKey("web_server_redirect_uri"));
    assertEquals("http://localhost:8080,http://localhost:9090", map.get("web_server_redirect_uri"));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Aggregations

ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)38 Test (org.junit.Test)34 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)28 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)23 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)19 Authentication (org.springframework.security.core.Authentication)18 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)16 Date (java.util.Date)13 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)13 HashMap (java.util.HashMap)11 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)7 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)6 DBUnitTest (org.orcid.test.DBUnitTest)6 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)6 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)6 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)6 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)6 OrcidOauth2ClientAuthentication (org.orcid.core.oauth.OrcidOauth2ClientAuthentication)5 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)5 InvalidClientException (org.springframework.security.oauth2.common.exceptions.InvalidClientException)5