Search in sources :

Example 26 with ClientDetailsService

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

the class DefaultTokenServices method getAccessTokenValiditySeconds.

/**
	 * The access token validity period in seconds
	 * 
	 * @param clientAuth the current authorization request
	 * @return the access token validity period in seconds
	 */
protected int getAccessTokenValiditySeconds(OAuth2Request clientAuth) {
    if (clientDetailsService != null) {
        ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
        Integer validity = client.getAccessTokenValiditySeconds();
        if (validity != null) {
            return validity;
        }
    }
    return accessTokenValiditySeconds;
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails)

Example 27 with ClientDetailsService

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

the class DefaultTokenServices method getRefreshTokenValiditySeconds.

/**
	 * The refresh token validity period in seconds
	 * 
	 * @param clientAuth the current authorization request
	 * @return the refresh token validity period in seconds
	 */
protected int getRefreshTokenValiditySeconds(OAuth2Request clientAuth) {
    if (clientDetailsService != null) {
        ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
        Integer validity = client.getRefreshTokenValiditySeconds();
        if (validity != null) {
            return validity;
        }
    }
    return refreshTokenValiditySeconds;
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails)

Example 28 with ClientDetailsService

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

the class ClientDetailsServiceBeanDefinitionParserTests method testClientDetailsFromNonPropertyFile.

@Test
public void testClientDetailsFromNonPropertyFile() {
    // valid client details NOT from property file
    ClientDetails clientDetails = clientDetailsService.loadClientByClientId("my-client-id-non-property-file");
    assertNotNull(clientDetailsService);
    assertEquals("my-client-id-non-property-file", clientDetails.getClientId());
    assertEquals("my-client-secret-non-property-file", clientDetails.getClientSecret());
    Set<String> grantTypes = clientDetails.getAuthorizedGrantTypes();
    assertNotNull(grantTypes);
    assertEquals(2, grantTypes.size());
    assertTrue(grantTypes.contains("password"));
    assertTrue(grantTypes.contains("authorization_code"));
    Set<String> scopes = clientDetails.getScope();
    assertNotNull(scopes);
    assertEquals(2, scopes.size());
    assertTrue(scopes.contains("scope1"));
    assertTrue(scopes.contains("scope2"));
    Collection<GrantedAuthority> authorities = clientDetails.getAuthorities();
    assertNotNull(authorities);
    assertEquals(2, authorities.size());
    assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_USER"));
    assertTrue(AuthorityUtils.authorityListToSet(authorities).contains("ROLE_ANONYMOUS"));
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Test(org.junit.Test)

Example 29 with ClientDetailsService

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

the class ClientDetailsServiceBeanDefinitionParserTests method testClientDetailsDefaultFlow.

@Test
public void testClientDetailsDefaultFlow() {
    ClientDetails clientDetails = clientDetailsService.loadClientByClientId("my-client-id-default-flow");
    assertNotNull(clientDetailsService);
    assertEquals("my-client-id-default-flow", clientDetails.getClientId());
    assertEquals(1, clientDetails.getRegisteredRedirectUri().size());
    assertEquals("http://mycompany.com", clientDetails.getRegisteredRedirectUri().iterator().next());
    Set<String> grantTypes = clientDetails.getAuthorizedGrantTypes();
    assertNotNull(grantTypes);
    assertEquals(2, grantTypes.size());
    assertTrue(grantTypes.contains("authorization_code"));
    assertTrue(grantTypes.contains("refresh_token"));
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) Test(org.junit.Test)

Example 30 with ClientDetailsService

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

the class ApprovalStoreUserApprovalHandlerTests method testAutoapprovedAllScopes.

@Test
public void testAutoapprovedAllScopes() {
    handler.setClientDetailsService(clientDetailsService);
    BaseClientDetails client = new BaseClientDetails("client", null, "read", "authorization_code", null);
    client.setAutoApproveScopes(new HashSet<String>(Arrays.asList("true")));
    clientDetailsService.setClientDetailsStore(Collections.singletonMap("client", client));
    AuthorizationRequest authorizationRequest = new AuthorizationRequest("client", Arrays.asList("read"));
    AuthorizationRequest result = handler.checkForPreApproval(authorizationRequest, userAuthentication);
    assertTrue(result.isApproved());
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)27 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)18 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)16 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)14 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)13 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)11 Authentication (org.springframework.security.core.Authentication)8 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)7 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)7 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)6 ClientRegistrationException (org.springframework.security.oauth2.provider.ClientRegistrationException)6 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)6 HashMap (java.util.HashMap)5 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)5 InMemoryClientDetailsService (org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService)5 Before (org.junit.Before)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)4 DefaultOAuth2RequestFactory (org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory)4 Date (java.util.Date)3 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)3