Commit 36f144ba authored by Romain Fromi's avatar Romain Fromi Committed by 陈健

Adding OAuth2ClientContextFilter to Spring Security Filter chain to catch…

Adding OAuth2ClientContextFilter to Spring Security Filter chain to catch "UserRedirectRequiredException" and redirect user to Google login page accordingly.
parent 9ae5c5cc
......@@ -2,12 +2,12 @@ package com.github.fromi.openidconnect.security;
import static org.springframework.http.HttpMethod.GET;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
......@@ -28,9 +28,14 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
return new OpenIDConnectAuthenticationFilter(LOGIN_URL);
}
@Bean
public OAuth2ClientContextFilter oAuth2ClientContextFilter() {
return new OAuth2ClientContextFilter();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.addFilterAfter(openIdConnectAuthenticationFilter(), AbstractPreAuthenticatedProcessingFilter.class)
http.addFilterAfter(oAuth2ClientContextFilter(), AbstractPreAuthenticatedProcessingFilter.class)
.addFilterAfter(openIdConnectAuthenticationFilter(), OAuth2ClientContextFilter.class)
.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint())
.and().authorizeRequests()
.antMatchers(GET, "/").permitAll()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment