Format Federation Example

Issue gh-122
This commit is contained in:
Josh Cummings
2023-02-28 10:06:34 -07:00
parent 7ffe455088
commit c2957a3a2c
2 changed files with 12 additions and 11 deletions

View File

@@ -29,7 +29,6 @@ import org.opensaml.saml.saml2.core.impl.ResponseUnmarshaller;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.springframework.lang.NonNull;
import org.springframework.security.saml2.core.OpenSamlInitializationService;
import org.springframework.security.saml2.core.Saml2Error;
import org.springframework.security.saml2.core.Saml2ErrorCodes;
@@ -40,11 +39,13 @@ import org.springframework.security.saml2.provider.service.registration.RelyingP
import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationResolver;
public class EntityIdRelyingPartyRegistrationResolver implements RelyingPartyRegistrationResolver {
static {
OpenSamlInitializationService.initialize();
}
private final ResponseUnmarshaller responseUnmarshaller;
private final ParserPool parserPool;
private final InMemoryRelyingPartyRegistrationRepository registrations;
@@ -96,4 +97,5 @@ public class EntityIdRelyingPartyRegistrationResolver implements RelyingPartyReg
throw new Saml2AuthenticationException(error, ex.getMessage());
}
}
}

View File

@@ -65,7 +65,6 @@ public class SecurityConfiguration {
return http.build();
}
@Bean
Saml2AuthenticationTokenConverter usingEntityId(InMemoryRelyingPartyRegistrationRepository repository) {
var registrations = new EntityIdRelyingPartyRegistrationResolver(repository);
@@ -82,28 +81,28 @@ public class SecurityConfiguration {
@Bean
InMemoryRelyingPartyRegistrationRepository repository(Saml2RelyingPartyProperties properties,
@Value("classpath:credentials/rp-private.key") RSAPrivateKey key,
@Value("classpath:credentials/rp-certificate.crt") File cert) {
@Value("classpath:credentials/rp-private.key") RSAPrivateKey key,
@Value("classpath:credentials/rp-certificate.crt") File cert) {
Saml2X509Credential signing = Saml2X509Credential.signing(key, x509Certificate(cert));
Registration registration = properties.getRegistration().values().iterator().next();
return new InMemoryRelyingPartyRegistrationRepository(RelyingPartyRegistrations
.collectionFromMetadataLocation(registration.getAssertingparty().getMetadataUri())
.stream().map((builder) -> builder
.registrationId(UUID.randomUUID().toString())
.collectionFromMetadataLocation(registration.getAssertingparty().getMetadataUri()).stream()
.map((builder) -> builder.registrationId(UUID.randomUUID().toString())
.entityId(registration.getEntityId())
.assertionConsumerServiceLocation(registration.getAcs().getLocation())
.singleLogoutServiceLocation(registration.getSinglelogout().getUrl())
.singleLogoutServiceResponseLocation(registration.getSinglelogout().getResponseUrl())
.signingX509Credentials(credentials -> credentials.add(signing))
.build()
).collect(Collectors.toList()));
.signingX509Credentials((credentials) -> credentials.add(signing)).build())
.collect(Collectors.toList()));
}
X509Certificate x509Certificate(File location) {
try (InputStream source = new FileInputStream(location)) {
return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(source);
} catch (CertificateException | IOException ex) {
}
catch (CertificateException | IOException ex) {
throw new IllegalArgumentException(ex);
}
}
}