Skip to content

Commit 4926bf8

Browse files
committed
Use the user input of urn:mace:dir:attribute-def:uid if provided
Release 10.1.2
1 parent d423e19 commit 4926bf8

6 files changed

Lines changed: 31 additions & 7 deletions

File tree

‎mujina-common/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>org.openconext</groupId>
2121
<artifactId>mujina</artifactId>
22-
<version>10.1.2-SNAPSHOT</version>
22+
<version>10.1.2</version>
2323
<relativePath>../pom.xml</relativePath>
2424
</parent>
2525
<artifactId>mujina-common</artifactId>

‎mujina-idp/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>org.openconext</groupId>
2121
<artifactId>mujina</artifactId>
22-
<version>10.1.2-SNAPSHOT</version>
22+
<version>10.1.2</version>
2323
<relativePath>../pom.xml</relativePath>
2424
</parent>
2525
<artifactId>mujina-idp</artifactId>

‎mujina-idp/src/main/java/mujina/idp/SsoController.java‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@ private void doSSO(HttpServletRequest request, HttpServletResponse response, Aut
6969

7070
@SuppressWarnings("unchecked")
7171
private List<SAMLAttribute> attributes(Authentication authentication) {
72-
String uid = authentication.getName();
72+
String uidValue = authentication.getName();
73+
//See SAMLAttributeAuthenticationFilter#setDetails
74+
Map<String, List<String>> parameterMap = (Map<String, List<String>>) authentication.getDetails();
75+
if (parameterMap.containsKey("urn:mace:dir:attribute-def:uid")) {
76+
List<String> uidValues = parameterMap.get("urn:mace:dir:attribute-def:uid");
77+
if (!CollectionUtils.isEmpty(uidValues)) {
78+
uidValue = uidValues.getFirst();
79+
}
80+
}
81+
final String uid = uidValue;
7382
Map<String, List<String>> result = new HashMap<>(idpConfiguration.getAttributes());
7483

7584
Optional<Map<String, List<String>>> optionalMap = idpConfiguration.getUsers().stream()
@@ -78,8 +87,7 @@ private List<SAMLAttribute> attributes(Authentication authentication) {
7887
.map(FederatedUserAuthenticationToken::getAttributes);
7988
optionalMap.ifPresent(result::putAll);
8089

81-
//See SAMLAttributeAuthenticationFilter#setDetails
82-
Map<String, List<String>> parameterMap = (Map<String, List<String>>) authentication.getDetails();
90+
8391
result.putAll(parameterMap);
8492
if (parameterMap.containsKey("authn-context-class-ref-value")) {
8593
result.remove("authn-context-class-ref-value");

‎mujina-idp/src/test/java/mujina/idp/SsoControllerTest.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ public void singleSignOnServiceRemovesAuthnContextClassRefValueFromAttributes()
8989
assertFalse(samlResponse.contains("authn-context-class-ref-value"));
9090
}
9191

92+
// Regression test: SsoController#attributes must derive the uid used for attribute generation
93+
// (mail, givenName, cn, ...) and for matching a persisted FederatedUserAuthenticationToken from the
94+
// urn:mace:dir:attribute-def:uid form field when it is submitted on /login, rather than always from
95+
// authentication.getName(). This lets a federated/proxied login override the SAML uid independently
96+
// of the local username used to authenticate.
97+
@Test
98+
public void singleSignOnServiceUsesSubmittedUidAttributeForAttributeGeneration() throws Exception {
99+
CookieFilter cookieFilter = loginWithExtraParams("admin", "secret",
100+
Map.of("urn:mace:dir:attribute-def:uid", "janesmith"));
101+
102+
String samlResponse = decodeSAMLResponse(singleSignOnServiceRequest(redirectBindingParams(false), cookieFilter));
103+
104+
assertTrue(samlResponse.contains("janesmith@example.com"));
105+
assertFalse(samlResponse.contains("admin@example.com"));
106+
}
107+
92108
// Regression test: when the 'Persist me' checkbox is submitted on /login, SsoController#attributes
93109
// must replace the existing configured user with a new FederatedUserAuthenticationToken carrying the
94110
// attributes entered on the login form, so a subsequent login reuses them without re-entering them.

‎mujina-sp/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>org.openconext</groupId>
2121
<artifactId>mujina</artifactId>
22-
<version>10.1.2-SNAPSHOT</version>
22+
<version>10.1.2</version>
2323
<relativePath>../pom.xml</relativePath>
2424
</parent>
2525
<artifactId>mujina-sp</artifactId>

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<modelVersion>4.0.0</modelVersion>
1919
<groupId>org.openconext</groupId>
2020
<artifactId>mujina</artifactId>
21-
<version>10.1.2-SNAPSHOT</version>
21+
<version>10.1.2</version>
2222
<packaging>pom</packaging>
2323
<parent>
2424
<groupId>org.springframework.boot</groupId>

0 commit comments

Comments
 (0)