Search in sources :

Example 11 with DefaultTokenServices

use of org.springframework.security.oauth2.provider.token.DefaultTokenServices in project dhis2-core by dhis2.

the class DhisWebApiWebSecurityConfig method tokenServices.

@Bean("defaultTokenService")
@Primary
public DefaultTokenServices tokenServices() {
    final DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
    defaultTokenServices.setTokenStore(tokenStore());
    defaultTokenServices.setSupportRefreshToken(true);
    return defaultTokenServices;
}
Also used : DefaultTokenServices(org.springframework.security.oauth2.provider.token.DefaultTokenServices) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 12 with DefaultTokenServices

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

the class AuthorizationServerEndpointsConfigurer method createDefaultTokenServices.

private DefaultTokenServices createDefaultTokenServices() {
    DefaultTokenServices tokenServices = new DefaultTokenServices();
    tokenServices.setTokenStore(tokenStore());
    tokenServices.setSupportRefreshToken(true);
    tokenServices.setReuseRefreshToken(reuseRefreshToken);
    tokenServices.setClientDetailsService(clientDetailsService());
    tokenServices.setTokenEnhancer(tokenEnhancer());
    addUserDetailsService(tokenServices, this.userDetailsService);
    return tokenServices;
}
Also used : DefaultTokenServices(org.springframework.security.oauth2.provider.token.DefaultTokenServices)

Example 13 with DefaultTokenServices

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

the class ResourceServerSecurityConfigurer method tokenServices.

private ResourceServerTokenServices tokenServices(HttpSecurity http) {
    if (resourceTokenServices != null) {
        return resourceTokenServices;
    }
    DefaultTokenServices tokenServices = new DefaultTokenServices();
    tokenServices.setTokenStore(tokenStore());
    tokenServices.setSupportRefreshToken(true);
    tokenServices.setClientDetailsService(clientDetails());
    this.resourceTokenServices = tokenServices;
    return tokenServices;
}
Also used : DefaultTokenServices(org.springframework.security.oauth2.provider.token.DefaultTokenServices)

Example 14 with DefaultTokenServices

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

the class AbstractDefaultTokenServicesTests method testRefreshTokenNonExpiring.

@Test
public void testRefreshTokenNonExpiring() throws Exception {
    ClientDetailsService clientDetailsService = new InMemoryClientDetailsServiceBuilder().withClient("id").refreshTokenValiditySeconds(0).authorizedGrantTypes("refresh_token").and().build();
    DefaultTokenServices tokenServices = getTokenServices();
    tokenServices.setClientDetailsService(clientDetailsService);
    OAuth2RefreshToken refreshToken = tokenServices.createAccessToken(createAuthentication()).getRefreshToken();
    assertNotNull(refreshToken);
    assertFalse(refreshToken instanceof ExpiringOAuth2RefreshToken);
}
Also used : ExpiringOAuth2RefreshToken(org.springframework.security.oauth2.common.ExpiringOAuth2RefreshToken) OAuth2RefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken) DefaultExpiringOAuth2RefreshToken(org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken) InMemoryClientDetailsServiceBuilder(org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) ExpiringOAuth2RefreshToken(org.springframework.security.oauth2.common.ExpiringOAuth2RefreshToken) DefaultExpiringOAuth2RefreshToken(org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken) Test(org.junit.Test)

Example 15 with DefaultTokenServices

use of org.springframework.security.oauth2.provider.token.DefaultTokenServices in project spring-boot by spring-projects.

the class ResourceServerTokenServicesConfigurationTests method jwkConfiguration.

@Test
public void jwkConfiguration() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.environment, "security.oauth2.resource.jwk.key-set-uri=http://my-auth-server/token_keys");
    this.context = new SpringApplicationBuilder(ResourceConfiguration.class).environment(this.environment).web(false).run();
    DefaultTokenServices services = this.context.getBean(DefaultTokenServices.class);
    assertThat(services).isNotNull();
    this.thrown.expect(NoSuchBeanDefinitionException.class);
    this.context.getBean(RemoteTokenServices.class);
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) DefaultTokenServices(org.springframework.security.oauth2.provider.token.DefaultTokenServices) Test(org.junit.Test)

Aggregations

DefaultTokenServices (org.springframework.security.oauth2.provider.token.DefaultTokenServices)14 Bean (org.springframework.context.annotation.Bean)8 Primary (org.springframework.context.annotation.Primary)6 Test (org.junit.Test)4 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)3 InMemoryClientDetailsServiceBuilder (org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder)2 Before (org.junit.Before)1 DefaultExpiringOAuth2RefreshToken (org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken)1 ExpiringOAuth2RefreshToken (org.springframework.security.oauth2.common.ExpiringOAuth2RefreshToken)1 OAuth2RefreshToken (org.springframework.security.oauth2.common.OAuth2RefreshToken)1 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)1 JwtTokenStore (org.springframework.security.oauth2.provider.token.store.JwtTokenStore)1 GenericFilterBean (org.springframework.web.filter.GenericFilterBean)1