Skip to content

Commit df4c382

Browse files
refactor: change XPath expression to exclude Signature inside Advice field
1 parent fb9b104 commit df4c382

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/oneid/oneid-ecs-core/src/main/java/it/pagopa/oneid/service/config/SAMLNamespaceContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public String getNamespaceURI(String prefix) {
1212
throw new NullPointerException("Null prefix is not allowed.");
1313
}
1414
switch (prefix) {
15-
case "samlp":
15+
case "saml2p":
1616
return "urn:oasis:names:tc:SAML:2.0:protocol";
17-
case "saml":
17+
case "saml2":
1818
return "urn:oasis:names:tc:SAML:2.0:assertion";
1919
case "ds":
2020
return "http://www.w3.org/2000/09/xmldsig#";

src/oneid/oneid-ecs-core/src/main/java/it/pagopa/oneid/service/utils/SAMLUtilsExtendedCore.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ private Response unmarshallResponse(byte[] decodedSamlResponse) throws OneIdenti
220220

221221
private void checkNoMultipleSignatures(Document doc) throws XPathExpressionException {
222222
XPath xPath = XPathFactory.newInstance().newXPath();
223-
// Set the namespace context to handle prefixes like 'samlp', 'saml', and 'ds'
223+
// Set the namespace context to handle prefixes like 'saml2p', 'saml2', and 'ds'
224224
xPath.setNamespaceContext(new SAMLNamespaceContext());
225225

226-
String expression = "count(.//ds:Signature)";
226+
//In case of "Advice" field inside the Response, we do not consider the signatures inside it
227+
String expression = "count(.//ds:Signature[not(ancestor::saml2:Advice)])";
227228
Double responseSignatureCount = (Double) xPath.compile(expression)
228229
.evaluate(doc, XPathConstants.NUMBER);
229230

0 commit comments

Comments
 (0)