use of org.springframework.security.oauth2.provider.token.TokenEnhancer in project spring-security-oauth by spring-projects.
the class AbstractDefaultTokenServicesTests method testRefreshTokenRequestHasRefreshFlag.
@Test
public void testRefreshTokenRequestHasRefreshFlag() throws Exception {
ExpiringOAuth2RefreshToken expectedExpiringRefreshToken = (ExpiringOAuth2RefreshToken) getTokenServices().createAccessToken(createAuthentication()).getRefreshToken();
TokenRequest tokenRequest = new TokenRequest(Collections.singletonMap("client_id", "id"), "id", Collections.singleton("read"), null);
final AtomicBoolean called = new AtomicBoolean(false);
getTokenServices().setTokenEnhancer(new TokenEnhancer() {
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
assertTrue(authentication.getOAuth2Request().isRefresh());
called.set(true);
return accessToken;
}
});
getTokenServices().refreshAccessToken(expectedExpiringRefreshToken.getValue(), tokenRequest);
assertTrue(called.get());
}
use of org.springframework.security.oauth2.provider.token.TokenEnhancer in project spring-security-oauth by spring-projects.
the class TokenServicesWithTokenEnhancerTests method additionalInfoPreservedWhenTokenDecoded.
@Test
public void additionalInfoPreservedWhenTokenDecoded() {
TokenEnhancer info = new TokenEnhancer() {
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken);
result.getAdditionalInformation().put("foo", "bar");
return result;
}
};
enhancer.setTokenEnhancers(Arrays.<TokenEnhancer>asList(info, jwtTokenEnhancer));
OAuth2AccessToken token = tokenServices.createAccessToken(authentication);
assertEquals("bar", token.getAdditionalInformation().get("foo"));
assertEquals("bar", tokenServices.readAccessToken(token.getValue()).getAdditionalInformation().get("foo"));
}
use of org.springframework.security.oauth2.provider.token.TokenEnhancer in project spring-security-oauth by spring-projects.
the class TokenServicesWithTokenEnhancerTests method init.
@Before
public void init() throws Exception {
tokenServices = new DefaultTokenServices();
tokenServices.setClientDetailsService(new InMemoryClientDetailsServiceBuilder().withClient("client").authorizedGrantTypes(new String[] { "authorization_code", "refresh_token" }).scopes("read").secret("secret").and().build());
enhancer.setTokenEnhancers(Arrays.<TokenEnhancer>asList(jwtTokenEnhancer));
jwtTokenEnhancer.afterPropertiesSet();
tokenServices.setTokenStore(new JwtTokenStore(jwtTokenEnhancer));
tokenServices.setTokenEnhancer(enhancer);
}
use of org.springframework.security.oauth2.provider.token.TokenEnhancer in project spring-security-oauth by spring-projects.
the class AbstractPersistentDefaultTokenServicesTests method testTokenEnhancerUpdatesStoredTokens.
@Test
public void testTokenEnhancerUpdatesStoredTokens() throws Exception {
final ExpiringOAuth2RefreshToken refreshToken = new DefaultExpiringOAuth2RefreshToken("testToken", new Date(System.currentTimeMillis() + 100000));
getTokenServices().setTokenEnhancer(new TokenEnhancer() {
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken);
result.setRefreshToken(refreshToken);
return result;
}
});
OAuth2Authentication authentication = createAuthentication();
OAuth2AccessToken original = getTokenServices().createAccessToken(authentication);
assertTrue(original.getRefreshToken().equals(refreshToken));
OAuth2AccessToken result = getTokenStore().getAccessToken(authentication);
assertEquals(original, result);
assertEquals(refreshToken, result.getRefreshToken());
assertEquals(refreshToken, getTokenStore().readRefreshToken(refreshToken.getValue()));
}
use of org.springframework.security.oauth2.provider.token.TokenEnhancer in project paascloud-master by paascloud.
the class PcAuthorizationServerConfig method configure.
/**
* Configure.
*
* @param endpoints the endpoints
*
* @throws Exception the exception
*/
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore).authenticationManager(authenticationManager).userDetailsService(userDetailsService);
if (jwtAccessTokenConverter != null && jwtTokenEnhancer != null) {
TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
List<TokenEnhancer> enhancers = new ArrayList<>();
enhancers.add(jwtTokenEnhancer);
enhancers.add(jwtAccessTokenConverter);
enhancerChain.setTokenEnhancers(enhancers);
endpoints.tokenEnhancer(enhancerChain).accessTokenConverter(jwtAccessTokenConverter);
}
}
Aggregations