Search in sources :

Example 1 with ProviderSettings

use of org.springframework.security.oauth2.server.authorization.config.ProviderSettings 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 ProviderSettings

use of org.springframework.security.oauth2.server.authorization.config.ProviderSettings in project spring-authorization-server by spring-projects.

the class OAuth2ClientCredentialsAuthenticationProviderTests method setUp.

@Before
public void setUp() {
    this.authorizationService = mock(OAuth2AuthorizationService.class);
    this.jwtEncoder = mock(JwtEncoder.class);
    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);
    OAuth2TokenGenerator<OAuth2Token> delegatingTokenGenerator = new DelegatingOAuth2TokenGenerator(jwtGenerator, accessTokenGenerator);
    this.tokenGenerator = spy(new OAuth2TokenGenerator<OAuth2Token>() {

        @Override
        public OAuth2Token generate(OAuth2TokenContext context) {
            return delegatingTokenGenerator.generate(context);
        }
    });
    this.authenticationProvider = new OAuth2ClientCredentialsAuthenticationProvider(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) 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 3 with ProviderSettings

use of org.springframework.security.oauth2.server.authorization.config.ProviderSettings in project spring-authorization-server by spring-projects.

the class OAuth2AccessTokenGeneratorTests method setUp.

@Before
public void setUp() {
    this.accessTokenCustomizer = mock(OAuth2TokenCustomizer.class);
    this.accessTokenGenerator = new OAuth2AccessTokenGenerator();
    this.accessTokenGenerator.setAccessTokenCustomizer(this.accessTokenCustomizer);
    ProviderSettings providerSettings = ProviderSettings.builder().issuer("https://provider.com").build();
    this.providerContext = new ProviderContext(providerSettings, null);
}
Also used : ProviderContext(org.springframework.security.oauth2.server.authorization.context.ProviderContext) ProviderSettings(org.springframework.security.oauth2.server.authorization.config.ProviderSettings) Before(org.junit.Before)

Example 4 with ProviderSettings

use of org.springframework.security.oauth2.server.authorization.config.ProviderSettings in project spring-authorization-server by spring-projects.

the class OAuth2TokenEndpointConfigurer method init.

@Override
<B extends HttpSecurityBuilder<B>> void init(B builder) {
    ProviderSettings providerSettings = OAuth2ConfigurerUtils.getProviderSettings(builder);
    this.requestMatcher = new AntPathRequestMatcher(providerSettings.getTokenEndpoint(), HttpMethod.POST.name());
    List<AuthenticationProvider> authenticationProviders = !this.authenticationProviders.isEmpty() ? this.authenticationProviders : createDefaultAuthenticationProviders(builder);
    authenticationProviders.forEach(authenticationProvider -> builder.authenticationProvider(postProcess(authenticationProvider)));
}
Also used : ProviderSettings(org.springframework.security.oauth2.server.authorization.config.ProviderSettings) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) 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)

Example 5 with ProviderSettings

use of org.springframework.security.oauth2.server.authorization.config.ProviderSettings in project spring-authorization-server by spring-projects.

the class OAuth2TokenRevocationEndpointConfigurer method configure.

@Override
<B extends HttpSecurityBuilder<B>> void configure(B builder) {
    AuthenticationManager authenticationManager = builder.getSharedObject(AuthenticationManager.class);
    ProviderSettings providerSettings = OAuth2ConfigurerUtils.getProviderSettings(builder);
    OAuth2TokenRevocationEndpointFilter revocationEndpointFilter = new OAuth2TokenRevocationEndpointFilter(authenticationManager, providerSettings.getTokenRevocationEndpoint());
    if (this.revocationRequestConverter != null) {
        revocationEndpointFilter.setAuthenticationConverter(this.revocationRequestConverter);
    }
    if (this.revocationResponseHandler != null) {
        revocationEndpointFilter.setAuthenticationSuccessHandler(this.revocationResponseHandler);
    }
    if (this.errorResponseHandler != null) {
        revocationEndpointFilter.setAuthenticationFailureHandler(this.errorResponseHandler);
    }
    builder.addFilterAfter(postProcess(revocationEndpointFilter), FilterSecurityInterceptor.class);
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) OAuth2TokenRevocationEndpointFilter(org.springframework.security.oauth2.server.authorization.web.OAuth2TokenRevocationEndpointFilter) ProviderSettings(org.springframework.security.oauth2.server.authorization.config.ProviderSettings)

Aggregations

ProviderSettings (org.springframework.security.oauth2.server.authorization.config.ProviderSettings)29 ProviderContext (org.springframework.security.oauth2.server.authorization.context.ProviderContext)13 Test (org.junit.Test)7 FilterChain (javax.servlet.FilterChain)6 Before (org.junit.Before)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)6 AntPathRequestMatcher (org.springframework.security.web.util.matcher.AntPathRequestMatcher)6 AuthenticationProvider (org.springframework.security.authentication.AuthenticationProvider)5 OrRequestMatcher (org.springframework.security.web.util.matcher.OrRequestMatcher)5 JwtEncoder (org.springframework.security.oauth2.jwt.JwtEncoder)4 OAuth2AuthorizationService (org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService)4 OAuth2TokenCustomizer (org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer)4 OAuth2Token (org.springframework.security.oauth2.core.OAuth2Token)3 DelegatingOAuth2TokenGenerator (org.springframework.security.oauth2.server.authorization.DelegatingOAuth2TokenGenerator)3 JwtGenerator (org.springframework.security.oauth2.server.authorization.JwtGenerator)3 OAuth2AccessTokenGenerator (org.springframework.security.oauth2.server.authorization.OAuth2AccessTokenGenerator)3 OAuth2TokenContext (org.springframework.security.oauth2.server.authorization.OAuth2TokenContext)3 OAuth2TokenGenerator (org.springframework.security.oauth2.server.authorization.OAuth2TokenGenerator)3