Search in sources :

Example 11 with JwtTokenStore

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

the class Application method tokenStore.

@Bean
public JwtTokenStore tokenStore() throws Exception {
    JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
    // N.B. in a real system you would have to configure the verifierKey (or use JdbcTokenStore)
    enhancer.afterPropertiesSet();
    return new JwtTokenStore(enhancer);
}
Also used : JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) JwtAccessTokenConverter(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter) Bean(org.springframework.context.annotation.Bean)

Example 12 with JwtTokenStore

use of org.springframework.security.oauth2.provider.token.store.JwtTokenStore 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());
}
Also used : JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) Matchers.anyString(org.mockito.Matchers.anyString) LinkedHashMap(java.util.LinkedHashMap) AccessTokenConverter(org.springframework.security.oauth2.provider.token.AccessTokenConverter) Field(java.lang.reflect.Field) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with JwtTokenStore

use of org.springframework.security.oauth2.provider.token.store.JwtTokenStore in project Spring-5.0-By-Example by PacktPublishing.

the class OAuthTokenConfiguration method tokenStore.

@Bean
public JwtTokenStore tokenStore() throws Exception {
    JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
    enhancer.setSigningKey(privateKey);
    enhancer.setVerifierKey(publicKey);
    enhancer.afterPropertiesSet();
    return new JwtTokenStore(enhancer);
}
Also used : JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) JwtAccessTokenConverter(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter) Bean(org.springframework.context.annotation.Bean)

Example 14 with JwtTokenStore

use of org.springframework.security.oauth2.provider.token.store.JwtTokenStore in project Spring-5.0-By-Example by PacktPublishing.

the class OAuthTokenConfiguration method tokenStore.

@Bean
public JwtTokenStore tokenStore() throws Exception {
    JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
    enhancer.setSigningKey(privateKey);
    enhancer.setVerifierKey(publicKey);
    enhancer.afterPropertiesSet();
    return new JwtTokenStore(enhancer);
}
Also used : JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) JwtAccessTokenConverter(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter) Bean(org.springframework.context.annotation.Bean)

Example 15 with JwtTokenStore

use of org.springframework.security.oauth2.provider.token.store.JwtTokenStore in project Spring-5.0-By-Example by PacktPublishing.

the class OAuthTokenConfiguration method tokenStore.

@Bean
public JwtTokenStore tokenStore() throws Exception {
    JwtAccessTokenConverter enhancer = new JwtAccessTokenConverter();
    enhancer.setSigningKey(privateKey);
    enhancer.setVerifierKey(publicKey);
    enhancer.afterPropertiesSet();
    return new JwtTokenStore(enhancer);
}
Also used : JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) JwtAccessTokenConverter(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter) Bean(org.springframework.context.annotation.Bean)

Aggregations

JwtTokenStore (org.springframework.security.oauth2.provider.token.store.JwtTokenStore)16 Bean (org.springframework.context.annotation.Bean)8 JwtAccessTokenConverter (org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter)8 Field (java.lang.reflect.Field)6 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)4 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 SignatureVerifier (org.springframework.security.jwt.crypto.sign.SignatureVerifier)1 InMemoryClientDetailsServiceBuilder (org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1 AccessTokenConverter (org.springframework.security.oauth2.provider.token.AccessTokenConverter)1 JwtClaimsSetVerifier (org.springframework.security.oauth2.provider.token.store.JwtClaimsSetVerifier)1