Search in sources :

Example 1 with OAuth2RefreshTokenAuthenticationProvider

use of org.springframework.security.oauth2.server.authorization.authentication.OAuth2RefreshTokenAuthenticationProvider in project spring-authorization-server by spring-projects.

the class OAuth2RefreshTokenAuthenticationProviderTests method setUp.

@Before
public void setUp() {
    this.authorizationService = mock(OAuth2AuthorizationService.class);
    this.jwtEncoder = mock(JwtEncoder.class);
    when(this.jwtEncoder.encode(any(), any())).thenReturn(createJwt(Collections.singleton("scope1")));
    this.jwtCustomizer = mock(OAuth2TokenCustomizer.class);
    JwtGenerator jwtGenerator = new JwtGenerator(this.jwtEncoder);
    jwtGenerator.setJwtCustomizer(this.jwtCustomizer);
    this.accessTokenCustomizer = mock(OAuth2TokenCustomizer.class);
    OAuth2AccessTokenGenerator accessTokenGenerator = new OAuth2AccessTokenGenerator();
    accessTokenGenerator.setAccessTokenCustomizer(this.accessTokenCustomizer);
    OAuth2RefreshTokenGenerator refreshTokenGenerator = new OAuth2RefreshTokenGenerator();
    OAuth2TokenGenerator<OAuth2Token> delegatingTokenGenerator = new DelegatingOAuth2TokenGenerator(jwtGenerator, accessTokenGenerator, refreshTokenGenerator);
    this.tokenGenerator = spy(new OAuth2TokenGenerator<OAuth2Token>() {

        @Override
        public OAuth2Token generate(OAuth2TokenContext context) {
            return delegatingTokenGenerator.generate(context);
        }
    });
    this.authenticationProvider = new OAuth2RefreshTokenAuthenticationProvider(this.authorizationService, this.tokenGenerator);
    ProviderSettings providerSettings = ProviderSettings.builder().issuer("https://provider.com").build();
    ProviderContextHolder.setProviderContext(new ProviderContext(providerSettings, null));
}
Also used : ProviderContext(org.springframework.security.oauth2.server.authorization.context.ProviderContext) OAuth2Token(org.springframework.security.oauth2.core.OAuth2Token) ProviderSettings(org.springframework.security.oauth2.server.authorization.config.ProviderSettings) JwtEncoder(org.springframework.security.oauth2.jwt.JwtEncoder) OAuth2TokenCustomizer(org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer) DelegatingOAuth2TokenGenerator(org.springframework.security.oauth2.server.authorization.DelegatingOAuth2TokenGenerator) JwtGenerator(org.springframework.security.oauth2.server.authorization.JwtGenerator) OAuth2RefreshTokenGenerator(org.springframework.security.oauth2.server.authorization.OAuth2RefreshTokenGenerator) OAuth2TokenGenerator(org.springframework.security.oauth2.server.authorization.OAuth2TokenGenerator) DelegatingOAuth2TokenGenerator(org.springframework.security.oauth2.server.authorization.DelegatingOAuth2TokenGenerator) OAuth2TokenContext(org.springframework.security.oauth2.server.authorization.OAuth2TokenContext) OAuth2AuthorizationService(org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService) OAuth2AccessTokenGenerator(org.springframework.security.oauth2.server.authorization.OAuth2AccessTokenGenerator) Before(org.junit.Before)

Example 2 with OAuth2RefreshTokenAuthenticationProvider

use of org.springframework.security.oauth2.server.authorization.authentication.OAuth2RefreshTokenAuthenticationProvider in project spring-authorization-server by spring-projects.

the class OAuth2TokenEndpointConfigurer method createDefaultAuthenticationProviders.

private <B extends HttpSecurityBuilder<B>> List<AuthenticationProvider> createDefaultAuthenticationProviders(B builder) {
    List<AuthenticationProvider> authenticationProviders = new ArrayList<>();
    OAuth2AuthorizationService authorizationService = OAuth2ConfigurerUtils.getAuthorizationService(builder);
    OAuth2TokenGenerator<? extends OAuth2Token> tokenGenerator = OAuth2ConfigurerUtils.getTokenGenerator(builder);
    OAuth2AuthorizationCodeAuthenticationProvider authorizationCodeAuthenticationProvider = new OAuth2AuthorizationCodeAuthenticationProvider(authorizationService, tokenGenerator);
    authenticationProviders.add(authorizationCodeAuthenticationProvider);
    OAuth2RefreshTokenAuthenticationProvider refreshTokenAuthenticationProvider = new OAuth2RefreshTokenAuthenticationProvider(authorizationService, tokenGenerator);
    authenticationProviders.add(refreshTokenAuthenticationProvider);
    OAuth2ClientCredentialsAuthenticationProvider clientCredentialsAuthenticationProvider = new OAuth2ClientCredentialsAuthenticationProvider(authorizationService, tokenGenerator);
    authenticationProviders.add(clientCredentialsAuthenticationProvider);
    return authenticationProviders;
}
Also used : OAuth2AuthorizationCodeAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeAuthenticationProvider) OAuth2ClientCredentialsAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientCredentialsAuthenticationProvider) OAuth2AuthorizationService(org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService) AuthenticationProvider(org.springframework.security.authentication.AuthenticationProvider) OAuth2RefreshTokenAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2RefreshTokenAuthenticationProvider) OAuth2AuthorizationCodeAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeAuthenticationProvider) OAuth2ClientCredentialsAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientCredentialsAuthenticationProvider) ArrayList(java.util.ArrayList) OAuth2RefreshTokenAuthenticationProvider(org.springframework.security.oauth2.server.authorization.authentication.OAuth2RefreshTokenAuthenticationProvider)

Aggregations

OAuth2AuthorizationService (org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 AuthenticationProvider (org.springframework.security.authentication.AuthenticationProvider)1 OAuth2Token (org.springframework.security.oauth2.core.OAuth2Token)1 JwtEncoder (org.springframework.security.oauth2.jwt.JwtEncoder)1 DelegatingOAuth2TokenGenerator (org.springframework.security.oauth2.server.authorization.DelegatingOAuth2TokenGenerator)1 JwtGenerator (org.springframework.security.oauth2.server.authorization.JwtGenerator)1 OAuth2AccessTokenGenerator (org.springframework.security.oauth2.server.authorization.OAuth2AccessTokenGenerator)1 OAuth2RefreshTokenGenerator (org.springframework.security.oauth2.server.authorization.OAuth2RefreshTokenGenerator)1 OAuth2TokenContext (org.springframework.security.oauth2.server.authorization.OAuth2TokenContext)1 OAuth2TokenCustomizer (org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer)1 OAuth2TokenGenerator (org.springframework.security.oauth2.server.authorization.OAuth2TokenGenerator)1 OAuth2AuthorizationCodeAuthenticationProvider (org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeAuthenticationProvider)1 OAuth2ClientCredentialsAuthenticationProvider (org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientCredentialsAuthenticationProvider)1 OAuth2RefreshTokenAuthenticationProvider (org.springframework.security.oauth2.server.authorization.authentication.OAuth2RefreshTokenAuthenticationProvider)1 ProviderSettings (org.springframework.security.oauth2.server.authorization.config.ProviderSettings)1 ProviderContext (org.springframework.security.oauth2.server.authorization.context.ProviderContext)1