Skip to content

Commit 4af6769

Browse files
committed
Remove the need for LogoutController
1 parent a99795d commit 4af6769

File tree

5 files changed

+28
-55
lines changed

5 files changed

+28
-55
lines changed

src/main/java/eu/openanalytics/containerproxy/auth/IAuthenticationBackend.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ public interface IAuthenticationBackend {
5959
public default String getLogoutSuccessURL() {
6060
return "/login";
6161
}
62-
62+
63+
public default String getLogoutURL() {
64+
return "/logout";
65+
}
66+
6367
public default void customizeContainer(ContainerSpec spec) {
6468
// Default: do nothing.
6569
}

src/main/java/eu/openanalytics/containerproxy/auth/impl/SAMLAuthenticationBackend.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public void configureAuthenticationManagerBuilder(AuthenticationManagerBuilder a
8686
auth.authenticationProvider(samlAuthenticationProvider);
8787
}
8888

89+
@Override
90+
public String getLogoutURL() {
91+
if (environment.getProperty("proxy.saml.logout-url") != null) {
92+
return "/logout";
93+
}
94+
return "/saml/logout";
95+
}
96+
8997
@Override
9098
public String getLogoutSuccessURL() {
9199
String logoutURL = environment.getProperty("proxy.saml.logout-url");

src/main/java/eu/openanalytics/containerproxy/auth/impl/saml/SAMLConfiguration.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,7 @@
5555
import org.springframework.security.core.authority.SimpleGrantedAuthority;
5656
import org.springframework.security.core.userdetails.User;
5757
import org.springframework.security.core.userdetails.UsernameNotFoundException;
58-
import org.springframework.security.saml.SAMLAuthenticationProvider;
59-
import org.springframework.security.saml.SAMLBootstrap;
60-
import org.springframework.security.saml.SAMLCredential;
61-
import org.springframework.security.saml.SAMLEntryPoint;
62-
import org.springframework.security.saml.SAMLLogoutFilter;
63-
import org.springframework.security.saml.SAMLProcessingFilter;
58+
import org.springframework.security.saml.*;
6459
import org.springframework.security.saml.context.SAMLContextProvider;
6560
import org.springframework.security.saml.context.SAMLContextProviderImpl;
6661
import org.springframework.security.saml.key.EmptyKeyManager;
@@ -128,6 +123,16 @@ public SAMLLogoutFilter samlLogoutFilter() {
128123
new LogoutHandler[]{userLogoutHandler, securityContextLogoutHandler()});
129124
}
130125

126+
/**
127+
* Filter responsible for the `/saml/SingleLogout` endpoint. This makes it possible for users to logout in the IDP
128+
* or any other application and get automatically logged out in ShinyProxy as well.
129+
*/
130+
@Bean
131+
public SAMLLogoutProcessingFilter samlLogoutProcessingFilter() {
132+
return new SAMLLogoutProcessingFilter(successLogoutHandler(),
133+
securityContextLogoutHandler());
134+
}
135+
131136
@Bean
132137
public SecurityContextLogoutHandler securityContextLogoutHandler() {
133138
SecurityContextLogoutHandler logoutHandler = new SecurityContextLogoutHandler();
@@ -322,6 +327,7 @@ public SAMLFilterSet samlFilter() throws Exception {
322327
List<SecurityFilterChain> chains = new ArrayList<SecurityFilterChain>();
323328
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"), samlEntryPoint()));
324329
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"), samlLogoutFilter()));
330+
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SingleLogout/**"), samlLogoutProcessingFilter()));
325331
chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"), samlWebSSOProcessingFilter()));
326332
return new SAMLFilterSet(chains);
327333
}

src/main/java/eu/openanalytics/containerproxy/security/WebSecurityConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ protected void configure(HttpSecurity http) throws Exception {
135135
.loginPage("/login")
136136
.and()
137137
.logout()
138-
.logoutRequestMatcher(new AntPathRequestMatcher("/simple/logout"))
138+
.logoutUrl(auth.getLogoutURL())
139+
// important: set the next option after logoutUrl because it would otherwise get overwritten
140+
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
139141
.addLogoutHandler(logoutHandler)
140142
.logoutSuccessUrl(auth.getLogoutSuccessURL());
141143

src/main/java/eu/openanalytics/containerproxy/ui/LogoutController.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)