File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments