Skip to content

Commit 06984a3

Browse files
committed
Fix to avoid error when one or more non-required elements are missing
1 parent 9c0c926 commit 06984a3

3 files changed

Lines changed: 20 additions & 16 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# OneLogin's SAML Java SAML
22

3-
Updating from 1.0-SNAPSHOT to 1.1
3+
Updating from 1.0-SNAPSHOT to 1.1.2
44
---------------------------------
55

6-
Version 1.1 adds many improvements on security. It is a recommended update for all Java SAML users.
6+
Version 1.1.2 adds many improvements on security. It is a recommended update for all Java SAML users.
77

88

99
Overview

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.onelogin</groupId>
55
<artifactId>java-saml</artifactId>
6-
<version>1.1.1</version>
6+
<version>1.1.2</version>
77

88
<properties>
99
<slf4jVersion>1.7.12</slf4jVersion>

src/main/java/com/onelogin/saml/Response.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,23 @@ public boolean isValid(String... requestId){
147147
throw new Exception("There is an EncryptedAttribute in the Response and this SP not support them");
148148
}
149149

150+
// Check Audience
151+
Set<String> validAudiences = this.getAudiences();
152+
153+
if (!validAudiences.isEmpty() && !this.audienceUrl.equals(currentUrl)) {
154+
throw new Exception( this.audienceUrl + " is not a valid audience for this Response");
155+
}
156+
150157
// Check destination
151158
if(rootElement.hasAttribute("Destination")){
152159
String destinationUrl = rootElement.getAttribute("Destination");
153160
if (destinationUrl != null) {
154-
if(!destinationUrl.equals(currentUrl)){
161+
if(!destinationUrl.isEmpty() && !destinationUrl.equals(currentUrl)){
155162
throw new Exception("The response was received at " + currentUrl + " instead of " + destinationUrl);
156163
}
157164
}
158165
}
159166

160-
// Check Audience
161-
Set<String> validAudiences = this.getAudiences();
162-
163-
if (validAudiences.isEmpty() || !this.audienceUrl.equals(currentUrl)) {
164-
throw new Exception( this.audienceUrl + " is not a valid audience for this Response");
165-
}
166-
167167
// Check the issuers
168168
Set<String> issuers = this.getIssuers();
169169
for(String issuer : issuers){
@@ -196,7 +196,7 @@ public boolean isValid(String... requestId){
196196
if(subjectConfirmationDataNodes.item(c).getLocalName().equals("SubjectConfirmationData")){
197197

198198
Node recipient = subjectConfirmationDataNodes.item(c).getAttributes().getNamedItem("Recipient");
199-
if(recipient != null && !recipient.getNodeValue().equals(currentUrl)){
199+
if(recipient != null && !recipient.getNodeValue().isEmpty() && !recipient.getNodeValue().equals(currentUrl)){
200200
validSubjectConfirmation = false;
201201
}
202202

@@ -314,13 +314,17 @@ public Set<String> getAudiences() throws XPathExpressionException
314314
NodeList entries = this.queryAssertion("/saml:Conditions/saml:AudienceRestriction/saml:Audience");
315315

316316
if(entries.getLength() > 0){
317-
this.audienceUrl = entries.item(0).getChildNodes().item(0).getNodeValue();
317+
if(entries.item(0)!= null && entries.item(0).getChildNodes().getLength() > 0){
318+
this.audienceUrl = entries.item(0).getChildNodes().item(0).getNodeValue();
319+
}
318320
}
319321

320322
for(int i=0; i < entries.getLength(); i++) {
321-
String value = entries.item(i).getTextContent().trim();
322-
if (value != null && !value.isEmpty()) {
323-
audiences.add(value);
323+
if(entries.item(i) != null){
324+
String value = entries.item(i).getTextContent();
325+
if (value != null && !value.trim().isEmpty()) {
326+
audiences.add(value.trim());
327+
}
324328
}
325329
}
326330
return audiences;

0 commit comments

Comments
 (0)