2020 */
2121package eu .openanalytics .containerproxy .auth .impl .saml ;
2222
23+ import eu .openanalytics .containerproxy .auth .UserLogoutHandler ;
2324import java .util .ArrayList ;
2425import java .util .Arrays ;
2526import java .util .Collection ;
5859import org .springframework .security .saml .SAMLBootstrap ;
5960import org .springframework .security .saml .SAMLCredential ;
6061import org .springframework .security .saml .SAMLEntryPoint ;
62+ import org .springframework .security .saml .SAMLLogoutFilter ;
6163import org .springframework .security .saml .SAMLProcessingFilter ;
6264import org .springframework .security .saml .context .SAMLContextProvider ;
6365import org .springframework .security .saml .context .SAMLContextProviderImpl ;
7375import org .springframework .security .saml .processor .SAMLProcessorImpl ;
7476import org .springframework .security .saml .userdetails .SAMLUserDetailsService ;
7577import org .springframework .security .saml .util .VelocityFactory ;
78+ import org .springframework .security .saml .websso .SingleLogoutProfile ;
79+ import org .springframework .security .saml .websso .SingleLogoutProfileImpl ;
7680import org .springframework .security .saml .websso .WebSSOProfile ;
7781import org .springframework .security .saml .websso .WebSSOProfileConsumer ;
7882import org .springframework .security .saml .websso .WebSSOProfileConsumerHoKImpl ;
8488import org .springframework .security .web .SecurityFilterChain ;
8589import org .springframework .security .web .authentication .SavedRequestAwareAuthenticationSuccessHandler ;
8690import org .springframework .security .web .authentication .SimpleUrlAuthenticationFailureHandler ;
91+ import org .springframework .security .web .authentication .logout .LogoutHandler ;
92+ import org .springframework .security .web .authentication .logout .SecurityContextLogoutHandler ;
93+ import org .springframework .security .web .authentication .logout .SimpleUrlLogoutSuccessHandler ;
8794import org .springframework .security .web .util .matcher .AntPathRequestMatcher ;
8895
8996@ Configuration
@@ -98,13 +105,43 @@ public class SAMLConfiguration {
98105 @ Inject
99106 @ Lazy
100107 private AuthenticationManager authenticationManager ;
108+
109+ @ Inject
110+ private UserLogoutHandler userLogoutHandler ;
101111
102112 @ Bean
103113 public SAMLEntryPoint samlEntryPoint () {
104114 SAMLEntryPoint samlEntryPoint = new SAMLEntryPoint ();
105115 samlEntryPoint .setDefaultProfileOptions (defaultWebSSOProfileOptions ());
106116 return samlEntryPoint ;
107117 }
118+
119+ @ Bean
120+ public SingleLogoutProfile logoutProfile () {
121+ return new SingleLogoutProfileImpl ();
122+ }
123+
124+ @ Bean
125+ public SAMLLogoutFilter samlLogoutFilter () {
126+ return new SAMLLogoutFilter (successLogoutHandler (),
127+ new LogoutHandler []{userLogoutHandler , securityContextLogoutHandler ()},
128+ new LogoutHandler []{userLogoutHandler , securityContextLogoutHandler ()});
129+ }
130+
131+ @ Bean
132+ public SecurityContextLogoutHandler securityContextLogoutHandler () {
133+ SecurityContextLogoutHandler logoutHandler = new SecurityContextLogoutHandler ();
134+ logoutHandler .setInvalidateHttpSession (true );
135+ logoutHandler .setClearAuthentication (true );
136+ return logoutHandler ;
137+ }
138+
139+ @ Bean
140+ public SimpleUrlLogoutSuccessHandler successLogoutHandler () {
141+ SimpleUrlLogoutSuccessHandler successLogoutHandler = new SimpleUrlLogoutSuccessHandler ();
142+ successLogoutHandler .setDefaultTargetUrl ("/" );
143+ return successLogoutHandler ;
144+ }
108145
109146 @ Bean
110147 public WebSSOProfileOptions defaultWebSSOProfileOptions () {
@@ -284,6 +321,7 @@ public WebSSOProfileConsumerHoKImpl hokWebSSOprofileConsumer() {
284321 public SAMLFilterSet samlFilter () throws Exception {
285322 List <SecurityFilterChain > chains = new ArrayList <SecurityFilterChain >();
286323 chains .add (new DefaultSecurityFilterChain (new AntPathRequestMatcher ("/saml/login/**" ), samlEntryPoint ()));
324+ chains .add (new DefaultSecurityFilterChain (new AntPathRequestMatcher ("/saml/logout/**" ), samlLogoutFilter ()));
287325 chains .add (new DefaultSecurityFilterChain (new AntPathRequestMatcher ("/saml/SSO/**" ), samlWebSSOProcessingFilter ()));
288326 return new SAMLFilterSet (chains );
289327 }
0 commit comments