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