Skip to content

Commit 3fde14b

Browse files
committed
Fix Logout errors
1 parent 84779ce commit 3fde14b

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

gamsaml20/src/main/java/com/genexus/saml20/utils/DSig.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,10 @@ public static String validateSignatures(Document xmlDoc, String certPath, String
5656
return "";
5757
}
5858
}
59-
return buildXml(assertions, xmlDoc);
59+
return SamlAssertionUtils.isLogout(xmlDoc) ? SamlAssertionUtils.buildXmlLogout(assertions) : SamlAssertionUtils.buildXmlLogin(assertions, xmlDoc);
6060
}
6161

62-
public static String buildXml(List<Element> assertions, Document xmlDoc){
63-
//security meassure against assertion manipulation, it assures that every assertion to be used on the app has been signed and verified
64-
Element element = xmlDoc.getDocumentElement();
65-
Node response = element.cloneNode(false);
6662

67-
NodeList status = element.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "Status");
68-
response.appendChild(status.item(0));
69-
70-
for(Element elem: assertions){
71-
if(!elem.getLocalName().equals("Response")){
72-
Node node = elem.cloneNode(true);
73-
response.appendChild(node);
74-
}
75-
}
76-
return Encoding.elementToString((Element) response);
77-
}
7863

7964
private static boolean verifySignatureAlgorithm(Element elem) {
8065
logger.trace("verifySignatureAlgorithm");

gamsaml20/src/main/java/com/genexus/saml20/utils/SamlAssertionUtils.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,37 @@ public static Document loadDocument(String xml) {
4949
}
5050
}
5151

52+
public static String buildXmlLogin(List<org.w3c.dom.Element> assertions, Document xmlDoc){
53+
//security meassure against assertion manipulation, it assures that every assertion to be used on the app has been signed and verified
54+
org.w3c.dom.Element element = xmlDoc.getDocumentElement();
55+
Node response = element.cloneNode(false);
56+
57+
NodeList status = element.getElementsByTagNameNS(_saml_protocolNS, "Status");
58+
response.appendChild(status.item(0));
59+
60+
for(org.w3c.dom.Element elem: assertions){
61+
if(!elem.getLocalName().equals("Response")){
62+
Node node = elem.cloneNode(true);
63+
response.appendChild(node);
64+
}
65+
}
66+
return Encoding.elementToString((org.w3c.dom.Element) response);
67+
}
68+
69+
public static String buildXmlLogout(List<org.w3c.dom.Element> assertions){
70+
if(assertions.isEmpty())
71+
{
72+
return "";
73+
}
74+
org.w3c.dom.Element element = assertions.get(0);
75+
Node logoutResponse = element.cloneNode(false);
76+
NodeList status = element.getElementsByTagNameNS(_saml_protocolNS, "Status");
77+
logoutResponse.appendChild(status.item(0));
78+
NodeList issuer = element.getElementsByTagNameNS(_saml_assertionNS, "Issuer");
79+
logoutResponse.appendChild(issuer.item(0));
80+
return Encoding.elementToString((org.w3c.dom.Element) logoutResponse);
81+
}
82+
5283
public static boolean isLogout(Document xmlDoc){
5384
logger.trace("isLogout");
5485
try {

0 commit comments

Comments
 (0)