diff --git a/CHANGELOG.md b/CHANGELOG.md index 747b346..766f167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 0.9.0 - 2019-01-09 + +* FEATURE - Added `SAMLConfigBean.useJdkCacertsForSslVerification` flag to allow SSL verifications to be performed by using JDK's cacerts instead of app's keystore file. + ## 0.8.0 - 2018-07-11 * Moved from Java 7 to Java 8. diff --git a/README.md b/README.md index 129a953..08568cf 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Tested against IdP's environments:- com.github.choonchernlim spring-security-adfs-saml2 - 0.8.0 + 0.9.0 ``` @@ -35,9 +35,9 @@ Tested against IdP's environments:- * Java 8. * Both Sp and IdP must use HTTPS protocol. * Java’s default keysize is limited to 128-bit key due to US export laws and a few countries’ import laws. So, Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files must be installed to allow larger key size, such as 256-bit key. -* Keystore must contain both Sp's public/private keys and imported IdP's public certificate. - * Sp's public/private keys - to generate digital signature before sending SAML messages to IdP. - * IdP's public certificate - to verify IdP's SAML messages to prevent man-in-the-middle attack. +* Keystore contains the following:- + * (REQUIRED) Sp's public/private keys - to generate digital signature before sending SAML messages to IdP. + * (OPTIONAL) IdP's public certificate - to verify IdP's SAML messages to prevent man-in-the-middle attack. This certificate can also be stored under JDK's cacerts. * To generate Sp's public/private keys:- ``` @@ -120,6 +120,40 @@ class AppSecurityConfig extends SAMLWebSecurityConfigurerAdapter { } ``` +### Customizing SSL Verification + +By default, the keystore file serves 2 purposes:- + +* Acts as a keystore, containing app's public/private key. +* Acts as a truststore, containing IdP's certificate with public key. + +If the keystore does not contain IdP's certificate, the SSL verification will fail with the following error when attempting to retrieve IdP's metadata:- + +``` +PKIX path construction failed for untrusted credential: [subjectName='CN=idp.server.com,OU=IDP,C=US']: unable to find valid certification path to requested target +I/O exception (javax.net.ssl.SSLPeerUnverifiedException) caught when processing request: SSL peer failed hostname validation for name: null +Error retrieving metadata from https://idp.server.com/federationmetadata/2007-06/federationmetadata.xml +``` + +If you store the IdP's certificate under JDK's truststore (ie: cacerts) and you want the SSL verification to rely on that file, do this:- + +```java +@Configuration +@EnableWebSecurity +class AppSecurityConfig extends SAMLWebSecurityConfigurerAdapter { + + @Override + protected SAMLConfigBean samlConfigBean() { + return new SAMLConfigBeanBuilder() + // ... other configurations + .withUseJdkCacertsForSslVerification(true) + .build(); + } + + ... +} +``` + ### Environment Properties Driven Configuration If you don't want to use `@Profile` to configure environment-specific security, you may pass the configuration values through environment properties. @@ -213,22 +247,23 @@ protected void configure(final HttpSecurity http) throws Exception { `SAMLConfigBean` stores app-specific security configuration. -|Property |Required? |Description | -|---------------------------|----------|----------------------------------------------------------------------------------------------------------| -|idpServerName |Yes |IdP server name. Used for retrieving IdP metadata using HTTPS. If IdP link is `https://idp-server/adfs/ls`, value should be `idp-server`. | -|spServerName |Yes |Sp server name. Used for generating correct SAML endpoints in Sp metadata to handle servers doing SSL termination. If Sp link is `https://sp-server:8443/myapp`, value should be `sp-server`. | -|spHttpsPort |No |Sp HTTPS port. Used for generating correct SAML endpoints in Sp metadata to handle servers doing SSL termination. If Sp link is `https://sp-server:8443/myapp`, value should be `8443`.

