Search in sources :

Example 11 with TokenStore

use of org.springframework.security.oauth2.provider.token.TokenStore 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 12 with TokenStore

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

the class DefaultTokenServicesTests method testAccidentalNullAuthentication.

@Test(expected = InvalidTokenException.class)
public void testAccidentalNullAuthentication() {
    Mockito.when(tokenStore.readAccessToken(Mockito.anyString())).thenReturn(new DefaultOAuth2AccessToken("FOO"));
    // A bug in the TokenStore or a race condition could lead to the authentication
    // being null even if the token is not:
    Mockito.when(tokenStore.readAuthentication(Mockito.any(OAuth2AccessToken.class))).thenReturn(null);
    services.loadAuthentication("FOO");
}
Also used : OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Test(org.junit.Test)

Example 13 with TokenStore

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

the class Application method tokenStore.

@Bean
public JwtTokenStore tokenStore() throws Exception {
    JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
    // N.B. in a real system you would have to configure the verifierKey (or use JdbcTokenStore)
    enhancer.afterPropertiesSet();
    return new JwtTokenStore(enhancer);
}
Also used : JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) JwtAccessTokenConverter(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter) Bean(org.springframework.context.annotation.Bean)

Aggregations

OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)3 InMemoryTokenStore (org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore)3 Test (org.junit.Test)2 Advised (org.springframework.aop.framework.Advised)2 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)2 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)2 DefaultTokenServices (org.springframework.security.oauth2.provider.token.DefaultTokenServices)2 JwtTokenStore (org.springframework.security.oauth2.provider.token.store.JwtTokenStore)2 ArrayList (java.util.ArrayList)1 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1 Bean (org.springframework.context.annotation.Bean)1 AnonymousAuthenticationProvider (org.springframework.security.authentication.AnonymousAuthenticationProvider)1 OAuth2RefreshToken (org.springframework.security.oauth2.common.OAuth2RefreshToken)1 ResourceServerSecurityConfigurer (org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer)1 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)1 ApprovalStore (org.springframework.security.oauth2.provider.approval.ApprovalStore)1 ApprovalStoreUserApprovalHandler (org.springframework.security.oauth2.provider.approval.ApprovalStoreUserApprovalHandler)1 InMemoryApprovalStore (org.springframework.security.oauth2.provider.approval.InMemoryApprovalStore)1 JdbcApprovalStore (org.springframework.security.oauth2.provider.approval.JdbcApprovalStore)1