Skip to content

Commit 4a75209

Browse files
committed
Merge pull request #30 from onelogin/INT-275
Int 275
2 parents 92c6eed + 8e52f99 commit 4a75209

24 files changed

Lines changed: 3666 additions & 314 deletions

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ The following information needs to be available on the account:
4949

5050
`accountSettings.setCertificate`: The x509 certificate fingerprint. This is provided from the identity provider when setting up the relationship, for this version the certificate must be 1024-bit.
5151

52+
The following information needs to be available for the response:
53+
54+
`response.loadXmlFromBase64`: The coded SAML Response on string format
55+
`response.setDestinationUrl`: The URL of the current host + current view
56+
5257
In OneLogin, for this sample project, you'll want to set the SAML Consumer URL to "http://localhost:8080" and the SAML Audience and SAML Recipient to "http://localhost:8080/consume.jsp"

sample/src/main/webapp/consume.jsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
AccountSettings accountSettings = new AccountSettings();
2626
accountSettings.setCertificate(certificateS);
2727
28-
Response samlResponse = new Response(accountSettings);
29-
samlResponse.loadXmlFromBase64(request.getParameter("SAMLResponse"));
30-
samlResponse.setDestinationUrl(request.getRequestURL().toString());
28+
Response samlResponse = new Response(accountSettings,
29+
request.getParameter("SAMLResponse"),
30+
request.getRequestURL().toString());
3131
3232
if (samlResponse.isValid()) {
3333

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package com.onelogin;
22

3+
import java.io.ByteArrayInputStream;
4+
import java.security.cert.Certificate;
5+
import java.security.cert.CertificateException;
6+
import java.security.cert.CertificateFactory;
7+
8+
import org.apache.commons.codec.binary.Base64;
9+
10+
311
public class AccountSettings {
412
private String certificate;
13+
private Certificate idp_cert;
514
private String idp_sso_target_url;
615

716
public String getCertificate() {
@@ -16,4 +25,34 @@ public String getIdp_sso_target_url() {
1625
public void setIdpSsoTargetUrl(String idp_sso_target_url) {
1726
this.idp_sso_target_url = idp_sso_target_url;
1827
}
28+
29+
/**
30+
* Loads certificate from a base64 encoded string
31+
* @param certificate an base64 encoded string.
32+
*/
33+
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);
37+
}
38+
39+
40+
public Certificate getIdpCert() throws CertificateException {
41+
if(this.idp_cert == null){
42+
loadCertificate(this.certificate);
43+
}
44+
return this.idp_cert;
45+
}
46+
47+
/**
48+
* load and get a certificate from a encoded base64 byte array.
49+
* @param certificate an encoded base64 byte array.
50+
* @throws CertificateException In case it can't load the certificate.
51+
*/
52+
public Certificate getCert(byte[] certificate) throws CertificateException {
53+
CertificateFactory fty = CertificateFactory.getInstance("X.509");
54+
ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(certificate));
55+
idp_cert = fty.generateCertificate(bais);
56+
return idp_cert;
57+
}
1958
}

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

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)