Search in sources :

Example 1 with InMemoryTokenStore

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

the class TokenServicesWithTokenEnhancerTests method storeEnhancedRefreshTokenDuringRefresh.

// gh-511
@Test
public void storeEnhancedRefreshTokenDuringRefresh() {
    InMemoryTokenStore tokenStore = new InMemoryTokenStore();
    tokenServices.setSupportRefreshToken(true);
    tokenServices.setReuseRefreshToken(false);
    tokenServices.setTokenStore(tokenStore);
    OAuth2AccessToken accessToken = tokenServices.createAccessToken(authentication);
    OAuth2RefreshToken refreshToken = accessToken.getRefreshToken();
    TokenRequest tokenRequest = new TokenRequest(Collections.<String, String>emptyMap(), request.getClientId(), request.getScope(), "authorization_code");
    accessToken = tokenServices.refreshAccessToken(refreshToken.getValue(), tokenRequest);
    OAuth2RefreshToken enhancedRefreshToken = accessToken.getRefreshToken();
    OAuth2RefreshToken storedEnhancedRefreshToken = tokenStore.readRefreshToken(enhancedRefreshToken.getValue());
    assertEquals(enhancedRefreshToken.getValue(), storedEnhancedRefreshToken.getValue());
}
Also used : InMemoryTokenStore(org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore) OAuth2RefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest) Test(org.junit.Test)

Example 2 with InMemoryTokenStore

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

the class AbstractIntegrationTests method clear.

private void clear(TokenStore tokenStore) throws Exception {
    if (tokenStore instanceof Advised) {
        Advised advised = (Advised) tokenStore;
        TokenStore target = (TokenStore) advised.getTargetSource().getTarget();
        clear(target);
        return;
    }
    if (tokenStore instanceof InMemoryTokenStore) {
        ((InMemoryTokenStore) tokenStore).clear();
    }
    if (tokenStore instanceof JdbcTokenStore) {
        JdbcTemplate template = new JdbcTemplate(dataSource);
        template.execute("delete from oauth_access_token");
        template.execute("delete from oauth_refresh_token");
        template.execute("delete from oauth_client_token");
        template.execute("delete from oauth_code");
    }
}
Also used : InMemoryTokenStore(org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore) JdbcTokenStore(org.springframework.security.oauth2.provider.token.store.JdbcTokenStore) Advised(org.springframework.aop.framework.Advised) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) TokenStore(org.springframework.security.oauth2.provider.token.TokenStore) InMemoryTokenStore(org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore) JdbcTokenStore(org.springframework.security.oauth2.provider.token.store.JdbcTokenStore)

Example 3 with InMemoryTokenStore

use of org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore in project spring-cloud-framework by zhuwj921.

the class AuthorizationServerConfiguration method configure.

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    logger.debug("授权配置");
    endpoints.authenticationManager(authenticationManager).userDetailsService(// 若无,refresh_token会有UserDetailsService is required错误
    userDetailsService()).tokenStore(new InMemoryTokenStore());
}
Also used : InMemoryTokenStore(org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore)

Aggregations

InMemoryTokenStore (org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore)3 Test (org.junit.Test)1 Advised (org.springframework.aop.framework.Advised)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)1 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)1 OAuth2RefreshToken (org.springframework.security.oauth2.common.OAuth2RefreshToken)1 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)1 TokenStore (org.springframework.security.oauth2.provider.token.TokenStore)1 JdbcTokenStore (org.springframework.security.oauth2.provider.token.store.JdbcTokenStore)1