Search in sources :

Example 1 with OAuth2ClientAuthenticationProcessingFilter

use of org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter in project spring-boot by spring-projects.

the class SsoSecurityConfigurer method oauth2SsoFilter.

private OAuth2ClientAuthenticationProcessingFilter oauth2SsoFilter(OAuth2SsoProperties sso) {
    OAuth2RestOperations restTemplate = this.applicationContext.getBean(UserInfoRestTemplateFactory.class).getUserInfoRestTemplate();
    ResourceServerTokenServices tokenServices = this.applicationContext.getBean(ResourceServerTokenServices.class);
    OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter(sso.getLoginPath());
    filter.setRestTemplate(restTemplate);
    filter.setTokenServices(tokenServices);
    filter.setApplicationEventPublisher(this.applicationContext);
    return filter;
}
Also used : OAuth2RestOperations(org.springframework.security.oauth2.client.OAuth2RestOperations) UserInfoRestTemplateFactory(org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoRestTemplateFactory) OAuth2ClientAuthenticationProcessingFilter(org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter) ResourceServerTokenServices(org.springframework.security.oauth2.provider.token.ResourceServerTokenServices)

Example 2 with OAuth2ClientAuthenticationProcessingFilter

use of org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter in project service-authorization by reportportal.

the class OAuthSecurityConfig method configure.

@Override
protected final void configure(HttpSecurity http) throws Exception {
    // @formatter:off
    http.antMatcher("/**").authorizeRequests().antMatchers(SSO_LOGIN_PATH + "/**", "/webjars/**", "/index.html", "/epam/**", "/info", "/health", "/api-docs/**").permitAll().anyRequest().authenticated().and().csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    CompositeFilter authCompositeFilter = new CompositeFilter();
    List<OAuth2ClientAuthenticationProcessingFilter> additionalFilters = ImmutableList.<OAuth2ClientAuthenticationProcessingFilter>builder().addAll(getDefaultFilters(oauth2ClientContext)).addAll(getAdditionalFilters(oauth2ClientContext)).build();
    /* make sure filters have correct exception handler */
    additionalFilters.forEach(filter -> filter.setAuthenticationFailureHandler(OAUTH_ERROR_HANDLER));
    authCompositeFilter.setFilters(additionalFilters);
    // install additional OAuth Authentication filters
    http.addFilterAfter(authCompositeFilter, BasicAuthenticationFilter.class);
// @formatter:on
}
Also used : CompositeFilter(org.springframework.web.filter.CompositeFilter) OAuth2ClientAuthenticationProcessingFilter(org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter)

Example 3 with OAuth2ClientAuthenticationProcessingFilter

use of org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter in project vorto by eclipse.

the class SecurityConfiguration method newSsoFilter.

private Filter newSsoFilter(String defaultFilterProcessesUrl, UserInfoTokenServices tokenService, AccessTokenProvider accessTokenProvider, OAuth2RestTemplate restTemplate) {
    restTemplate.setAccessTokenProvider(accessTokenProvider);
    OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter(defaultFilterProcessesUrl);
    filter.setAuthenticationSuccessHandler(successHandler);
    tokenService.setRestTemplate(restTemplate);
    filter.setRestTemplate(restTemplate);
    filter.setTokenServices(tokenService);
    return filter;
}
Also used : OAuth2ClientAuthenticationProcessingFilter(org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter)

Example 4 with OAuth2ClientAuthenticationProcessingFilter

use of org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter in project spring-boot-quick by vector4wang.

the class WebSecurityConfig method sso.

private Filter sso() {
    OAuth2ClientAuthenticationProcessingFilter githubFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/github");
    OAuth2RestTemplate githubTemplate = new OAuth2RestTemplate(github(), oauth2ClientContext);
    githubFilter.setRestTemplate(githubTemplate);
    githubFilter.setTokenServices(new UserInfoTokenServices(githubResource().getUserInfoUri(), github().getClientId()));
    return githubFilter;
}
Also used : UserInfoTokenServices(org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices) OAuth2ClientAuthenticationProcessingFilter(org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate)

Aggregations

OAuth2ClientAuthenticationProcessingFilter (org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter)4 UserInfoRestTemplateFactory (org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoRestTemplateFactory)1 UserInfoTokenServices (org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices)1 OAuth2RestOperations (org.springframework.security.oauth2.client.OAuth2RestOperations)1 OAuth2RestTemplate (org.springframework.security.oauth2.client.OAuth2RestTemplate)1 ResourceServerTokenServices (org.springframework.security.oauth2.provider.token.ResourceServerTokenServices)1 CompositeFilter (org.springframework.web.filter.CompositeFilter)1