Apply formatting

This commit is contained in:
Marcus Hert Da Coregio
2024-01-24 10:28:39 -03:00
parent 64eb62026c
commit 923b627eda
35 changed files with 175 additions and 110 deletions

View File

@@ -77,8 +77,9 @@ public class CustomUrlsApplicationITests {
@Test
void metadataWhenGetThenForwardToUrl() throws Exception {
this.mvc.perform(get("/saml/metadata")).andExpect(status().isOk())
.andExpect(forwardedUrl("/saml2/service-provider-metadata/one"));
this.mvc.perform(get("/saml/metadata"))
.andExpect(status().isOk())
.andExpect(forwardedUrl("/saml2/service-provider-metadata/one"));
}
private void performLogin() throws Exception {

View File

@@ -82,9 +82,11 @@ public class SecurityConfiguration {
@Value("classpath:credentials/rp-private.key") RSAPrivateKey privateKey) {
Saml2X509Credential signing = Saml2X509Credential.signing(privateKey, relyingPartyCertificate());
RelyingPartyRegistration two = RelyingPartyRegistrations
.fromMetadataLocation("https://dev-05937739.okta.com/app/exk4842vmapcMkohr5d7/sso/saml/metadata")
.registrationId("two").signingX509Credentials((c) -> c.add(signing))
.singleLogoutServiceLocation("http://localhost:8080/logout/saml2/slo").build();
.fromMetadataLocation("https://dev-05937739.okta.com/app/exk4842vmapcMkohr5d7/sso/saml/metadata")
.registrationId("two")
.signingX509Credentials((c) -> c.add(signing))
.singleLogoutServiceLocation("http://localhost:8080/logout/saml2/slo")
.build();
return new InMemoryRelyingPartyRegistrationRepository(two);
}

View File

@@ -61,17 +61,22 @@ public class RefreshableRelyingPartyRegistrationRepository
@Scheduled(fixedDelay = 30, timeUnit = TimeUnit.MINUTES)
public void refreshMetadata() {
for (Map.Entry<String, Saml2RelyingPartyProperties.Registration> byRegistrationId : this.relyingPartyProperties
.getRegistration().entrySet()) {
.getRegistration()
.entrySet()) {
fetchMetadata(byRegistrationId.getKey(), byRegistrationId.getValue());
}
}
private void fetchMetadata(String registrationId, Saml2RelyingPartyProperties.Registration registration) {
RelyingPartyRegistration relyingPartyRegistration = RelyingPartyRegistrations
.fromMetadataLocation(registration.getAssertingparty().getMetadataUri())
.signingX509Credentials((credentials) -> registration.getSigning().getCredentials().stream()
.map(this::asSigningCredential).forEach(credentials::add))
.registrationId(registrationId).build();
.fromMetadataLocation(registration.getAssertingparty().getMetadataUri())
.signingX509Credentials((credentials) -> registration.getSigning()
.getCredentials()
.stream()
.map(this::asSigningCredential)
.forEach(credentials::add))
.registrationId(registrationId)
.build();
this.relyingPartyRegistrations.put(relyingPartyRegistration.getRegistrationId(), relyingPartyRegistration);
}

View File

@@ -79,8 +79,9 @@ public class SamlExtensionFederationApplicationITests {
@Test
void metadataWhenGetThenForwardToUrl() throws Exception {
this.mvc.perform(get("/saml/metadata")).andExpect(status().isOk())
.andExpect(forwardedUrl("/saml2/service-provider-metadata/one"));
this.mvc.perform(get("/saml/metadata"))
.andExpect(status().isOk())
.andExpect(forwardedUrl("/saml2/service-provider-metadata/one"));
}
private void performLogin() throws Exception {

View File

@@ -66,14 +66,16 @@ public class SecurityConfiguration {
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())
.entityId(registration.getEntityId())
.assertionConsumerServiceLocation(registration.getAcs().getLocation())
.singleLogoutServiceLocation(registration.getSinglelogout().getUrl())
.singleLogoutServiceResponseLocation(registration.getSinglelogout().getResponseUrl())
.signingX509Credentials((credentials) -> credentials.add(signing)).build())
.collect(Collectors.toList()));
.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()));
}
X509Certificate x509Certificate(File location) {