Skip to content

Commit c4907d4

Browse files
committed
Trim the extracted subject name id
If the subject name id is not trimmed, its value may contain surrounding whitespace characters depending on XML formatting. This change also avoids a double trim of audiences (which indeed were already trimmed).
1 parent 3a81e0c commit c4907d4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

core/src/main/java/com/onelogin/saml2/authn/SamlResponse.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import javax.xml.xpath.XPathExpressionException;
1515

1616
import com.onelogin.saml2.model.hsm.HSM;
17+
18+
import org.apache.commons.lang3.StringUtils;
1719
import org.joda.time.DateTime;
1820
import org.joda.time.Instant;
1921
import org.slf4j.Logger;
@@ -469,7 +471,10 @@ public Map<String,String> getNameIdData() throws Exception {
469471

470472
if (nameIdElem != null) {
471473
String value = nameIdElem.getTextContent();
472-
if (settings.isStrict() && value.isEmpty()) {
474+
if(value != null) {
475+
value = value.trim();
476+
}
477+
if (settings.isStrict() && StringUtils.isEmpty(value)) {
473478
throw new ValidationError("An empty NameID value found", ValidationError.EMPTY_NAMEID);
474479
}
475480

@@ -699,8 +704,10 @@ public List<String> getAudiences() throws XPathExpressionException {
699704
for (int i = 0; i < entries.getLength(); i++) {
700705
if (entries.item(i) != null) {
701706
String value = entries.item(i).getTextContent();
702-
if (value != null && !value.trim().isEmpty()) {
703-
audiences.add(value.trim());
707+
if(value != null)
708+
value = value.trim();
709+
if(!StringUtils.isEmpty(value)) {
710+
audiences.add(value);
704711
}
705712
}
706713
}

0 commit comments

Comments
 (0)