This project demonstrates how SAML2.0 works via a sample integration with Salesforce SSO. Watch how each field is populated into SAML response and figure out that they mean.
- Set up SSO in Salesforce side.
- Sign up for Salesforce developer portal(developer.salesforce.com).
- Log in and search for "Single Sign-On Settings".
- Click "SAML Enabled" checkbox to enable SSO.
- Add a new SAML Single Sign-On Settings.
- Enter all information
- For "Name" and "API Name", decide and enter this setting name and API name.
- For "Issuer", enter the IdP EntityID. It can be URL of your website or any unique name
- For "Entity ID", enter the SP EntityID, which is "https://saml.salesforce.com"
- For "Identity Provider Certificate", upload "certificate.cer" file included in the project.
- For "Assertion Decryption Certificat", select "RSA-SHA256".
- For "SAML Identity Type, select "Assertion contains the User's Salesforce username"
- For "SAML Identity Location", select "Identity is in the nameIdentifier element of the Subject statement"
- For "Service Provider Initiated Request Binding", select "HTTP POST".
- Download Eclipse or Intellij.
- Change samleConfigDefault.properties file if you want.
- Run the main method in App class.
- Go to localhost and play with it!
- If you want to change the package name, you need to download the import files and change the references accordingly.
xjc -d . https://docs.oasis-open.org/security/saml/v2.0/saml-schema-protocol-2.0.xsd
xjc -d . https://docs.oasis-open.org/security/saml/v2.0/saml-schema-assertion-2.0.xsd
xjc -d . https://docs.oasis-open.org/security/saml/v2.0/saml-schema-metadata-2.0.xsd
- In ResponseType.java,
- Add @XmlRootElement(name = "Response") on top of public class ResponseType
- Import class for XmlRootElement.
- In assertion/package-info.java, protocol/package-info.java,
- Fix the annotation to the following. @javax.xml.bind.annotation.XmlSchema(namespace = "urn:oasis:names:tc:SAML:2.0:assertion", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, xmlns = {@XmlNs(prefix="saml", namespaceURI="urn:oasis:names:tc:SAML:2.0:assertion")})
- Import class for XmlNs.
- Here, alias is selfsigned, keystore name is keystore.jks RSA, password is password
- For details, refer to https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html
keytool -genkeypair -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 360 -keysize 2048
- Alternatively, you can add "-storetype PKCS12" in the previous command to create pkcs12 directly.
keytool -importkeystore -srckeystore keystore.jks -destkeystore keystore.jks -deststoretype pkcs12
keytool -export -storepass password -alias selfsigned -keystore keystore.jks -file certificate.cer