Skip to content

Commit a3d13db

Browse files
authored
Ignore empty uid attribute submitted on the login form (#132)
1 parent 468a213 commit a3d13db

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private List<SAMLAttribute> attributes(Authentication authentication) {
7474
Map<String, List<String>> parameterMap = (Map<String, List<String>>) authentication.getDetails();
7575
if (parameterMap.containsKey("urn:mace:dir:attribute-def:uid")) {
7676
List<String> uidValues = parameterMap.get("urn:mace:dir:attribute-def:uid");
77-
if (!CollectionUtils.isEmpty(uidValues)) {
77+
if (!CollectionUtils.isEmpty(uidValues) && StringUtils.hasText(uidValues.getFirst())) {
7878
uidValue = uidValues.getFirst();
7979
}
8080
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ public void singleSignOnServiceUsesSubmittedUidAttributeForAttributeGeneration()
105105
assertFalse(samlResponse.contains("admin@example.com"));
106106
}
107107

108+
// Regression test: an empty urn:mace:dir:attribute-def:uid form field (the login form submits
109+
// attribute inputs even when left blank) must be ignored, falling back to authentication.getName().
110+
// Otherwise uid becomes "" and SsoController#attributes crashes on uid.substring(0, 1),
111+
// returning HTTP 500 and no SAML response at all.
112+
@Test
113+
public void singleSignOnServiceIgnoresEmptySubmittedUidAttribute() throws Exception {
114+
CookieFilter cookieFilter = loginWithExtraParams("admin", "secret",
115+
Map.of("urn:mace:dir:attribute-def:uid", ""));
116+
117+
String samlResponse = decodeSAMLResponse(singleSignOnServiceRequest(redirectBindingParams(false), cookieFilter));
118+
119+
assertTrue(samlResponse.contains("admin@example.com"));
120+
}
121+
108122
// Regression test: when the 'Persist me' checkbox is submitted on /login, SsoController#attributes
109123
// must replace the existing configured user with a new FederatedUserAuthenticationToken carrying the
110124
// attributes entered on the login form, so a subsequent login reuses them without re-entering them.

0 commit comments

Comments
 (0)