Search in sources :

Example 1 with JwtTokenStore

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

the class RefreshTokenSupportTests method verifyAccessTokens.

protected void verifyAccessTokens(OAuth2AccessToken oldAccessToken, OAuth2AccessToken newAccessToken) {
    // make sure the new access token can be used.
    verifyTokenResponse(newAccessToken.getValue(), HttpStatus.OK);
    // the old access token is still valid because there is no state on the server.
    verifyTokenResponse(oldAccessToken.getValue(), HttpStatus.OK);
    JwtTokenStore store = (JwtTokenStore) ReflectionTestUtils.getField(services, "tokenStore");
    OAuth2AccessToken token = store.readAccessToken(oldAccessToken.getValue());
    OAuth2AccessToken refresh = ReflectionTestUtils.invokeMethod(store, "convertAccessToken", oldAccessToken.getRefreshToken().getValue());
    assertEquals(refresh.getExpiration().getTime(), token.getExpiration().getTime() + 100000);
}
Also used : JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken)

Example 2 with JwtTokenStore

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

the class JwkTokenStoreTest method readAccessTokenWhenCalledThenDelegateCalled.

@Test
public void readAccessTokenWhenCalledThenDelegateCalled() throws Exception {
    JwkTokenStore spy = spy(this.jwkTokenStore);
    JwtTokenStore delegate = mock(JwtTokenStore.class);
    when(delegate.readAccessToken(anyString())).thenReturn(null);
    Field field = ReflectionUtils.findField(spy.getClass(), "delegate");
    field.setAccessible(true);
    ReflectionUtils.setField(field, spy, delegate);
    spy.readAccessToken(anyString());
    verify(delegate).readAccessToken(anyString());
}
Also used : Field(java.lang.reflect.Field) JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with JwtTokenStore

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

the class JwkTokenStoreTest method readAuthenticationUsingAccessTokenStringWhenCalledThenDelegateCalled.

@Test
public void readAuthenticationUsingAccessTokenStringWhenCalledThenDelegateCalled() throws Exception {
    JwkTokenStore spy = spy(this.jwkTokenStore);
    JwtTokenStore delegate = mock(JwtTokenStore.class);
    when(delegate.readAuthentication(anyString())).thenReturn(null);
    Field field = ReflectionUtils.findField(spy.getClass(), "delegate");
    field.setAccessible(true);
    ReflectionUtils.setField(field, spy, delegate);
    spy.readAuthentication(anyString());
    verify(delegate).readAuthentication(anyString());
}
Also used : Field(java.lang.reflect.Field) JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with JwtTokenStore

use of org.springframework.security.oauth2.provider.token.store.JwtTokenStore 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);
}
Also used : JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) InMemoryClientDetailsServiceBuilder(org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder) Before(org.junit.Before)

Example 5 with JwtTokenStore

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

the class JwkTokenStoreTest method removeAccessTokenWhenCalledThenDelegateCalled.

@Test
public void removeAccessTokenWhenCalledThenDelegateCalled() throws Exception {
    JwkTokenStore spy = spy(this.jwkTokenStore);
    JwtTokenStore delegate = mock(JwtTokenStore.class);
    doNothing().when(delegate).removeAccessToken(any(OAuth2AccessToken.class));
    Field field = ReflectionUtils.findField(spy.getClass(), "delegate");
    field.setAccessible(true);
    ReflectionUtils.setField(field, spy, delegate);
    spy.removeAccessToken(any(OAuth2AccessToken.class));
    verify(delegate).removeAccessToken(any(OAuth2AccessToken.class));
}
Also used : Field(java.lang.reflect.Field) JwtTokenStore(org.springframework.security.oauth2.provider.token.store.JwtTokenStore) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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