use of org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter in project spring-security-oauth2-google by skate056.
the class GoogleAccessTokenConverterTest method shouldExtractAuthenticationAndScopesWhenScopeIsString.
// private DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();
@Test
public void shouldExtractAuthenticationAndScopesWhenScopeIsString() throws Exception {
Map<String, Object> map = newHashMap();
map.put(AccessTokenConverter.SCOPE, "a b");
OAuth2Authentication authentication = accessTokenConverter.extractAuthentication(map);
assertThat(authentication.getOAuth2Request().getScope(), containsInAnyOrder("a", "b"));
}
use of org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter in project spring-security-oauth by spring-projects.
the class JwtTokenStoreTests method testAuthenticationPreservesGrantType.
@Test
public void testAuthenticationPreservesGrantType() throws Exception {
DefaultAccessTokenConverter delegate = new DefaultAccessTokenConverter();
delegate.setIncludeGrantType(true);
enhancer.setAccessTokenConverter(delegate);
expectedOAuth2AccessToken = enhancer.enhance(new DefaultOAuth2AccessToken("FOO"), expectedAuthentication);
OAuth2Authentication authentication = tokenStore.readAuthentication(expectedOAuth2AccessToken.getValue());
assertEquals("password", authentication.getOAuth2Request().getGrantType());
}
use of org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter in project spring-security-oauth by spring-projects.
the class TokenServicesWithTokenEnhancerTests method customUserPreservedWhenTokenDecoded.
@Test
public void customUserPreservedWhenTokenDecoded() {
DefaultAccessTokenConverter tokenConverter = new DefaultAccessTokenConverter();
tokenConverter.setUserTokenConverter(new UserAuthenticationConverter() {
@Override
public Authentication extractAuthentication(Map<String, ?> map) {
return new FooAuthentication((String) map.get("user"));
}
@Override
public Map<String, ?> convertUserAuthentication(Authentication userAuthentication) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("user", userAuthentication.getName());
map.put("foo", "bar");
return map;
}
});
jwtTokenEnhancer.setAccessTokenConverter(tokenConverter);
OAuth2AccessToken token = tokenServices.createAccessToken(authentication);
assertEquals("bob", tokenServices.loadAuthentication(token.getValue()).getUserAuthentication().getName());
}
Aggregations