|
|
@ -20,6 +20,7 @@ import java.io.InputStream;
|
|
|
|
import java.security.cert.CertificateFactory;
|
|
|
|
import java.security.cert.CertificateFactory;
|
|
|
|
import java.security.cert.X509Certificate;
|
|
|
|
import java.security.cert.X509Certificate;
|
|
|
|
import java.security.interfaces.RSAPrivateKey;
|
|
|
|
import java.security.interfaces.RSAPrivateKey;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
import java.util.function.Consumer;
|
|
|
@ -63,6 +64,7 @@ import org.springframework.util.StringUtils;
|
|
|
|
* @author Madhura Bhave
|
|
|
|
* @author Madhura Bhave
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @author Moritz Halbritter
|
|
|
|
* @author Moritz Halbritter
|
|
|
|
|
|
|
|
* @author Lasse Lindqvist
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Conditional(RegistrationConfiguredCondition.class)
|
|
|
|
@Conditional(RegistrationConfiguredCondition.class)
|
|
|
@ -88,14 +90,8 @@ class Saml2RelyingPartyRegistrationConfiguration {
|
|
|
|
private RelyingPartyRegistration asRegistration(String id, Registration properties) {
|
|
|
|
private RelyingPartyRegistration asRegistration(String id, Registration properties) {
|
|
|
|
AssertingPartyProperties assertingParty = new AssertingPartyProperties(properties, id);
|
|
|
|
AssertingPartyProperties assertingParty = new AssertingPartyProperties(properties, id);
|
|
|
|
boolean usingMetadata = StringUtils.hasText(assertingParty.getMetadataUri());
|
|
|
|
boolean usingMetadata = StringUtils.hasText(assertingParty.getMetadataUri());
|
|
|
|
Builder builder = (usingMetadata) ? RelyingPartyRegistrations
|
|
|
|
Builder builder = (!usingMetadata) ? RelyingPartyRegistration.withRegistrationId(id)
|
|
|
|
.collectionFromMetadataLocation(properties.getAssertingparty().getMetadataUri())
|
|
|
|
: createBuilderUsingMetadata(id, assertingParty).registrationId(id);
|
|
|
|
.stream()
|
|
|
|
|
|
|
|
.filter(b -> entityIdsMatch(properties, b))
|
|
|
|
|
|
|
|
.findFirst()
|
|
|
|
|
|
|
|
.orElseThrow(() -> new IllegalStateException(
|
|
|
|
|
|
|
|
"No relying party with entity-id " + properties.getEntityId() + " found."))
|
|
|
|
|
|
|
|
.registrationId(id) : RelyingPartyRegistration.withRegistrationId(id);
|
|
|
|
|
|
|
|
builder.assertionConsumerServiceLocation(properties.getAcs().getLocation());
|
|
|
|
builder.assertionConsumerServiceLocation(properties.getAcs().getLocation());
|
|
|
|
builder.assertionConsumerServiceBinding(properties.getAcs().getBinding());
|
|
|
|
builder.assertionConsumerServiceBinding(properties.getAcs().getBinding());
|
|
|
|
builder.assertingPartyDetails(mapAssertingParty(properties, id, usingMetadata));
|
|
|
|
builder.assertingPartyDetails(mapAssertingParty(properties, id, usingMetadata));
|
|
|
@ -124,17 +120,23 @@ class Saml2RelyingPartyRegistrationConfiguration {
|
|
|
|
return registration;
|
|
|
|
return registration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
private RelyingPartyRegistration.Builder createBuilderUsingMetadata(String id,
|
|
|
|
* Tests if the builder would have the correct entity-id. If no entity-id is given in
|
|
|
|
AssertingPartyProperties properties) {
|
|
|
|
* properties, any builder passes the test.
|
|
|
|
String requiredEntityId = properties.getEntityId();
|
|
|
|
* @param properties the properties
|
|
|
|
Collection<Builder> candidates = RelyingPartyRegistrations
|
|
|
|
* @param b the builder
|
|
|
|
.collectionFromMetadataLocation(properties.getMetadataUri());
|
|
|
|
* @return true if the builder passes the test
|
|
|
|
for (RelyingPartyRegistration.Builder candidate : candidates) {
|
|
|
|
*/
|
|
|
|
if (requiredEntityId == null || requiredEntityId.equals(getEntityId(candidate))) {
|
|
|
|
private boolean entityIdsMatch(Registration properties, Builder b) {
|
|
|
|
return candidate;
|
|
|
|
RelyingPartyRegistration rpr = b.build();
|
|
|
|
}
|
|
|
|
return properties.getAssertingparty().getEntityId() == null
|
|
|
|
}
|
|
|
|
|| properties.getAssertingparty().getEntityId().equals(rpr.getAssertingPartyDetails().getEntityId());
|
|
|
|
throw new IllegalStateException("No relying party with Entity ID '" + requiredEntityId + "' found");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Object getEntityId(RelyingPartyRegistration.Builder candidate) {
|
|
|
|
|
|
|
|
String[] result = new String[1];
|
|
|
|
|
|
|
|
candidate.assertingPartyDetails((builder) -> result[0] = builder.build().getEntityId());
|
|
|
|
|
|
|
|
return result[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Consumer<AssertingPartyDetails.Builder> mapAssertingParty(Registration registration, String id,
|
|
|
|
private Consumer<AssertingPartyDetails.Builder> mapAssertingParty(Registration registration, String id,
|
|
|
|