Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit 9aa16ff

Browse files
author
Dominik Frantisek Bucik
committed
feat: 🎸 Extended list of internal referrers for sess. invalider
Via property _saml.internalReferrers_ it can be configured which referrers are considered as internal and in such a cases session will not be invalidated. The property has to be list of URLs, separated by a comma, and the matching is done as a prefix of the current referrer
1 parent 3949857 commit 9aa16ff

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

perun-oidc-server-webapp/src/main/webapp/WEB-INF/user-context.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@
126126
<prop key="saml.keystore.password">pass</prop>
127127
<prop key="saml.keystore.defaultKey">pass</prop>
128128
<prop key="saml.keystore.defaultKeyPass">pass</prop>
129-
<prop key="saml.idp.defaultIdpEntityId">https://login.cesnet.cz/idp/</prop>
129+
<prop key="saml.idp.defaultIdpEntityId"/>
130130
<prop key="saml.idp.metadataLocation"/> <!-- i.e. /etc/perun/login-cesnet-metadata.xml -->
131131
<prop key="saml.idp.metadataUrl"/> <!-- i.e. https://login.cesnet.cz/proxy/module.php/metadata -->
132-
<prop key="saml.proxy.enabled">true</prop>
133-
<prop key="saml.proxy.spEntityId">https://login.cesnet.cz/proxy/</prop>
132+
<prop key="saml.proxy.spEntityId"/>
133+
<prop key="saml.internalReferrers"/> <!-- comma separated list of URLs (which are matched as prefixes) -->
134134
<prop key="saml.acrs.reserverdPrefixes">urn:cesnet:</prop>
135135
<prop key="saml.acrs.enableComparison">false</prop>
136136
<prop key="saml.user.attrIdentifier">eppn</prop><!-- eppn|epuid|eptid|uid|uniqueIdentifier -->
@@ -487,8 +487,8 @@
487487
<constructor-arg name="pattern" value="/authorize**"/>
488488
<constructor-arg name="oidcIssuer" value="${main.oidc.issuer.url}"/>
489489
<constructor-arg name="idpEntityId" value="${saml.idp.defaultIdpEntityId}"/>
490-
<constructor-arg name="proxyEnabled" value="${saml.proxy.enabled}"/>
491490
<constructor-arg name="proxySpEntityId" value="${saml.proxy.spEntityId}"/>
491+
<constructor-arg name="internalReferrers" value="#{'${saml.internalReferrers}'.split('\s*,\s*')}"/>
492492
<constructor-arg name="contextLogoutHandler" ref="logoutHandler"/>
493493
</bean>
494494
<bean id="samlDiscovery" class="org.springframework.security.saml.SAMLDiscovery">

perun-oidc-server/src/main/java/cz/muni/ics/oidc/saml/SamlInvalidateSessionFilter.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import static org.springframework.http.HttpHeaders.REFERER;
44

55
import java.io.IOException;
6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
import java.util.List;
9+
import java.util.stream.Collectors;
610
import javax.servlet.FilterChain;
711
import javax.servlet.ServletException;
812
import javax.servlet.ServletRequest;
@@ -21,25 +25,34 @@ public class SamlInvalidateSessionFilter extends GenericFilterBean {
2125
private static final Logger log = LoggerFactory.getLogger(SamlInvalidateSessionFilter.class);
2226
private final AntPathRequestMatcher matcher;
2327

24-
private final String idpEntityId;
25-
private final String proxySpEntityId;
26-
private final boolean proxyEnabled;
27-
private final String oidcIssuer;
2828
private final SecurityContextLogoutHandler contextLogoutHandler;
29+
private final List<String> internalReferrers = new ArrayList<>();
2930

3031
public SamlInvalidateSessionFilter(String pattern,
3132
String idpEntityId,
3233
String oidcIssuer,
33-
boolean proxyEnabled,
3434
String proxySpEntityId,
35-
SecurityContextLogoutHandler contextLogoutHandler)
35+
SecurityContextLogoutHandler contextLogoutHandler,
36+
String[] internalReferrers)
3637
{
3738
this.matcher = new AntPathRequestMatcher(pattern);
38-
this.idpEntityId = idpEntityId;
39-
this.oidcIssuer = oidcIssuer;
40-
this.proxyEnabled = proxyEnabled;
41-
this.proxySpEntityId = proxySpEntityId;
39+
if (StringUtils.hasText(idpEntityId)) {
40+
this.internalReferrers.add(idpEntityId);
41+
}
42+
if (StringUtils.hasText(oidcIssuer)) {
43+
this.internalReferrers.add(oidcIssuer);
44+
}
45+
if (StringUtils.hasText(proxySpEntityId)) {
46+
this.internalReferrers.add(proxySpEntityId);
47+
}
4248
this.contextLogoutHandler = contextLogoutHandler;
49+
if (internalReferrers != null && internalReferrers.length > 0) {
50+
List<String> referrers = Arrays.asList(internalReferrers);
51+
referrers = referrers.stream().filter(StringUtils::hasText).collect(Collectors.toList());
52+
if (!referrers.isEmpty()) {
53+
this.internalReferrers.addAll(referrers);
54+
}
55+
}
4356
}
4457

4558
@Override
@@ -59,23 +72,15 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
5972
}
6073

6174
private boolean isInternalReferer(String referer) {
62-
if (!StringUtils.hasText(referer)) {
63-
// no referer, consider as internal
75+
if (!StringUtils.hasText(referer)) { // no referer, consider as internal
6476
return true;
6577
}
66-
67-
boolean isInternal = referer.startsWith(oidcIssuer);
68-
if (!isInternal) {
69-
if (proxyEnabled) {
70-
// check if referer is PROXY (SP part)
71-
isInternal = referer.startsWith(proxySpEntityId);
72-
} else {
73-
// check if referer is IDP
74-
isInternal = referer.startsWith(idpEntityId);
78+
for (String internal : internalReferrers) {
79+
if (referer.startsWith(internal)) {
80+
return true;
7581
}
7682
}
77-
78-
log.debug("Referer {} is internal: {}", referer, isInternal);
79-
return isInternal;
83+
return false;
8084
}
85+
8186
}

0 commit comments

Comments
 (0)