Search in sources :

Example 1 with AccessTokenConverter

use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project theskeleton by codenergic.

the class SecurityConfig method accessTokenConverter.

@Bean
public AccessTokenConverter accessTokenConverter(UserService userService) {
    DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();
    accessTokenConverter.setUserTokenConverter(new UserAccessTokenAuthenticationConverter());
    return accessTokenConverter;
}
Also used : DefaultAccessTokenConverter(org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter) Bean(org.springframework.context.annotation.Bean)

Example 2 with AccessTokenConverter

use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project theskeleton by codenergic.

the class SecurityConfig method jwtAccessTokenConverter.

/**
 * Token converter and enhancer
 * @return
 */
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter(AccessTokenConverter accessTokenConverter) {
    JwtAccessTokenConverter tokenConverter = new JwtAccessTokenConverter();
    tokenConverter.setAccessTokenConverter(accessTokenConverter);
    return tokenConverter;
}
Also used : JwtAccessTokenConverter(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter) Bean(org.springframework.context.annotation.Bean)

Example 3 with AccessTokenConverter

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);
}
Also used : AccessTokenConverter(org.springframework.security.oauth2.provider.token.AccessTokenConverter) HashMap(java.util.HashMap) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) ResourceServerTokenServices(org.springframework.security.oauth2.provider.token.ResourceServerTokenServices) Before(org.junit.Before)

Example 4 with AccessTokenConverter

use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project openlmis-stockmanagement by OpenLMIS.

the class ResourceServerSecurityConfiguration method remoteTokenServices.

/**
 * RemoteTokenServices bean initializer.
 *
 * @param checkTokenUrl url to check tokens against
 * @param clientId      client's id
 * @param clientSecret  client's secret
 * @return token services
 */
@Bean
@Autowired
public RemoteTokenServices remoteTokenServices(@Value("${auth.server.url}") String checkTokenUrl, @Value("${auth.server.clientId}") String clientId, @Value("${auth.server.clientSecret}") String clientSecret) {
    final RemoteTokenServices remoteTokenServices = new RemoteTokenServices();
    remoteTokenServices.setCheckTokenEndpointUrl(checkTokenUrl);
    remoteTokenServices.setClientId(clientId);
    remoteTokenServices.setClientSecret(clientSecret);
    remoteTokenServices.setAccessTokenConverter(accessTokenConverter());
    return remoteTokenServices;
}
Also used : RemoteTokenServices(org.springframework.security.oauth2.provider.token.RemoteTokenServices) Autowired(org.springframework.beans.factory.annotation.Autowired) Bean(org.springframework.context.annotation.Bean)

Example 5 with AccessTokenConverter

use of org.springframework.security.oauth2.provider.token.AccessTokenConverter in project flytecnologia-api by jullierme.

the class FlyAutorizationServerConfig method configure.

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
    tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), jwtAccessTokenConverter));
    endpoints.tokenStore(tokenStore()).tokenEnhancer(tokenEnhancerChain).authenticationManager(authenticationManager).accessTokenConverter(jwtAccessTokenConverter).reuseRefreshTokens(false);
/* endpoints
                .tokenStore(tokenStore())
                .accessTokenConverter(jwtAccessTokenConverter)
                .reuseRefreshTokens(false)
                .authenticationManager(authenticationManager);*/
}
Also used : TokenEnhancerChain(org.springframework.security.oauth2.provider.token.TokenEnhancerChain)

Aggregations

Bean (org.springframework.context.annotation.Bean)8 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)4 Test (org.junit.Test)3 DefaultAccessTokenConverter (org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter)3 TokenEnhancerChain (org.springframework.security.oauth2.provider.token.TokenEnhancerChain)3 JwtAccessTokenConverter (org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter)3 HashMap (java.util.HashMap)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Primary (org.springframework.context.annotation.Primary)2 Resource (org.springframework.core.io.Resource)2 AccessTokenConverter (org.springframework.security.oauth2.provider.token.AccessTokenConverter)2 CustomerAccessTokenConverter (com.framework.auth.config.support.CustomerAccessTokenConverter)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 CustomTokenServices (org.motechproject.mots.security.token.CustomTokenServices)1