Default is `443`. | -|spContextPath |No |Sp context path. Used for generating correct SAML endpoints in Sp metadata to handle servers doing SSL termination. If Sp link is `https://sp-server:8443/myapp`, value should be `/myapp`.

Default is `''`. | -|keystoreResource |Yes |App's keystore containing its public/private key and ADFS' certificate with public key. | -|keystorePassword |Yes |Password to access app's keystore. | -|keystoreAlias |Yes |Alias of app's public/private key pair. | -|keystorePrivateKeyPassword |Yes |Password to access app's private key. | -|successLoginDefaultUrl |Yes |Where to redirect user on successful login if no saved request is found in the session. | -|successLogoutUrl |Yes |Where to redirect user on successful logout. | -|failedLoginDefaultUrl |No |Where to redirect user on failed login. This value is set to null, which returns 401 error code on failed login. But, in theory, this will never be used because IdP will handled the failed login on IdP login page.

Default is `''`, which return 401 error code.| -|storeCsrfTokenInCookie |No |Whether to store CSRF token in cookie named `XSRF-TOKEN` and expecting CSRF token to be set using header named `X-XSRF-TOKEN` to cater single-page app using frameworks like React and AngularJS.

Default is `false`. | -|samlUserDetailsService |No |For configuring user details and authorities. When set, `userDetails` will be set as `principal`.

Default is `null`. | -|authnContexts |No |Determine what authentication methods to use. To use the order of authentication methods defined by IdP, set as empty set. To enable Windows Integrated Auth (WIA), use `CustomAuthnContext.WINDOWS_INTEGRATED_AUTHN_CTX`.

Default is `AuthnContext.PASSWORD_AUTHN_CTX` where IdP login page is displayed to obtain user/password.| +|Property |Required? |Description | +|--------------------------------|----------|----------------------------------------------------------------------------------------------------------| +|idpServerName |Yes |IdP server name. Used for retrieving IdP metadata using HTTPS. If IdP link is `https://idp-server/adfs/ls`, value should be `idp-server`. | +|spServerName |Yes |Sp server name. Used for generating correct SAML endpoints in Sp metadata to handle servers doing SSL termination. If Sp link is `https://sp-server:8443/myapp`, value should be `sp-server`. | +|spHttpsPort |No |Sp HTTPS port. Used for generating correct SAML endpoints in Sp metadata to handle servers doing SSL termination. If Sp link is `https://sp-server:8443/myapp`, value should be `8443`.

Default is `443`. | +|spContextPath |No |Sp context path. Used for generating correct SAML endpoints in Sp metadata to handle servers doing SSL termination. If Sp link is `https://sp-server:8443/myapp`, value should be `/myapp`.

Default is `''`. | +|keystoreResource |Yes |App's keystore containing its public/private key and ADFS' certificate with public key. | +|keystorePassword |Yes |Password to access app's keystore. | +|keystoreAlias |Yes |Alias of app's public/private key pair. | +|keystorePrivateKeyPassword |Yes |Password to access app's private key. | +|successLoginDefaultUrl |Yes |Where to redirect user on successful login if no saved request is found in the session. | +|successLogoutUrl |Yes |Where to redirect user on successful logout. | +|failedLoginDefaultUrl |No |Where to redirect user on failed login. This value is set to null, which returns 401 error code on failed login. But, in theory, this will never be used because IdP will handled the failed login on IdP login page.

Default is `''`, which return 401 error code.| +|storeCsrfTokenInCookie |No |Whether to store CSRF token in cookie named `XSRF-TOKEN` and expecting CSRF token to be set using header named `X-XSRF-TOKEN` to cater single-page app using frameworks like React and AngularJS.

Default is `false`. | +|samlUserDetailsService |No |For configuring user details and authorities. When set, `userDetails` will be set as `principal`.

