Skip to content

Commit e5e25f0

Browse files
committed
Fix Issue with LogoutRequest rejected by ADFS due NameID with unspecified format instead no format attribute
1 parent 426e2b0 commit e5e25f0

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

core/src/main/java/com/onelogin/saml2/logout/LogoutRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings) {
241241
String nameIdFormat = null;
242242
String spNameQualifier = null;
243243
if (nameId != null) {
244-
if (this.nameIdFormat == null) {
244+
if (this.nameIdFormat == null && !settings.getSpNameIDFormat().equals(Constants.NAMEID_UNSPECIFIED)) {
245245
nameIdFormat = settings.getSpNameIDFormat();
246246
} else {
247247
nameIdFormat = this.nameIdFormat;

core/src/main/java/com/onelogin/saml2/util/Util.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ public static String generateNameId(String value, String spnq, String format, X5
11911191
nameId.setAttribute("SPNameQualifier", spnq);
11921192
}
11931193
if (format != null && !format.isEmpty()) {
1194-
nameId.setAttribute("Format", format);
1194+
nameId.setAttribute("Format", format);
11951195
}
11961196
nameId.appendChild(doc.createTextNode(value));
11971197
doc.appendChild(nameId);
@@ -1246,6 +1246,18 @@ public static String generateNameId(String value, String spnq, String format, X5
12461246
public static String generateNameId(String value, String spnq, String format) {
12471247
return generateNameId(value, spnq, format, null);
12481248
}
1249+
1250+
/**
1251+
* Generates a nameID.
1252+
*
1253+
* @param value
1254+
* The value
1255+
*
1256+
* @return Xml contained in the document.
1257+
*/
1258+
public static String generateNameId(String value) {
1259+
return generateNameId(value, null, null, null);
1260+
}
12491261

12501262
/**
12511263
* Method to generate a symmetric key for encryption

core/src/test/java/com/onelogin/saml2/test/logout/LogoutRequestTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ public void testGetNameIdData() throws Exception {
228228
String logoutRequestStr = Util.base64decodedInflated(logoutRequestStringBase64);
229229
assertThat(logoutRequestStr, containsString("<samlp:LogoutRequest"));
230230
String nameIdDataStr = LogoutRequest.getNameIdData(logoutRequestStr, null).toString();
231-
assertThat(nameIdDataStr, containsString("Format=urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"));
232231
assertThat(nameIdDataStr, containsString("Value=ONELOGIN_1e442c129e1f822c8096086a1103c5ee2c7cae1c"));
233232
assertThat(nameIdDataStr, not(containsString("SPNameQualifier")));
234233

@@ -249,7 +248,6 @@ public void testGetNameIdData() throws Exception {
249248
logoutRequestStr = Util.base64decodedInflated(logoutRequestStringBase64);
250249
PrivateKey key = settings.getSPkey();
251250
nameIdDataStr = LogoutRequest.getNameIdData(logoutRequestStr, key).toString();
252-
assertThat(nameIdDataStr, containsString("Format=urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"));
253251
assertThat(nameIdDataStr, containsString("Value=ONELOGIN_1e442c129e1f822c8096086a1103c5ee2c7cae1c"));
254252
assertThat(nameIdDataStr, not(containsString("SPNameQualifier")));
255253

@@ -268,6 +266,16 @@ public void testGetNameIdData() throws Exception {
268266
assertThat(nameIdDataStr, containsString("Format=urn:oasis:names:tc:SAML:2.0:nameid-format:emailAddress"));
269267
assertThat(nameIdDataStr, containsString("Value=ONELOGIN_9c86c4542ab9d6fce07f2f7fd335287b9b3cdf69"));
270268
assertThat(nameIdDataStr, containsString("SPNameQualifier=https://pitbulk.no-ip.org/newonelogin/demo1/metadata.php"));
269+
270+
settings = new SettingsBuilder().fromFile("config/config.emailaddressformat.properties").build();
271+
logoutRequest = new LogoutRequest(settings, null, "ONELOGIN_1e442c129e1f822c8096086a1103c5ee2c7cae1c", null);
272+
logoutRequestStringBase64 = logoutRequest.getEncodedLogoutRequest();
273+
logoutRequestStr = Util.base64decodedInflated(logoutRequestStringBase64);
274+
assertThat(logoutRequestStr, containsString("<samlp:LogoutRequest"));
275+
nameIdDataStr = LogoutRequest.getNameIdData(logoutRequestStr, null).toString();
276+
assertThat(nameIdDataStr, containsString("Value=ONELOGIN_1e442c129e1f822c8096086a1103c5ee2c7cae1c"));
277+
assertThat(nameIdDataStr, containsString("Format=urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"));
278+
assertThat(nameIdDataStr, not(containsString("SPNameQualifier")));
271279
}
272280

273281
/**

core/src/test/java/com/onelogin/saml2/test/util/UtilsTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,25 @@ public void testGenerateNameId() throws URISyntaxException, IOException, Certifi
17171717
assertThat(nameIdEnc, containsString("http://www.w3.org/2001/04/xmlenc#aes128-cbc"));
17181718
assertThat(nameIdEnc, containsString("http://www.w3.org/2001/04/xmlenc#rsa-1_5"));
17191719
}
1720-
1720+
1721+
/**
1722+
* Tests the generateNameId method
1723+
*
1724+
* @throws IOException
1725+
* @throws URISyntaxException
1726+
* @throws CertificateException
1727+
*
1728+
* @see com.onelogin.saml2.util.Util#generateNameId
1729+
*/
1730+
@Test
1731+
public void testGenerateNameIdWithoutFormat() throws URISyntaxException, IOException, CertificateException {
1732+
String nameIdValue = "ONELOGIN_ce998811003f4e60f8b07a311dc641621379cfde";
1733+
String nameId = Util.generateNameId(nameIdValue);
1734+
1735+
String expectedNameId = "<saml:NameID>ONELOGIN_ce998811003f4e60f8b07a311dc641621379cfde</saml:NameID>";
1736+
assertEquals(expectedNameId, nameId);
1737+
}
1738+
17211739
/**
17221740
* Tests the generateUniqueID method
17231741
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Service Provider Data that we are deploying
2+
# Identifier of the SP entity (must be a URI)
3+
onelogin.saml2.sp.entityid = http://localhost:8080/java-saml-jspsample/metadata.jsp
4+
# Specifies info about where and how the <AuthnResponse> message MUST be
5+
# returned to the requester, in this case our SP.
6+
# URL Location where the <Response> from the IdP will be returned
7+
onelogin.saml2.sp.assertion_consumer_service.url = http://localhost:8080/java-saml-jspsample/acs.jsp
8+
9+
# Specifies info about Logout service
10+
# URL Location where the <LogoutResponse> from the IdP will be returned or where to send the <LogoutRequest>
11+
onelogin.saml2.sp.single_logout_service.url = http://localhost:8080/java-saml-jspsample/sls.jsp
12+
13+
# Specifies constraints on the name identifier to be used to
14+
# represent the requested subject.
15+
onelogin.saml2.sp.nameidformat = urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
16+
17+
# Identity Provider Data that we want connect with our SP
18+
# Identifier of the IdP entity (must be a URI)
19+
onelogin.saml2.idp.entityid = http://idp.example.com/
20+
21+
# SSO endpoint info of the IdP. (Authentication Request protocol)
22+
# URL Target of the IdP where the SP will send the Authentication Request Message
23+
onelogin.saml2.idp.single_sign_on_service.url = http://idp.example.com/simplesaml/saml2/idp/SSOService.php
24+
25+
# SLO endpoint info of the IdP.
26+
# URL Location of the IdP where the SP will send the SLO Request
27+
onelogin.saml2.idp.single_logout_service.url = http://idp.example.com/simplesaml/saml2/idp/SingleLogoutService.php
28+
29+
# Public x509 certificate of the IdP
30+
onelogin.saml2.idp.x509cert = -----BEGIN CERTIFICATE-----\nMIIBrTCCAaGgAwIBAgIBATADBgEAMGcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRUwEwYDVQQHDAxTYW50YSBNb25pY2ExETAPBgNVBAoMCE9uZUxvZ2luMRkwFwYDVQQDDBBhcHAub25lbG9naW4uY29tMB4XDTEwMTAxMTIxMTUxMloXDTE1MTAxMTIxMTUxMlowZzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFTATBgNVBAcMDFNhbnRhIE1vbmljYTERMA8GA1UECgwIT25lTG9naW4xGTAXBgNVBAMMEGFwcC5vbmVsb2dpbi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMPmjfjy7L35oDpeBXBoRVCgktPkLno9DOEWB7MgYMMVKs2B6ymWQLEWrDugMK1hkzWFhIb5fqWLGbWy0J0veGR9/gHOQG+rD/I36xAXnkdiXXhzoiAG/zQxM0edMOUf40n314FC8moErcUg6QabttzesO59HFz6shPuxcWaVAgxAgMBAAEwAwYBAAMBAA==\n-----END CERTIFICATE-----

0 commit comments

Comments
 (0)