use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project new-cloud by xie-summer.
the class ResourceServerConfiguration method tokenServices.
@Bean
@Primary
public DefaultTokenServices tokenServices() {
final DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
defaultTokenServices.setTokenStore(tokenStore());
defaultTokenServices.setTokenEnhancer(accessTokenConverter());
return defaultTokenServices;
}
use of org.springframework.security.oauth2.provider.token.AccessTokenConverter 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);
}
}
use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project spring-security-oauth by spring-projects.
the class JwkTokenStoreTests method readAuthenticationUsingCustomAccessTokenConverterThenAuthenticationDetailsContainsClaims.
// gh-1015
@Test
public void readAuthenticationUsingCustomAccessTokenConverterThenAuthenticationDetailsContainsClaims() throws Exception {
AccessTokenConverter customAccessTokenConverter = mock(AccessTokenConverter.class);
when(customAccessTokenConverter.extractAuthentication(anyMapOf(String.class, String.class))).thenAnswer(new Answer<OAuth2Authentication>() {
@Override
public OAuth2Authentication answer(InvocationOnMock invocation) throws Throwable {
Map<String, String> claims = (Map<String, String>) invocation.getArguments()[0];
OAuth2Authentication authentication = new OAuth2Authentication(mock(OAuth2Request.class), null);
authentication.setDetails(claims);
return authentication;
}
});
JwkVerifyingJwtAccessTokenConverter jwtVerifyingAccessTokenConverter = new JwkVerifyingJwtAccessTokenConverter(mock(JwkDefinitionSource.class));
jwtVerifyingAccessTokenConverter = spy(jwtVerifyingAccessTokenConverter);
jwtVerifyingAccessTokenConverter.setAccessTokenConverter(customAccessTokenConverter);
Map<String, String> claims = new LinkedHashMap<String, String>();
claims.put("claim1", "value1");
claims.put("claim2", "value2");
claims.put("claim3", "value3");
doReturn(claims).when(jwtVerifyingAccessTokenConverter).decode((anyString()));
JwkTokenStore spy = spy(this.jwkTokenStore);
JwtTokenStore delegate = new JwtTokenStore(jwtVerifyingAccessTokenConverter);
Field field = ReflectionUtils.findField(spy.getClass(), "delegate");
field.setAccessible(true);
ReflectionUtils.setField(field, spy, delegate);
OAuth2Authentication authentication = spy.readAuthentication(anyString());
assertEquals(claims, authentication.getDetails());
}
use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project spring-security-oauth by spring-projects.
the class CheckTokenEndpointTest method setUp.
@Before
public void setUp() {
ResourceServerTokenServices resourceServerTokenServices = mock(ResourceServerTokenServices.class);
OAuth2AccessToken accessToken = mock(OAuth2AccessToken.class);
OAuth2Authentication authentication = mock(OAuth2Authentication.class);
when(resourceServerTokenServices.readAccessToken(anyString())).thenReturn(accessToken);
when(accessToken.isExpired()).thenReturn(false);
when(accessToken.getValue()).thenReturn("access-token-1234");
when(resourceServerTokenServices.loadAuthentication(accessToken.getValue())).thenReturn(authentication);
this.checkTokenEndpoint = new CheckTokenEndpoint(resourceServerTokenServices);
AccessTokenConverter accessTokenConverter = mock(AccessTokenConverter.class);
when(accessTokenConverter.convertAccessToken(accessToken, authentication)).thenReturn(new HashMap());
this.checkTokenEndpoint.setAccessTokenConverter(accessTokenConverter);
}
use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project spring-security-oauth by spring-projects.
the class JwkTokenStoreTest method readAuthenticationUsingCustomAccessTokenConverterThenAuthenticationDetailsContainsClaims.
// gh-1015
@Test
public void readAuthenticationUsingCustomAccessTokenConverterThenAuthenticationDetailsContainsClaims() throws Exception {
AccessTokenConverter customAccessTokenConverter = mock(AccessTokenConverter.class);
when(customAccessTokenConverter.extractAuthentication(anyMapOf(String.class, String.class))).thenAnswer(new Answer<OAuth2Authentication>() {
@Override
public OAuth2Authentication answer(InvocationOnMock invocation) throws Throwable {
Map<String, String> claims = (Map<String, String>) invocation.getArguments()[0];
OAuth2Authentication authentication = new OAuth2Authentication(mock(OAuth2Request.class), null);
authentication.setDetails(claims);
return authentication;
}
});
JwkVerifyingJwtAccessTokenConverter jwtVerifyingAccessTokenConverter = new JwkVerifyingJwtAccessTokenConverter(mock(JwkDefinitionSource.class));
jwtVerifyingAccessTokenConverter = spy(jwtVerifyingAccessTokenConverter);
jwtVerifyingAccessTokenConverter.setAccessTokenConverter(customAccessTokenConverter);
Map<String, String> claims = new LinkedHashMap<String, String>();
claims.put("claim1", "value1");
claims.put("claim2", "value2");
claims.put("claim3", "value3");
doReturn(claims).when(jwtVerifyingAccessTokenConverter).decode((anyString()));
JwkTokenStore spy = spy(this.jwkTokenStore);
JwtTokenStore delegate = new JwtTokenStore(jwtVerifyingAccessTokenConverter);
Field field = ReflectionUtils.findField(spy.getClass(), "delegate");
field.setAccessible(true);
ReflectionUtils.setField(field, spy, delegate);
OAuth2Authentication authentication = spy.readAuthentication(anyString());
assertEquals(claims, authentication.getDetails());
}
Aggregations