|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2019 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2020 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -16,23 +16,51 @@
|
|
|
|
|
|
package org.springframework.security.saml2.provider.service.authentication;
|
|
package org.springframework.security.saml2.provider.service.authentication;
|
|
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
import org.springframework.security.saml2.credentials.Saml2X509Credential;
|
|
import org.springframework.security.saml2.credentials.Saml2X509Credential;
|
|
|
|
+import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
|
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import static org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.withRegistrationId;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Represents an incoming SAML 2.0 response containing an assertion that has not been validated.
|
|
* Represents an incoming SAML 2.0 response containing an assertion that has not been validated.
|
|
* {@link Saml2AuthenticationToken#isAuthenticated()} will always return false.
|
|
* {@link Saml2AuthenticationToken#isAuthenticated()} will always return false.
|
|
|
|
+ *
|
|
* @since 5.2
|
|
* @since 5.2
|
|
|
|
+ * @author Filip Hanik
|
|
|
|
+ * @author Josh Cummings
|
|
*/
|
|
*/
|
|
public class Saml2AuthenticationToken extends AbstractAuthenticationToken {
|
|
public class Saml2AuthenticationToken extends AbstractAuthenticationToken {
|
|
|
|
|
|
|
|
+ private final RelyingPartyRegistration relyingPartyRegistration;
|
|
private final String saml2Response;
|
|
private final String saml2Response;
|
|
- private final String recipientUri;
|
|
|
|
- private String idpEntityId;
|
|
|
|
- private String localSpEntityId;
|
|
|
|
- private List<Saml2X509Credential> credentials;
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Creates a {@link Saml2AuthenticationToken} with the provided parameters
|
|
|
|
+ *
|
|
|
|
+ * Note that the given {@link RelyingPartyRegistration} should have all its
|
|
|
|
+ * templates resolved at this point. See
|
|
|
|
+ * {@link org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationFilter}
|
|
|
|
+ * for an example of performing that resolution.
|
|
|
|
+ *
|
|
|
|
+ * @param relyingPartyRegistration the resolved {@link RelyingPartyRegistration} to use
|
|
|
|
+ * @param saml2Response the SAML 2.0 response to authenticate
|
|
|
|
+ *
|
|
|
|
+ * @since 5.4
|
|
|
|
+ */
|
|
|
|
+ public Saml2AuthenticationToken(RelyingPartyRegistration relyingPartyRegistration,
|
|
|
|
+ String saml2Response) {
|
|
|
|
+
|
|
|
|
+ super(Collections.emptyList());
|
|
|
|
+ Assert.notNull(relyingPartyRegistration, "relyingPartyRegistration cannot be null");
|
|
|
|
+ Assert.notNull(saml2Response, "saml2Response cannot be null");
|
|
|
|
+ this.relyingPartyRegistration = relyingPartyRegistration;
|
|
|
|
+ this.saml2Response = saml2Response;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Creates an authentication token from an incoming SAML 2 Response object
|
|
* Creates an authentication token from an incoming SAML 2 Response object
|
|
@@ -41,18 +69,24 @@ public class Saml2AuthenticationToken extends AbstractAuthenticationToken {
|
|
* @param idpEntityId the entity ID of the asserting entity
|
|
* @param idpEntityId the entity ID of the asserting entity
|
|
* @param localSpEntityId the configured local SP, the relying party, entity ID
|
|
* @param localSpEntityId the configured local SP, the relying party, entity ID
|
|
* @param credentials the credentials configured for signature verification and decryption
|
|
* @param credentials the credentials configured for signature verification and decryption
|
|
|
|
+ * @deprecated Use {@link Saml2AuthenticationToken(RelyingPartyRegistration, String)} instead
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public Saml2AuthenticationToken(String saml2Response,
|
|
public Saml2AuthenticationToken(String saml2Response,
|
|
String recipientUri,
|
|
String recipientUri,
|
|
String idpEntityId,
|
|
String idpEntityId,
|
|
String localSpEntityId,
|
|
String localSpEntityId,
|
|
List<Saml2X509Credential> credentials) {
|
|
List<Saml2X509Credential> credentials) {
|
|
super(null);
|
|
super(null);
|
|
|
|
+ this.relyingPartyRegistration = withRegistrationId(idpEntityId)
|
|
|
|
+ .entityId(localSpEntityId)
|
|
|
|
+ .assertionConsumerServiceLocation(recipientUri)
|
|
|
|
+ .credentials(c -> c.addAll(credentials))
|
|
|
|
+ .assertingPartyDetails(assertingParty -> assertingParty
|
|
|
|
+ .entityId(idpEntityId)
|
|
|
|
+ .singleSignOnServiceLocation(idpEntityId))
|
|
|
|
+ .build();
|
|
this.saml2Response = saml2Response;
|
|
this.saml2Response = saml2Response;
|
|
- this.recipientUri = recipientUri;
|
|
|
|
- this.idpEntityId = idpEntityId;
|
|
|
|
- this.localSpEntityId = localSpEntityId;
|
|
|
|
- this.credentials = credentials;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -73,6 +107,16 @@ public class Saml2AuthenticationToken extends AbstractAuthenticationToken {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Get the resolved {@link RelyingPartyRegistration} associated with the request
|
|
|
|
+ *
|
|
|
|
+ * @return the resolved {@link RelyingPartyRegistration}
|
|
|
|
+ * @since 5.4
|
|
|
|
+ */
|
|
|
|
+ public RelyingPartyRegistration getRelyingPartyRegistration() {
|
|
|
|
+ return this.relyingPartyRegistration;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns inflated and decoded XML representation of the SAML 2 Response
|
|
* Returns inflated and decoded XML representation of the SAML 2 Response
|
|
* @return inflated and decoded XML representation of the SAML 2 Response
|
|
* @return inflated and decoded XML representation of the SAML 2 Response
|
|
@@ -84,25 +128,31 @@ public class Saml2AuthenticationToken extends AbstractAuthenticationToken {
|
|
/**
|
|
/**
|
|
* Returns the URI that the SAML 2 Response object came in on
|
|
* Returns the URI that the SAML 2 Response object came in on
|
|
* @return URI as a string
|
|
* @return URI as a string
|
|
|
|
+ * @deprecated Use {@link #getRelyingPartyRegistration().getAssertionConsumerServiceLocation()} instead
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public String getRecipientUri() {
|
|
public String getRecipientUri() {
|
|
- return this.recipientUri;
|
|
|
|
|
|
+ return this.relyingPartyRegistration.getAssertionConsumerServiceLocation();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns the configured entity ID of the receiving relying party, SP
|
|
* Returns the configured entity ID of the receiving relying party, SP
|
|
* @return an entityID for the configured local relying party
|
|
* @return an entityID for the configured local relying party
|
|
|
|
+ * @deprecated Use {@link #getRelyingPartyRegistration().getEntityId()} instead
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public String getLocalSpEntityId() {
|
|
public String getLocalSpEntityId() {
|
|
- return this.localSpEntityId;
|
|
|
|
|
|
+ return this.relyingPartyRegistration.getEntityId();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns all the credentials associated with the relying party configuraiton
|
|
* Returns all the credentials associated with the relying party configuraiton
|
|
* @return
|
|
* @return
|
|
|
|
+ * @deprecated Get the credentials through {@link #getRelyingPartyRegistration()} instead
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public List<Saml2X509Credential> getX509Credentials() {
|
|
public List<Saml2X509Credential> getX509Credentials() {
|
|
- return this.credentials;
|
|
|
|
|
|
+ return this.relyingPartyRegistration.getCredentials();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -126,8 +176,10 @@ public class Saml2AuthenticationToken extends AbstractAuthenticationToken {
|
|
/**
|
|
/**
|
|
* Returns the configured IDP, asserting party, entity ID
|
|
* Returns the configured IDP, asserting party, entity ID
|
|
* @return a string representing the entity ID
|
|
* @return a string representing the entity ID
|
|
|
|
+ * @deprecated Use {@link #getRelyingPartyRegistration().getAssertingPartyDetails().getEntityId()} instead
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public String getIdpEntityId() {
|
|
public String getIdpEntityId() {
|
|
- return this.idpEntityId;
|
|
|
|
|
|
+ return this.relyingPartyRegistration.getAssertingPartyDetails().getEntityId();
|
|
}
|
|
}
|
|
}
|
|
}
|