Search in sources :

Example 91 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)

Example 92 with ClientDetails

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

the class JdbcClientDetailsServiceTests method testUpdateNonExistentClient.

@Test(expected = NoSuchClientException.class)
public void testUpdateNonExistentClient() {
    BaseClientDetails clientDetails = new BaseClientDetails();
    clientDetails.setClientId("nosuchClientIdWithNoDetails");
    service.updateClientDetails(clientDetails);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Example 93 with ClientDetails

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

the class JdbcClientDetailsServiceTests method testAddClientWithNoDetails.

@Test
public void testAddClientWithNoDetails() {
    BaseClientDetails clientDetails = new BaseClientDetails();
    clientDetails.setClientId("addedClientIdWithNoDetails");
    service.addClientDetails(clientDetails);
    Map<String, Object> map = jdbcTemplate.queryForMap(SELECT_SQL, "addedClientIdWithNoDetails");
    assertEquals("addedClientIdWithNoDetails", map.get("client_id"));
    assertTrue(map.containsKey("client_secret"));
    assertEquals(null, map.get("client_secret"));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) Test(org.junit.Test)

Example 94 with ClientDetails

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

the class AuthorizationEndpointTests method init.

@Before
public void init() throws Exception {
    client = new BaseClientDetails();
    client.setRegisteredRedirectUri(Collections.singleton("https://anywhere.com"));
    client.setAuthorizedGrantTypes(Arrays.asList("authorization_code", "implicit"));
    endpoint.setClientDetailsService(new ClientDetailsService() {

        public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
            return client;
        }
    });
    endpoint.setTokenGranter(new TokenGranter() {

        public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
            return null;
        }
    });
    endpoint.setRedirectResolver(new DefaultRedirectResolver());
    endpoint.afterPropertiesSet();
}
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) TokenGranter(org.springframework.security.oauth2.provider.TokenGranter) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception) Before(org.junit.Before)

Example 95 with ClientDetails

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

the class DefaultTokenServicesWithInMemoryTests method testNoRefreshTokenIfNotAuthorized.

@Test
public void testNoRefreshTokenIfNotAuthorized() throws Exception {
    // create access token
    getTokenServices().setAccessTokenValiditySeconds(1);
    getTokenServices().setClientDetailsService(new ClientDetailsService() {

        public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
            BaseClientDetails client = new BaseClientDetails();
            client.setAccessTokenValiditySeconds(1);
            client.setAuthorizedGrantTypes(Arrays.asList("authorization_code"));
            return client;
        }
    });
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(expectedAuthentication);
    assertNull(token.getRefreshToken());
}
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) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Test(org.junit.Test)

Aggregations

ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)47 Test (org.junit.Test)39 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)32 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)28 Authentication (org.springframework.security.core.Authentication)21 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)20 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)20 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)19 Date (java.util.Date)14 HashMap (java.util.HashMap)13 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)9 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)7 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)7 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)7 ClientRegistrationException (org.springframework.security.oauth2.provider.ClientRegistrationException)7 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 OrcidOauth2ClientAuthentication (org.orcid.core.oauth.OrcidOauth2ClientAuthentication)5