Default is `null`. | +|authnContexts |No |Determine what authentication methods to use. To use the order of authentication methods defined by IdP, set as empty set. To enable Windows Integrated Auth (WIA), use `CustomAuthnContext.WINDOWS_INTEGRATED_AUTHN_CTX`.

Default is `AuthnContext.PASSWORD_AUTHN_CTX` where IdP login page is displayed to obtain user/password.| +|useJdkCacertsForSslVerification |No |When performing IdP's SSL verification, find IdP's certs under JDK's cacerts instead of app's keystore file.

Default is `false`.| ## Important SAML Endpoints @@ -253,38 +288,3 @@ Learn about my pains and lessons learned while building this module. * [Configuring Binding for Sending SAML Messages to IdP](http://myshittycode.com/2016/02/18/spring-security-saml-configuring-binding-for-sending-saml-messages-to-idp/) * [Java + SAML: Illegal Key Size](http://myshittycode.com/2016/02/18/java-saml-illegal-key-size/) -## Troubleshooting - -### SSL peer failed hostname validation for name: null - -By default, this dependency requires a keystore file that serves 2 purposes:- - -* Acts as a keystore, containing app's public/private key. -* Acts as a truststore, containing IdP's certificate with public key. - -If the keystore does not contain IdP's certificate, the SSL verification will fail with the following error when attempting to retrieve IdP's metadata:- - -``` -PKIX path construction failed for untrusted credential: [subjectName='CN=idp.server.com,OU=IDP,C=US']: unable to find valid certification path to requested target -I/O exception (javax.net.ssl.SSLPeerUnverifiedException) caught when processing request: SSL peer failed hostname validation for name: null -Error retrieving metadata from https://idp.server.com/federationmetadata/2007-06/federationmetadata.xml -``` - -That said, sometimes you may want to rely on the installed JDK's truststore (ie: cacerts) to manage IdP's certificate. - -To pull this off, don't create `TLSProtocolConfigurer` object by doing this:- - -```java -@Configuration -@EnableWebSecurity -class AppSecurityConfig extends SAMLWebSecurityConfigurerAdapter { - - @Bean - @Override - TLSProtocolConfigurer tlsProtocolConfigurer() { - return null; - } - - ... -} -``` diff --git a/pom.xml b/pom.xml index 87f9153..5792295 100644 --- a/pom.xml +++ b/pom.xml @@ -5,13 +5,13 @@ com.github.choonchernlim - build-reports - 0.3.5 + spring-boot-ci + 0.4.0 spring-security-adfs-saml2 - 0.8.0 + 0.9.0 jar Spring Security ADFS SAML2 @@ -45,17 +45,12 @@ UTF-8 1.8 - 1.0.3.RELEASE - 5.0.7.RELEASE - 5.0.6.RELEASE - 2.6.4 - 7.0 - 3.4.0 0.1.1 - 3.1.0 - 1.1-groovy-2.4-rc-3 - 3.2.4 - 2.5.1 + 2.6.4 + 8.0 + 4.2.2 + 3.0.1 + 1.0.3.RELEASE @@ -81,21 +76,6 @@ - - org.springframework.security - spring-security-core - ${spring-security.version} - - - org.springframework.security - spring-security-config - ${spring-security.version} - - - org.springframework.security - spring-security-web - ${spring-security.version} - org.opensaml opensaml @@ -106,26 +86,6 @@ better-preconditions ${better-preconditions.version} - - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} - - - org.springframework - spring-test - ${spring.version} - - - org.spockframework - spock-core - ${spock-core.version} - - - cglib - cglib-nodep - ${cglib-nodep.version} - org.objenesis objenesis @@ -174,7 +134,7 @@ org.spockframework - spock-core + spock-spring test @@ -191,29 +151,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - groovy-eclipse-compiler - ${jdk.version} - ${jdk.version} - - - - org.codehaus.groovy - groovy-eclipse-compiler - 2.9.2-01 - - - org.codehaus.groovy - groovy-eclipse-batch - 2.4.3-01 - - - -