|
@@ -103,18 +103,15 @@ import org.springframework.util.StringUtils;
|
|
* {@link Saml2AuthenticationToken#getSaml2Response()} along with the information about
|
|
* {@link Saml2AuthenticationToken#getSaml2Response()} along with the information about
|
|
* the asserting party, the identity provider (IDP), as well as the relying party, the
|
|
* the asserting party, the identity provider (IDP), as well as the relying party, the
|
|
* service provider (SP, this application).
|
|
* service provider (SP, this application).
|
|
- * </p>
|
|
|
|
* <p>
|
|
* <p>
|
|
* The {@link Saml2AuthenticationToken} will be processed into a SAML Response object. The
|
|
* The {@link Saml2AuthenticationToken} will be processed into a SAML Response object. The
|
|
* SAML response object can be signed. If the Response is signed, a signature will not be
|
|
* SAML response object can be signed. If the Response is signed, a signature will not be
|
|
* required on the assertion.
|
|
* required on the assertion.
|
|
- * </p>
|
|
|
|
* <p>
|
|
* <p>
|
|
* While a response object can contain a list of assertion, this provider will only
|
|
* While a response object can contain a list of assertion, this provider will only
|
|
* leverage the first valid assertion for the purpose of authentication. Assertions that
|
|
* leverage the first valid assertion for the purpose of authentication. Assertions that
|
|
* do not pass validation will be ignored. If no valid assertions are found a
|
|
* do not pass validation will be ignored. If no valid assertions are found a
|
|
* {@link Saml2AuthenticationException} is thrown.
|
|
* {@link Saml2AuthenticationException} is thrown.
|
|
- * </p>
|
|
|
|
* <p>
|
|
* <p>
|
|
* This provider supports two types of encrypted SAML elements
|
|
* This provider supports two types of encrypted SAML elements
|
|
* <ul>
|
|
* <ul>
|
|
@@ -125,11 +122,9 @@ import org.springframework.util.StringUtils;
|
|
* </ul>
|
|
* </ul>
|
|
* If the assertion is encrypted, then signature validation on the assertion is no longer
|
|
* If the assertion is encrypted, then signature validation on the assertion is no longer
|
|
* required.
|
|
* required.
|
|
- * </p>
|
|
|
|
* <p>
|
|
* <p>
|
|
* This provider does not perform an X509 certificate validation on the configured
|
|
* This provider does not perform an X509 certificate validation on the configured
|
|
* asserting party, IDP, verification certificates.
|
|
* asserting party, IDP, verification certificates.
|
|
- * </p>
|
|
|
|
*
|
|
*
|
|
* @author Ryan Cassar
|
|
* @author Ryan Cassar
|
|
* @since 5.2
|
|
* @since 5.2
|
|
@@ -138,7 +133,7 @@ import org.springframework.util.StringUtils;
|
|
* StatusResponse</a>
|
|
* StatusResponse</a>
|
|
* @see <a href="https://wiki.shibboleth.net/confluence/display/OS30/Home">OpenSAML 3</a>
|
|
* @see <a href="https://wiki.shibboleth.net/confluence/display/OS30/Home">OpenSAML 3</a>
|
|
* @deprecated Because OpenSAML 3 has reached End-of-Life, please update to
|
|
* @deprecated Because OpenSAML 3 has reached End-of-Life, please update to
|
|
- * {@link OpenSaml4AuthenticationProvider}
|
|
|
|
|
|
+ * {@code OpenSaml4AuthenticationProvider}
|
|
*/
|
|
*/
|
|
public final class OpenSamlAuthenticationProvider implements AuthenticationProvider {
|
|
public final class OpenSamlAuthenticationProvider implements AuthenticationProvider {
|
|
|
|
|
|
@@ -195,7 +190,7 @@ public final class OpenSamlAuthenticationProvider implements AuthenticationProvi
|
|
*
|
|
*
|
|
* <pre>
|
|
* <pre>
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
- * provider.setResponseElementsDecrypter((responseToken) -> {
|
|
|
|
|
|
+ * provider.setResponseElementsDecrypter((responseToken) -> {
|
|
* DecrypterParameters parameters = new DecrypterParameters();
|
|
* DecrypterParameters parameters = new DecrypterParameters();
|
|
* // ... set parameters as needed
|
|
* // ... set parameters as needed
|
|
* Decrypter decrypter = new Decrypter(parameters);
|
|
* Decrypter decrypter = new Decrypter(parameters);
|
|
@@ -216,7 +211,7 @@ public final class OpenSamlAuthenticationProvider implements AuthenticationProvi
|
|
* <pre>
|
|
* <pre>
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* Converter<EncryptedAssertion, Assertion> myService = ...
|
|
* Converter<EncryptedAssertion, Assertion> myService = ...
|
|
- * provider.setResponseDecrypter((responseToken) -> {
|
|
|
|
|
|
+ * provider.setResponseDecrypter((responseToken) -> {
|
|
* Response response = responseToken.getResponse();
|
|
* Response response = responseToken.getResponse();
|
|
* response.getEncryptedAssertions().stream()
|
|
* response.getEncryptedAssertions().stream()
|
|
* .map(service::decrypt).forEach(response.getAssertions()::add);
|
|
* .map(service::decrypt).forEach(response.getAssertions()::add);
|
|
@@ -242,7 +237,7 @@ public final class OpenSamlAuthenticationProvider implements AuthenticationProvi
|
|
*
|
|
*
|
|
* <pre>
|
|
* <pre>
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
- * provider.setAssertionValidator(assertionToken -> {
|
|
|
|
|
|
+ * provider.setAssertionValidator(assertionToken -> {
|
|
* Saml2ResponseValidatorResult result = createDefaultAssertionValidator()
|
|
* Saml2ResponseValidatorResult result = createDefaultAssertionValidator()
|
|
* .convert(assertionToken)
|
|
* .convert(assertionToken)
|
|
* return result.concat(myCustomValidator.convert(assertionToken));
|
|
* return result.concat(myCustomValidator.convert(assertionToken));
|
|
@@ -255,7 +250,7 @@ public final class OpenSamlAuthenticationProvider implements AuthenticationProvi
|
|
* <pre>
|
|
* <pre>
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* provider.setAssertionValidator(
|
|
* provider.setAssertionValidator(
|
|
- * createDefaultAssertionValidator(assertionToken -> {
|
|
|
|
|
|
+ * createDefaultAssertionValidator(assertionToken -> {
|
|
* Map<String, Object> params = new HashMap<>();
|
|
* Map<String, Object> params = new HashMap<>();
|
|
* params.put(CLOCK_SKEW, 2 * 60 * 1000);
|
|
* params.put(CLOCK_SKEW, 2 * 60 * 1000);
|
|
* // other parameters
|
|
* // other parameters
|
|
@@ -271,7 +266,7 @@ public final class OpenSamlAuthenticationProvider implements AuthenticationProvi
|
|
* step from this validator.
|
|
* step from this validator.
|
|
*
|
|
*
|
|
* This method takes precedence over {@link #setResponseTimeValidationSkew}.
|
|
* This method takes precedence over {@link #setResponseTimeValidationSkew}.
|
|
- * @param assertionValidator
|
|
|
|
|
|
+ * @param assertionValidator the strategy for validating a given assertion
|
|
* @since 5.4
|
|
* @since 5.4
|
|
*/
|
|
*/
|
|
public void setAssertionValidator(Converter<AssertionToken, Saml2ResponseValidatorResult> assertionValidator) {
|
|
public void setAssertionValidator(Converter<AssertionToken, Saml2ResponseValidatorResult> assertionValidator) {
|
|
@@ -287,7 +282,7 @@ public final class OpenSamlAuthenticationProvider implements AuthenticationProvi
|
|
*
|
|
*
|
|
* <pre>
|
|
* <pre>
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
- * provider.setResponseDecrypter((assertionToken) -> {
|
|
|
|
|
|
+ * provider.setResponseDecrypter((assertionToken) -> {
|
|
* DecrypterParameters parameters = new DecrypterParameters();
|
|
* DecrypterParameters parameters = new DecrypterParameters();
|
|
* // ... set parameters as needed
|
|
* // ... set parameters as needed
|
|
* Decrypter decrypter = new Decrypter(parameters);
|
|
* Decrypter decrypter = new Decrypter(parameters);
|
|
@@ -307,7 +302,7 @@ public final class OpenSamlAuthenticationProvider implements AuthenticationProvi
|
|
* <pre>
|
|
* <pre>
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* MyDecryptionService myService = ...
|
|
* MyDecryptionService myService = ...
|
|
- * provider.setResponseDecrypter((responseToken) -> {
|
|
|
|
|
|
+ * provider.setResponseDecrypter((responseToken) -> {
|
|
* Assertion assertion = assertionToken.getAssertion();
|
|
* Assertion assertion = assertionToken.getAssertion();
|
|
* EncryptedID encrypted = assertion.getSubject().getEncryptedID();
|
|
* EncryptedID encrypted = assertion.getSubject().getEncryptedID();
|
|
* NameID name = myService.decrypt(encrypted);
|
|
* NameID name = myService.decrypt(encrypted);
|
|
@@ -333,7 +328,7 @@ public final class OpenSamlAuthenticationProvider implements AuthenticationProvi
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
* Converter<ResponseToken, Saml2Authentication> authenticationConverter =
|
|
* Converter<ResponseToken, Saml2Authentication> authenticationConverter =
|
|
* createDefaultResponseAuthenticationConverter();
|
|
* createDefaultResponseAuthenticationConverter();
|
|
- * provider.setResponseAuthenticationConverter(responseToken -> {
|
|
|
|
|
|
+ * provider.setResponseAuthenticationConverter(responseToken -> {
|
|
* Saml2Authentication authentication = authenticationConverter.convert(responseToken);
|
|
* Saml2Authentication authentication = authenticationConverter.convert(responseToken);
|
|
* User user = myUserRepository.findByUsername(authentication.getName());
|
|
* User user = myUserRepository.findByUsername(authentication.getName());
|
|
* return new MyAuthentication(authentication, user);
|
|
* return new MyAuthentication(authentication, user);
|