Skip to content

Commit 0a4328b

Browse files
committed
Merge pull request #43 from collectivehealth/Chen-Han/patch-1
Error Message Change + getAttribute() change
2 parents 65ce16e + e7afda4 commit 0a4328b

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

src/main/java/com/onelogin/AccountSettings.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,19 @@ public void setIdpSsoTargetUrl(String idp_sso_target_url) {
3131
* @param certificate an base64 encoded string.
3232
*/
3333
public void loadCertificate(String certificate) throws CertificateException {
34-
CertificateFactory fty = CertificateFactory.getInstance("X.509");
35-
ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(certificate.getBytes()));
36-
this.idp_cert = fty.generateCertificate(bais);
34+
loadCertificate(certificate, true);
3735
}
3836

39-
37+
public void loadCertificate(String certificate, boolean isBase64) throws CertificateException {
38+
CertificateFactory fty = CertificateFactory.getInstance("X.509");
39+
byte[] cert = certificate.getBytes();
40+
if (isBase64) {
41+
cert = Base64.decodeBase64(cert);
42+
}
43+
ByteArrayInputStream bais = new ByteArrayInputStream(cert);
44+
this.idp_cert = fty.generateCertificate(bais);
45+
}
46+
4047
public Certificate getIdpCert() throws CertificateException {
4148
if(this.idp_cert == null){
4249
loadCertificate(this.certificate);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void loadXmlFromBase64(String responseStr) throws Exception {
7676
this.response = new String(decodedB);
7777
this.document = Utils.loadXML(this.response);
7878
if(this.document == null){
79-
throw new Exception("SAML Response could not be processed");
79+
throw new Exception("SAML Response could not be processed, invalid or empty SAML");
8080
}
8181
}
8282

@@ -138,7 +138,7 @@ public boolean isValid(String... requestId){
138138

139139
// Validate Assertion timestamps
140140
if (!this.validateTimestamps()) {
141-
throw new Exception("Timing issues (please check your clock settings)");
141+
throw new Exception("Timing issues. Possible reasons include: SAML expired, service's clock setting is not UTC.");
142142
}
143143

144144
// EncryptedAttributes are not supported
@@ -253,8 +253,10 @@ public String getNameId() throws Exception {
253253

254254
public String getAttribute(String name) {
255255
HashMap<String, ArrayList<String>> attributes = getAttributes();
256+
256257
if (!attributes.isEmpty()) {
257-
return attributes.get(name).toString();
258+
ArrayList<String> attrVal = attributes.get(name);
259+
return attrVal == null || attrVal.size() == 0 ? null : attrVal.get(0).toString();
258260
}
259261
return null;
260262
}

0 commit comments

Comments
 (0)