Search in sources :

Example 1 with DefaultAccessTokenConverter

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"));
}
Also used : OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Test(org.junit.Test)

Example 2 with DefaultAccessTokenConverter

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());
}
Also used : DefaultAccessTokenConverter(org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Test(org.junit.Test)

Example 3 with DefaultAccessTokenConverter

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());
}
Also used : OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)3 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Authentication (org.springframework.security.core.Authentication)1 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)1 DefaultAccessTokenConverter (org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter)1