Skip to content

Commit abec336

Browse files
committed
Merge branch 'master' of https://github.com/juazugas/java-saml into juazugas-master
2 parents 1f82f10 + aa19a6d commit abec336

16 files changed

Lines changed: 353 additions & 229 deletions

File tree

core/pom.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<dependency>
4949
<groupId>joda-time</groupId>
5050
<artifactId>joda-time</artifactId>
51-
<version>2.10.3</version>
51+
<version>2.10.6</version>
5252
</dependency>
5353

5454
<!-- commons -->
@@ -60,12 +60,12 @@
6060
<dependency>
6161
<groupId>org.apache.santuario</groupId>
6262
<artifactId>xmlsec</artifactId>
63-
<version>2.1.4</version>
63+
<version>2.2.0</version>
6464
</dependency>
6565
<dependency>
6666
<groupId>commons-codec</groupId>
6767
<artifactId>commons-codec</artifactId>
68-
<version>1.12</version>
68+
<version>1.15</version>
6969
</dependency>
7070
</dependencies>
7171

@@ -74,7 +74,7 @@
7474
<plugin>
7575
<groupId>org.jacoco</groupId>
7676
<artifactId>jacoco-maven-plugin</artifactId>
77-
<version>0.8.2</version>
77+
<version>0.8.6</version>
7878
<configuration>
7979
<propertyName>jacoco.agent.argLine</propertyName>
8080
</configuration>
@@ -90,7 +90,7 @@
9090
<plugin>
9191
<groupId>org.apache.maven.plugins</groupId>
9292
<artifactId>maven-jar-plugin</artifactId>
93-
<version>2.4</version>
93+
<version>3.2.0</version>
9494
<executions>
9595
<execution>
9696
<goals>
@@ -102,22 +102,22 @@
102102
<plugin>
103103
<groupId>org.apache.maven.plugins</groupId>
104104
<artifactId>maven-surefire-plugin</artifactId>
105-
<version>2.12</version>
105+
<version>2.22.2</version>
106106
<configuration>
107107
<argLine>${jacoco.agent.argLine}</argLine>
108108
</configuration>
109109
</plugin>
110110
<plugin>
111111
<groupId>org.apache.maven.plugins</groupId>
112112
<artifactId>maven-enforcer-plugin</artifactId>
113-
<version>1.1.1</version>
113+
<version>1.4.1</version>
114114
<executions>
115115
<execution>
116116
<id>enforce</id>
117117
<configuration>
118118
<rules>
119119
<evaluateBeanshell>
120-
<condition>javax.crypto.Cipher.getMaxAllowedKeyLength("AES") &gt; 128</condition>
120+
<condition>javax.crypto.Cipher.getMaxAllowedKeyLength("AES") > 128</condition>
121121
</evaluateBeanshell>
122122
</rules>
123123
</configuration>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings) {
224224
valueMap.put("issueInstant", issueInstantString);
225225
valueMap.put("id", String.valueOf(id));
226226
valueMap.put("assertionConsumerServiceURL", String.valueOf(settings.getSpAssertionConsumerServiceUrl()));
227+
valueMap.put("protocolBinding", settings.getSpAssertionConsumerServiceBinding());
227228
valueMap.put("spEntityid", settings.getSpEntityId());
228229

229230
String requestedAuthnContextStr = "";
@@ -247,7 +248,7 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings) {
247248
*/
248249
private static StringBuilder getAuthnRequestTemplate() {
249250
StringBuilder template = new StringBuilder();
250-
template.append("<samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"${id}\" Version=\"2.0\" IssueInstant=\"${issueInstant}\"${providerStr}${forceAuthnStr}${isPassiveStr}${destinationStr} ProtocolBinding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\" AssertionConsumerServiceURL=\"${assertionConsumerServiceURL}\">");
251+
template.append("<samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"${id}\" Version=\"2.0\" IssueInstant=\"${issueInstant}\"${providerStr}${forceAuthnStr}${isPassiveStr}${destinationStr} ProtocolBinding=\"${protocolBinding}\" AssertionConsumerServiceURL=\"${assertionConsumerServiceURL}\">");
251252
template.append("<saml:Issuer>${spEntityid}</saml:Issuer>");
252253
template.append("${subjectStr}${nameIDPolicyStr}${requestedAuthnContextStr}</samlp:AuthnRequest>");
253254
return template;

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class SamlResponse {
7979
/**
8080
* After validation, if it fails this property has the cause of the problem
8181
*/
82-
private String error;
82+
private Exception validationException;
8383

8484
/**
8585
* Constructor to have a Response object fully built and ready to validate the saml response.
@@ -144,7 +144,7 @@ public void loadXmlFromBase64(String responseStr) throws ParserConfigurationExce
144144
* @return if the response is valid or not
145145
*/
146146
public boolean isValid(String requestId) {
147-
error = null;
147+
validationException = null;
148148

149149
try {
150150
if (samlResponseDocument == null) {
@@ -307,9 +307,9 @@ public boolean isValid(String requestId) {
307307
LOGGER.debug("SAMLResponse validated --> {}", samlResponseString);
308308
return true;
309309
} catch (Exception e) {
310-
error = e.getMessage();
310+
validationException = e;
311311
LOGGER.debug("SAMLResponse invalid --> {}", samlResponseString);
312-
LOGGER.error(error);
312+
LOGGER.error(validationException.getMessage());
313313
return false;
314314
}
315315
}
@@ -966,15 +966,24 @@ public void setDestinationUrl(String url) {
966966
/**
967967
* After execute a validation process, if fails this method returns the cause
968968
*
969-
* @return the cause of the validation error
969+
* @return the cause of the validation error as a string
970970
*/
971971
public String getError() {
972-
if (error != null) {
973-
return error;
972+
if (validationException != null) {
973+
return validationException.getMessage();
974974
}
975975
return null;
976976
}
977977

978+
/**
979+
* After execute a validation process, if fails this method returns the Exception object
980+
*
981+
* @return the cause of the validation error
982+
*/
983+
public Exception getValidationException() {
984+
return validationException;
985+
}
986+
978987
/**
979988
* Extracts a node from the DOMDocument (Assertion).
980989
*

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class LogoutRequest {
9898
/**
9999
* After validation, if it fails this property has the cause of the problem
100100
*/
101-
private String error;
101+
private Exception validationException;
102102

103103
/**
104104
* Constructs the LogoutRequest object.
@@ -366,7 +366,7 @@ private static StringBuilder getLogoutRequestTemplate() {
366366
* @throws Exception
367367
*/
368368
public Boolean isValid() throws Exception {
369-
error = null;
369+
validationException = null;
370370

371371
try {
372372
if (this.logoutRequestString == null || logoutRequestString.isEmpty()) {
@@ -474,9 +474,9 @@ public Boolean isValid() throws Exception {
474474
LOGGER.debug("LogoutRequest validated --> " + logoutRequestString);
475475
return true;
476476
} catch (Exception e) {
477-
error = e.getMessage();
477+
validationException = e;
478478
LOGGER.debug("LogoutRequest invalid --> " + logoutRequestString);
479-
LOGGER.error(error);
479+
LOGGER.error(validationException.getMessage());
480480
return false;
481481
}
482482
}
@@ -737,9 +737,22 @@ public static List<String> getSessionIndexes(String samlLogoutRequestString) thr
737737
* @return the cause of the validation error
738738
*/
739739
public String getError() {
740-
return error;
740+
if (validationException != null) {
741+
return validationException.getMessage();
742+
}
743+
return null;
741744
}
742745

746+
/**
747+
* After execute a validation process, if fails this method returns the Exception object
748+
*
749+
* @return the cause of the validation error
750+
*/
751+
public Exception getValidationException() {
752+
return validationException;
753+
}
754+
755+
743756
/**
744757
* @return the ID of the Logout Request
745758
*/

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class LogoutResponse {
8282
/**
8383
* After validation, if it fails this property has the cause of the problem
8484
*/
85-
private String error;
85+
private Exception validationException;
8686

8787
/**
8888
* Constructs the LogoutResponse object.
@@ -168,7 +168,7 @@ public String getId() {
168168
* @return if the SAML LogoutResponse is or not valid
169169
*/
170170
public Boolean isValid(String requestId) {
171-
error = null;
171+
validationException = null;
172172

173173
try {
174174
if (this.logoutResponseDocument == null) {
@@ -270,9 +270,9 @@ public Boolean isValid(String requestId) {
270270
LOGGER.debug("LogoutRequest validated --> " + logoutResponseString);
271271
return true;
272272
} catch (Exception e) {
273-
error = e.getMessage();
273+
validationException = e;
274274
LOGGER.debug("LogoutResponse invalid --> " + logoutResponseString);
275-
LOGGER.error(error);
275+
LOGGER.error(validationException.getMessage());
276276
return false;
277277
}
278278
}
@@ -451,6 +451,18 @@ private static StringBuilder getLogoutResponseTemplate() {
451451
* @return the cause of the validation error
452452
*/
453453
public String getError() {
454-
return error;
454+
if (validationException != null) {
455+
return validationException.getMessage();
456+
}
457+
return null;
458+
}
459+
460+
/**
461+
* After execute a validation process, if fails this method returns the Exception object
462+
*
463+
* @return the cause of the validation error
464+
*/
465+
public Exception getValidationException() {
466+
return validationException;
455467
}
456468
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
import org.joda.time.DateTime;
7474
import org.joda.time.DateTimeZone;
7575
import org.joda.time.Period;
76-
import org.joda.time.format.DateTimeFormat;
7776
import org.joda.time.format.DateTimeFormatter;
77+
import org.joda.time.format.ISODateTimeFormat;
7878
import org.joda.time.format.ISOPeriodFormat;
7979
import org.joda.time.format.PeriodFormatter;
8080
import org.slf4j.Logger;
@@ -103,9 +103,9 @@ public final class Util {
103103
* Private property to construct a logger for this class.
104104
*/
105105
private static final Logger LOGGER = LoggerFactory.getLogger(Util.class);
106-
107-
private static final DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").withZone(DateTimeZone.UTC);
108-
private static final DateTimeFormatter DATE_TIME_FORMAT_MILLS = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZone(DateTimeZone.UTC);
106+
107+
private static final DateTimeFormatter DATE_TIME_FORMAT = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
108+
private static final DateTimeFormatter DATE_TIME_FORMAT_MILLS = ISODateTimeFormat.dateTime().withZoneUTC();
109109
public static final String UNIQUE_ID_PREFIX = "ONELOGIN_";
110110
public static final String RESPONSE_SIGNATURE_XPATH = "/samlp:Response/ds:Signature";
111111
public static final String ASSERTION_SIGNATURE_XPATH = "/samlp:Response/saml:Assertion/ds:Signature";
@@ -597,9 +597,9 @@ public static String calculateX509Fingerprint(X509Certificate x509cert, String a
597597
byte[] dataBytes = x509cert.getEncoded();
598598
if (alg == null || alg.isEmpty() || alg.equals("SHA-1")|| alg.equals("sha1")) {
599599
fingerprint = DigestUtils.sha1Hex(dataBytes);
600-
} else if (alg.equals("SHA-256") || alg .equals("sha256")) {
600+
} else if (alg.equals("SHA-256") || alg.equals("sha256")) {
601601
fingerprint = DigestUtils.sha256Hex(dataBytes);
602-
} else if (alg.equals("SHA-384") || alg .equals("sha384")) {
602+
} else if (alg.equals("SHA-384") || alg.equals("sha384")) {
603603
fingerprint = DigestUtils.sha384Hex(dataBytes);
604604
} else if (alg.equals("SHA-512") || alg.equals("sha512")) {
605605
fingerprint = DigestUtils.sha512Hex(dataBytes);

0 commit comments

Comments
 (0)