|
|
@ -22,6 +22,7 @@ import java.security.cert.X509Certificate;
|
|
|
|
import java.security.interfaces.RSAPrivateKey;
|
|
|
|
import java.security.interfaces.RSAPrivateKey;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
@ -37,6 +38,8 @@ import org.springframework.security.converter.RsaKeyConverters;
|
|
|
|
import org.springframework.security.saml2.core.Saml2X509Credential;
|
|
|
|
import org.springframework.security.saml2.core.Saml2X509Credential;
|
|
|
|
import org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository;
|
|
|
|
import org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository;
|
|
|
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
|
|
|
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
|
|
|
|
|
|
|
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.AssertingPartyDetails;
|
|
|
|
|
|
|
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.Builder;
|
|
|
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
|
|
|
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
|
|
|
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrations;
|
|
|
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrations;
|
|
|
|
import org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationFilter;
|
|
|
|
import org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationFilter;
|
|
|
@ -67,26 +70,13 @@ class Saml2RelyingPartyRegistrationConfiguration {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private RelyingPartyRegistration asRegistration(String id, Registration properties) {
|
|
|
|
private RelyingPartyRegistration asRegistration(String id, Registration properties) {
|
|
|
|
RelyingPartyRegistration.Builder builder;
|
|
|
|
|
|
|
|
boolean usingMetadata = StringUtils.hasText(properties.getIdentityprovider().getMetadataUri());
|
|
|
|
boolean usingMetadata = StringUtils.hasText(properties.getIdentityprovider().getMetadataUri());
|
|
|
|
if (usingMetadata) {
|
|
|
|
Builder builder = (usingMetadata) ? RelyingPartyRegistrations
|
|
|
|
builder = RelyingPartyRegistrations.fromMetadataLocation(properties.getIdentityprovider().getMetadataUri())
|
|
|
|
.fromMetadataLocation(properties.getIdentityprovider().getMetadataUri()).registrationId(id)
|
|
|
|
.registrationId(id);
|
|
|
|
: RelyingPartyRegistration.withRegistrationId(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
builder = RelyingPartyRegistration.withRegistrationId(id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.assertionConsumerServiceLocation(
|
|
|
|
builder.assertionConsumerServiceLocation(
|
|
|
|
"{baseUrl}" + Saml2WebSsoAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI);
|
|
|
|
"{baseUrl}" + Saml2WebSsoAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI);
|
|
|
|
Saml2RelyingPartyProperties.Identityprovider identityprovider = properties.getIdentityprovider();
|
|
|
|
builder.assertingPartyDetails(mapIdentityProvider(properties, usingMetadata));
|
|
|
|
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
|
|
|
|
|
|
|
builder.assertingPartyDetails((details) -> {
|
|
|
|
|
|
|
|
map.from(identityprovider::getEntityId).to(details::entityId);
|
|
|
|
|
|
|
|
map.from(identityprovider.getSinglesignon()::getBinding).to(details::singleSignOnServiceBinding);
|
|
|
|
|
|
|
|
map.from(identityprovider.getSinglesignon()::getUrl).to(details::singleSignOnServiceLocation);
|
|
|
|
|
|
|
|
map.from(identityprovider.getSinglesignon()::isSignRequest).when((signRequest) -> !usingMetadata)
|
|
|
|
|
|
|
|
.to(details::wantAuthnRequestsSigned);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.signingX509Credentials((credentials) -> properties.getSigning().getCredentials().stream()
|
|
|
|
builder.signingX509Credentials((credentials) -> properties.getSigning().getCredentials().stream()
|
|
|
|
.map(this::asSigningCredential).forEach(credentials::add));
|
|
|
|
.map(this::asSigningCredential).forEach(credentials::add));
|
|
|
|
builder.assertingPartyDetails((details) -> details
|
|
|
|
builder.assertingPartyDetails((details) -> details
|
|
|
@ -99,6 +89,19 @@ class Saml2RelyingPartyRegistrationConfiguration {
|
|
|
|
return registration;
|
|
|
|
return registration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Consumer<AssertingPartyDetails.Builder> mapIdentityProvider(Registration properties,
|
|
|
|
|
|
|
|
boolean usingMetadata) {
|
|
|
|
|
|
|
|
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
|
|
|
|
|
|
|
Saml2RelyingPartyProperties.Identityprovider identityprovider = properties.getIdentityprovider();
|
|
|
|
|
|
|
|
return (details) -> {
|
|
|
|
|
|
|
|
map.from(identityprovider::getEntityId).to(details::entityId);
|
|
|
|
|
|
|
|
map.from(identityprovider.getSinglesignon()::getBinding).to(details::singleSignOnServiceBinding);
|
|
|
|
|
|
|
|
map.from(identityprovider.getSinglesignon()::getUrl).to(details::singleSignOnServiceLocation);
|
|
|
|
|
|
|
|
map.from(identityprovider.getSinglesignon()::isSignRequest).when((signRequest) -> !usingMetadata)
|
|
|
|
|
|
|
|
.to(details::wantAuthnRequestsSigned);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void validateSigningCredentials(Registration properties, boolean signRequest) {
|
|
|
|
private void validateSigningCredentials(Registration properties, boolean signRequest) {
|
|
|
|
if (signRequest) {
|
|
|
|
if (signRequest) {
|
|
|
|
Assert.state(!properties.getSigning().getCredentials().isEmpty(),
|
|
|
|
Assert.state(!properties.getSigning().getCredentials().isEmpty(),
|
|
|
|