20
20
*/
21
21
package eu .openanalytics .containerproxy .auth .impl .saml ;
22
22
23
+ import eu .openanalytics .containerproxy .auth .UserLogoutHandler ;
23
24
import java .util .ArrayList ;
24
25
import java .util .Arrays ;
25
26
import java .util .Collection ;
58
59
import org .springframework .security .saml .SAMLBootstrap ;
59
60
import org .springframework .security .saml .SAMLCredential ;
60
61
import org .springframework .security .saml .SAMLEntryPoint ;
62
+ import org .springframework .security .saml .SAMLLogoutFilter ;
61
63
import org .springframework .security .saml .SAMLProcessingFilter ;
62
64
import org .springframework .security .saml .context .SAMLContextProvider ;
63
65
import org .springframework .security .saml .context .SAMLContextProviderImpl ;
73
75
import org .springframework .security .saml .processor .SAMLProcessorImpl ;
74
76
import org .springframework .security .saml .userdetails .SAMLUserDetailsService ;
75
77
import org .springframework .security .saml .util .VelocityFactory ;
78
+ import org .springframework .security .saml .websso .SingleLogoutProfile ;
79
+ import org .springframework .security .saml .websso .SingleLogoutProfileImpl ;
76
80
import org .springframework .security .saml .websso .WebSSOProfile ;
77
81
import org .springframework .security .saml .websso .WebSSOProfileConsumer ;
78
82
import org .springframework .security .saml .websso .WebSSOProfileConsumerHoKImpl ;
84
88
import org .springframework .security .web .SecurityFilterChain ;
85
89
import org .springframework .security .web .authentication .SavedRequestAwareAuthenticationSuccessHandler ;
86
90
import 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 ;
87
94
import org .springframework .security .web .util .matcher .AntPathRequestMatcher ;
88
95
89
96
@ Configuration
@@ -98,13 +105,43 @@ public class SAMLConfiguration {
98
105
@ Inject
99
106
@ Lazy
100
107
private AuthenticationManager authenticationManager ;
108
+
109
+ @ Inject
110
+ private UserLogoutHandler userLogoutHandler ;
101
111
102
112
@ Bean
103
113
public SAMLEntryPoint samlEntryPoint () {
104
114
SAMLEntryPoint samlEntryPoint = new SAMLEntryPoint ();
105
115
samlEntryPoint .setDefaultProfileOptions (defaultWebSSOProfileOptions ());
106
116
return samlEntryPoint ;
107
117
}
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
+ }
108
145
109
146
@ Bean
110
147
public WebSSOProfileOptions defaultWebSSOProfileOptions () {
@@ -284,6 +321,7 @@ public WebSSOProfileConsumerHoKImpl hokWebSSOprofileConsumer() {
284
321
public SAMLFilterSet samlFilter () throws Exception {
285
322
List <SecurityFilterChain > chains = new ArrayList <SecurityFilterChain >();
286
323
chains .add (new DefaultSecurityFilterChain (new AntPathRequestMatcher ("/saml/login/**" ), samlEntryPoint ()));
324
+ chains .add (new DefaultSecurityFilterChain (new AntPathRequestMatcher ("/saml/logout/**" ), samlLogoutFilter ()));
287
325
chains .add (new DefaultSecurityFilterChain (new AntPathRequestMatcher ("/saml/SSO/**" ), samlWebSSOProcessingFilter ()));
288
326
return new SAMLFilterSet (chains );
289
327
}
0 commit comments