Use parenthesis with single-arg lambdas
Use regular expression search/replace to ensure all single-arg lambdas have parenthesis. This aligns with the style used in Spring Boot and ensure that single-arg and multi-arg lambdas are consistent. Issue gh-8945
This commit is contained in:
+2
-2
@@ -52,7 +52,7 @@ import org.springframework.security.saml2.Saml2Exception;
|
||||
*
|
||||
* <pre>
|
||||
* static {
|
||||
* OpenSamlInitializationService.requireInitialize(registry -> {
|
||||
* OpenSamlInitializationService.requireInitialize((registry) -> {
|
||||
* registry.setParserPool(...);
|
||||
* registry.getBuilderFactory().registerBuilder(...);
|
||||
* });
|
||||
@@ -94,7 +94,7 @@ public final class OpenSamlInitializationService {
|
||||
* @throws Saml2Exception if OpenSAML failed to initialize
|
||||
*/
|
||||
public static boolean initialize() {
|
||||
return initialize(registry -> {
|
||||
return initialize((registry) -> {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+11
-9
@@ -175,20 +175,22 @@ public final class OpenSamlAuthenticationProvider implements AuthenticationProvi
|
||||
|
||||
private final ParserPool parserPool;
|
||||
|
||||
private Converter<Assertion, Collection<? extends GrantedAuthority>> authoritiesExtractor = (a -> Collections
|
||||
private Converter<Assertion, Collection<? extends GrantedAuthority>> authoritiesExtractor = ((a) -> Collections
|
||||
.singletonList(new SimpleGrantedAuthority("ROLE_USER")));
|
||||
|
||||
private GrantedAuthoritiesMapper authoritiesMapper = (a -> a);
|
||||
private GrantedAuthoritiesMapper authoritiesMapper = ((a) -> a);
|
||||
|
||||
private Duration responseTimeValidationSkew = Duration.ofMinutes(5);
|
||||
|
||||
private Function<Saml2AuthenticationToken, Converter<Response, AbstractAuthenticationToken>> authenticationConverter = token -> response -> {
|
||||
Assertion assertion = CollectionUtils.firstElement(response.getAssertions());
|
||||
String username = assertion.getSubject().getNameID().getValue();
|
||||
Map<String, List<Object>> attributes = getAssertionAttributes(assertion);
|
||||
return new Saml2Authentication(new DefaultSaml2AuthenticatedPrincipal(username, attributes),
|
||||
token.getSaml2Response(), this.authoritiesMapper.mapAuthorities(getAssertionAuthorities(assertion)));
|
||||
};
|
||||
private Function<Saml2AuthenticationToken, Converter<Response, AbstractAuthenticationToken>> authenticationConverter = (
|
||||
token) -> (response) -> {
|
||||
Assertion assertion = CollectionUtils.firstElement(response.getAssertions());
|
||||
String username = assertion.getSubject().getNameID().getValue();
|
||||
Map<String, List<Object>> attributes = getAssertionAttributes(assertion);
|
||||
return new Saml2Authentication(new DefaultSaml2AuthenticatedPrincipal(username, attributes),
|
||||
token.getSaml2Response(),
|
||||
this.authoritiesMapper.mapAuthorities(getAssertionAuthorities(assertion)));
|
||||
};
|
||||
|
||||
private Converter<Saml2AuthenticationToken, SignatureTrustEngine> signatureTrustEngineConverter = new SignatureTrustEngineConverter();
|
||||
|
||||
|
||||
+5
-4
@@ -79,15 +79,16 @@ public class OpenSamlAuthenticationRequestFactory implements Saml2Authentication
|
||||
|
||||
private IssuerBuilder issuerBuilder;
|
||||
|
||||
private Converter<Saml2AuthenticationRequestContext, String> protocolBindingResolver = context -> {
|
||||
private Converter<Saml2AuthenticationRequestContext, String> protocolBindingResolver = (context) -> {
|
||||
if (context == null) {
|
||||
return SAMLConstants.SAML2_POST_BINDING_URI;
|
||||
}
|
||||
return context.getRelyingPartyRegistration().getAssertionConsumerServiceBinding().getUrn();
|
||||
};
|
||||
|
||||
private Function<Saml2AuthenticationRequestContext, Consumer<AuthnRequest>> authnRequestConsumerResolver = context -> authnRequest -> {
|
||||
};
|
||||
private Function<Saml2AuthenticationRequestContext, Consumer<AuthnRequest>> authnRequestConsumerResolver = (
|
||||
context) -> (authnRequest) -> {
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an {@link OpenSamlAuthenticationRequestFactory}
|
||||
@@ -220,7 +221,7 @@ public class OpenSamlAuthenticationRequestFactory implements Saml2Authentication
|
||||
if (!isAllowedBinding) {
|
||||
throw new IllegalArgumentException("Invalid protocol binding: " + protocolBinding);
|
||||
}
|
||||
this.protocolBindingResolver = context -> protocolBinding;
|
||||
this.protocolBindingResolver = (context) -> protocolBinding;
|
||||
}
|
||||
|
||||
private AuthnRequest sign(AuthnRequest authnRequest, RelyingPartyRegistration relyingPartyRegistration) {
|
||||
|
||||
+2
-2
@@ -113,7 +113,7 @@ public final class Saml2AuthenticationRequest {
|
||||
public static Builder withAuthenticationRequestContext(Saml2AuthenticationRequestContext context) {
|
||||
return new Builder().assertionConsumerServiceUrl(context.getAssertionConsumerServiceUrl())
|
||||
.issuer(context.getIssuer()).destination(context.getDestination())
|
||||
.credentials(c -> c.addAll(context.getRelyingPartyRegistration().getCredentials()));
|
||||
.credentials((c) -> c.addAll(context.getRelyingPartyRegistration().getCredentials()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +148,7 @@ public final class Saml2AuthenticationRequest {
|
||||
* request. For example: <code>
|
||||
* Saml2X509Credential credential = ...;
|
||||
* return Saml2AuthenticationRequest.withLocalSpEntityId("id")
|
||||
* .credentials(c -> c.add(credential))
|
||||
* .credentials((c) -> c.add(credential))
|
||||
* ...
|
||||
* .build();
|
||||
* </code>
|
||||
|
||||
+2
-3
@@ -78,9 +78,8 @@ public class Saml2AuthenticationToken extends AbstractAuthenticationToken {
|
||||
super(null);
|
||||
this.relyingPartyRegistration = RelyingPartyRegistration.withRegistrationId(idpEntityId)
|
||||
.entityId(localSpEntityId).assertionConsumerServiceLocation(recipientUri)
|
||||
.credentials(c -> c.addAll(credentials))
|
||||
.assertingPartyDetails(
|
||||
assertingParty -> assertingParty.entityId(idpEntityId).singleSignOnServiceLocation(idpEntityId))
|
||||
.credentials((c) -> c.addAll(credentials)).assertingPartyDetails((assertingParty) -> assertingParty
|
||||
.entityId(idpEntityId).singleSignOnServiceLocation(idpEntityId))
|
||||
.build();
|
||||
this.saml2Response = saml2Response;
|
||||
}
|
||||
|
||||
+6
-5
@@ -160,10 +160,10 @@ public class OpenSamlRelyingPartyRegistrationBuilderHttpMessageConverter
|
||||
"Metadata response is missing verification certificates, necessary for verifying SAML assertions");
|
||||
}
|
||||
RelyingPartyRegistration.Builder builder = RelyingPartyRegistration.withRegistrationId(descriptor.getEntityID())
|
||||
.assertingPartyDetails(party -> party.entityId(descriptor.getEntityID())
|
||||
.assertingPartyDetails((party) -> party.entityId(descriptor.getEntityID())
|
||||
.wantAuthnRequestsSigned(Boolean.TRUE.equals(idpssoDescriptor.getWantAuthnRequestsSigned()))
|
||||
.verificationX509Credentials(c -> c.addAll(verification))
|
||||
.encryptionX509Credentials(c -> c.addAll(encryption)));
|
||||
.verificationX509Credentials((c) -> c.addAll(verification))
|
||||
.encryptionX509Credentials((c) -> c.addAll(encryption)));
|
||||
for (SingleSignOnService singleSignOnService : idpssoDescriptor.getSingleSignOnServices()) {
|
||||
Saml2MessageBinding binding;
|
||||
if (singleSignOnService.getBinding().equals(Saml2MessageBinding.POST.getUrn())) {
|
||||
@@ -175,8 +175,9 @@ public class OpenSamlRelyingPartyRegistrationBuilderHttpMessageConverter
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
builder.assertingPartyDetails(party -> party.singleSignOnServiceLocation(singleSignOnService.getLocation())
|
||||
.singleSignOnServiceBinding(binding));
|
||||
builder.assertingPartyDetails(
|
||||
(party) -> party.singleSignOnServiceLocation(singleSignOnService.getLocation())
|
||||
.singleSignOnServiceBinding(binding));
|
||||
return builder;
|
||||
}
|
||||
throw new Saml2Exception(
|
||||
|
||||
+16
-16
@@ -59,11 +59,11 @@ import org.springframework.util.Assert;
|
||||
* RelyingPartyRegistration rp = RelyingPartyRegistration.withRegistrationId(registrationId)
|
||||
* .entityId(relyingPartyEntityId)
|
||||
* .assertionConsumerServiceLocation(assertingConsumerServiceLocation)
|
||||
* .signingX509Credentials(c -> c.add(relyingPartySigningCredential))
|
||||
* .assertingPartyDetails(details -> details
|
||||
* .signingX509Credentials((c) -> c.add(relyingPartySigningCredential))
|
||||
* .assertingPartyDetails((details) -> details
|
||||
* .entityId(assertingPartyEntityId));
|
||||
* .singleSignOnServiceLocation(singleSignOnServiceLocation))
|
||||
* .verifyingX509Credentials(c -> c.add(assertingPartyVerificationCredential))
|
||||
* .verifyingX509Credentials((c) -> c.add(assertingPartyVerificationCredential))
|
||||
* .build();
|
||||
* </pre>
|
||||
*
|
||||
@@ -362,17 +362,17 @@ public final class RelyingPartyRegistration {
|
||||
public static Builder withRelyingPartyRegistration(RelyingPartyRegistration registration) {
|
||||
Assert.notNull(registration, "registration cannot be null");
|
||||
return withRegistrationId(registration.getRegistrationId()).entityId(registration.getEntityId())
|
||||
.signingX509Credentials(c -> c.addAll(registration.getSigningX509Credentials()))
|
||||
.decryptionX509Credentials(c -> c.addAll(registration.getDecryptionX509Credentials()))
|
||||
.signingX509Credentials((c) -> c.addAll(registration.getSigningX509Credentials()))
|
||||
.decryptionX509Credentials((c) -> c.addAll(registration.getDecryptionX509Credentials()))
|
||||
.assertionConsumerServiceLocation(registration.getAssertionConsumerServiceLocation())
|
||||
.assertionConsumerServiceBinding(registration.getAssertionConsumerServiceBinding())
|
||||
.assertingPartyDetails(assertingParty -> assertingParty
|
||||
.assertingPartyDetails((assertingParty) -> assertingParty
|
||||
.entityId(registration.getAssertingPartyDetails().getEntityId())
|
||||
.wantAuthnRequestsSigned(registration.getAssertingPartyDetails().getWantAuthnRequestsSigned())
|
||||
.verificationX509Credentials(
|
||||
c -> c.addAll(registration.getAssertingPartyDetails().getVerificationX509Credentials()))
|
||||
.verificationX509Credentials((c) -> c
|
||||
.addAll(registration.getAssertingPartyDetails().getVerificationX509Credentials()))
|
||||
.encryptionX509Credentials(
|
||||
c -> c.addAll(registration.getAssertingPartyDetails().getEncryptionX509Credentials()))
|
||||
(c) -> c.addAll(registration.getAssertingPartyDetails().getEncryptionX509Credentials()))
|
||||
.singleSignOnServiceLocation(
|
||||
registration.getAssertingPartyDetails().getSingleSignOnServiceLocation())
|
||||
.singleSignOnServiceBinding(
|
||||
@@ -913,7 +913,7 @@ public final class RelyingPartyRegistration {
|
||||
* communication between IDP and SP For example: <code>
|
||||
* Saml2X509Credential credential = ...;
|
||||
* return RelyingPartyRegistration.withRegistrationId("id")
|
||||
* .credentials(c -> c.add(credential))
|
||||
* .credentials((c) -> c.add(credential))
|
||||
* ...
|
||||
* .build();
|
||||
* </code>
|
||||
@@ -959,7 +959,7 @@ public final class RelyingPartyRegistration {
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder remoteIdpEntityId(String entityId) {
|
||||
assertingPartyDetails(idp -> idp.entityId(entityId));
|
||||
assertingPartyDetails((idp) -> idp.entityId(entityId));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -973,7 +973,7 @@ public final class RelyingPartyRegistration {
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder idpWebSsoUrl(String url) {
|
||||
assertingPartyDetails(config -> config.singleSignOnServiceLocation(url));
|
||||
assertingPartyDetails((config) -> config.singleSignOnServiceLocation(url));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1013,16 +1013,16 @@ public final class RelyingPartyRegistration {
|
||||
for (org.springframework.security.saml2.credentials.Saml2X509Credential credential : this.credentials) {
|
||||
Saml2X509Credential mapped = fromDeprecated(credential);
|
||||
if (credential.isSigningCredential()) {
|
||||
signingX509Credentials(c -> c.add(mapped));
|
||||
signingX509Credentials((c) -> c.add(mapped));
|
||||
}
|
||||
if (credential.isDecryptionCredential()) {
|
||||
decryptionX509Credentials(c -> c.add(mapped));
|
||||
decryptionX509Credentials((c) -> c.add(mapped));
|
||||
}
|
||||
if (credential.isSignatureVerficationCredential()) {
|
||||
this.providerDetails.assertingPartyDetailsBuilder.verificationX509Credentials(c -> c.add(mapped));
|
||||
this.providerDetails.assertingPartyDetailsBuilder.verificationX509Credentials((c) -> c.add(mapped));
|
||||
}
|
||||
if (credential.isEncryptionCredential()) {
|
||||
this.providerDetails.assertingPartyDetailsBuilder.encryptionX509Credentials(c -> c.add(mapped));
|
||||
this.providerDetails.assertingPartyDetailsBuilder.encryptionX509Credentials((c) -> c.add(mapped));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ public final class DefaultRelyingPartyRegistrationResolver
|
||||
}
|
||||
|
||||
private Function<String, String> templateResolver(String applicationUri, RelyingPartyRegistration relyingParty) {
|
||||
return template -> resolveUrlTemplate(template, applicationUri, relyingParty);
|
||||
return (template) -> resolveUrlTemplate(template, applicationUri, relyingParty);
|
||||
}
|
||||
|
||||
private static String resolveUrlTemplate(String template, String baseUrl, RelyingPartyRegistration relyingParty) {
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class OpenSamlInitializationServiceTests {
|
||||
OpenSamlInitializationService.initialize();
|
||||
XMLObjectProviderRegistry registry = ConfigurationService.get(XMLObjectProviderRegistry.class);
|
||||
assertThat(registry.getParserPool()).isNotNull();
|
||||
assertThatCode(() -> OpenSamlInitializationService.requireInitialize(r -> {
|
||||
assertThatCode(() -> OpenSamlInitializationService.requireInitialize((r) -> {
|
||||
})).isInstanceOf(Saml2Exception.class).hasMessageContaining("OpenSAML was already initialized previously");
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -210,7 +210,7 @@ public class OpenSamlAuthenticationProviderTests {
|
||||
Response response = TestOpenSamlObjects.response();
|
||||
Assertion assertion = TestOpenSamlObjects.assertion();
|
||||
assertion.getSubject().getSubjectConfirmations()
|
||||
.forEach(sc -> sc.getSubjectConfirmationData().setAddress("10.10.10.10"));
|
||||
.forEach((sc) -> sc.getSubjectConfirmationData().setAddress("10.10.10.10"));
|
||||
TestOpenSamlObjects.signed(assertion, TestSaml2X509Credentials.assertingPartySigningCredential(),
|
||||
RELYING_PARTY_ENTITY_ID);
|
||||
response.getAssertions().add(assertion);
|
||||
@@ -401,7 +401,7 @@ public class OpenSamlAuthenticationProviderTests {
|
||||
ValidationContext context = mock(ValidationContext.class);
|
||||
given(context.getStaticParameters()).willReturn(parameters);
|
||||
OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
||||
provider.setValidationContextConverter(tuple -> context);
|
||||
provider.setValidationContextConverter((tuple) -> context);
|
||||
Response response = TestOpenSamlObjects.response();
|
||||
Assertion assertion = TestOpenSamlObjects.assertion();
|
||||
response.getAssertions().add(assertion);
|
||||
|
||||
+7
-7
@@ -70,9 +70,9 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
public void setUp() {
|
||||
this.relyingPartyRegistrationBuilder = RelyingPartyRegistration.withRegistrationId("id")
|
||||
.assertionConsumerServiceLocation("template")
|
||||
.providerDetails(c -> c.webSsoUrl("https://destination/sso"))
|
||||
.providerDetails(c -> c.entityId("remote-entity-id")).localEntityIdTemplate("local-entity-id")
|
||||
.credentials(c -> c.add(TestSaml2X509Credentials.relyingPartySigningCredential()));
|
||||
.providerDetails((c) -> c.webSsoUrl("https://destination/sso"))
|
||||
.providerDetails((c) -> c.entityId("remote-entity-id")).localEntityIdTemplate("local-entity-id")
|
||||
.credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartySigningCredential()));
|
||||
this.relyingPartyRegistration = this.relyingPartyRegistrationBuilder.build();
|
||||
this.contextBuilder = Saml2AuthenticationRequestContext.builder().issuer("https://issuer")
|
||||
.relyingPartyRegistration(this.relyingPartyRegistration)
|
||||
@@ -107,7 +107,7 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
this.context = this.contextBuilder.relayState("Relay State Value")
|
||||
.relyingPartyRegistration(
|
||||
RelyingPartyRegistration.withRelyingPartyRegistration(this.relyingPartyRegistration)
|
||||
.providerDetails(c -> c.signAuthNRequest(false)).build())
|
||||
.providerDetails((c) -> c.signAuthNRequest(false)).build())
|
||||
.build();
|
||||
Saml2RedirectAuthenticationRequest result = this.factory.createRedirectAuthenticationRequest(this.context);
|
||||
assertThat(result.getSamlRequest()).isNotEmpty();
|
||||
@@ -122,7 +122,7 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
this.context = this.contextBuilder.relayState("Relay State Value")
|
||||
.relyingPartyRegistration(
|
||||
RelyingPartyRegistration.withRelyingPartyRegistration(this.relyingPartyRegistration)
|
||||
.providerDetails(c -> c.signAuthNRequest(false)).build())
|
||||
.providerDetails((c) -> c.signAuthNRequest(false)).build())
|
||||
.build();
|
||||
Saml2PostAuthenticationRequest result = this.factory.createPostAuthenticationRequest(this.context);
|
||||
assertThat(result.getSamlRequest()).isNotEmpty();
|
||||
@@ -170,7 +170,7 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
public void createPostAuthenticationRequestWhenAuthnRequestConsumerThenUses() {
|
||||
Function<Saml2AuthenticationRequestContext, Consumer<AuthnRequest>> authnRequestConsumerResolver = mock(
|
||||
Function.class);
|
||||
given(authnRequestConsumerResolver.apply(this.context)).willReturn(authnRequest -> {
|
||||
given(authnRequestConsumerResolver.apply(this.context)).willReturn((authnRequest) -> {
|
||||
});
|
||||
this.factory.setAuthnRequestConsumerResolver(authnRequestConsumerResolver);
|
||||
|
||||
@@ -182,7 +182,7 @@ public class OpenSamlAuthenticationRequestFactoryTests {
|
||||
public void createRedirectAuthenticationRequestWhenAuthnRequestConsumerThenUses() {
|
||||
Function<Saml2AuthenticationRequestContext, Consumer<AuthnRequest>> authnRequestConsumerResolver = mock(
|
||||
Function.class);
|
||||
given(authnRequestConsumerResolver.apply(this.context)).willReturn(authnRequest -> {
|
||||
given(authnRequestConsumerResolver.apply(this.context)).willReturn((authnRequest) -> {
|
||||
});
|
||||
this.factory.setAuthnRequestConsumerResolver(authnRequestConsumerResolver);
|
||||
|
||||
|
||||
+5
-5
@@ -32,14 +32,14 @@ public class Saml2AuthenticationRequestFactoryTests {
|
||||
|
||||
private RelyingPartyRegistration registration = RelyingPartyRegistration.withRegistrationId("id")
|
||||
.assertionConsumerServiceUrlTemplate("template")
|
||||
.providerDetails(c -> c.webSsoUrl("https://example.com/destination"))
|
||||
.providerDetails(c -> c.entityId("remote-entity-id")).localEntityIdTemplate("local-entity-id")
|
||||
.credentials(c -> c.add(TestSaml2X509Credentials.relyingPartySigningCredential())).build();
|
||||
.providerDetails((c) -> c.webSsoUrl("https://example.com/destination"))
|
||||
.providerDetails((c) -> c.entityId("remote-entity-id")).localEntityIdTemplate("local-entity-id")
|
||||
.credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartySigningCredential())).build();
|
||||
|
||||
@Test
|
||||
public void createAuthenticationRequestParametersWhenRedirectDefaultIsUsedMessageIsDeflatedAndEncoded() {
|
||||
final String value = "Test String: " + UUID.randomUUID().toString();
|
||||
Saml2AuthenticationRequestFactory factory = request -> value;
|
||||
Saml2AuthenticationRequestFactory factory = (request) -> value;
|
||||
Saml2AuthenticationRequestContext request = Saml2AuthenticationRequestContext.builder()
|
||||
.relyingPartyRegistration(this.registration).issuer("https://example.com/issuer")
|
||||
.assertionConsumerServiceUrl("https://example.com/acs-url").build();
|
||||
@@ -53,7 +53,7 @@ public class Saml2AuthenticationRequestFactoryTests {
|
||||
@Test
|
||||
public void createAuthenticationRequestParametersWhenPostDefaultIsUsedMessageIsEncoded() {
|
||||
final String value = "Test String: " + UUID.randomUUID().toString();
|
||||
Saml2AuthenticationRequestFactory factory = request -> value;
|
||||
Saml2AuthenticationRequestFactory factory = (request) -> value;
|
||||
Saml2AuthenticationRequestContext request = Saml2AuthenticationRequestContext.builder()
|
||||
.relyingPartyRegistration(this.registration).issuer("https://example.com/issuer")
|
||||
.assertionConsumerServiceUrl("https://example.com/acs-url").build();
|
||||
|
||||
+2
-2
@@ -53,8 +53,8 @@ public class OpenSamlMetadataResolverTests {
|
||||
public void resolveWhenRelyingPartyNoCredentialsThenMetadataMatches() {
|
||||
// given
|
||||
RelyingPartyRegistration relyingPartyRegistration = TestRelyingPartyRegistrations.noCredentials()
|
||||
.assertingPartyDetails(party -> party.verificationX509Credentials(
|
||||
c -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())))
|
||||
.assertingPartyDetails((party) -> party.verificationX509Credentials(
|
||||
(c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())))
|
||||
.build();
|
||||
OpenSamlMetadataResolver openSamlMetadataResolver = new OpenSamlMetadataResolver();
|
||||
|
||||
|
||||
+5
-5
@@ -28,8 +28,8 @@ public class RelyingPartyRegistrationTests {
|
||||
@Test
|
||||
public void withRelyingPartyRegistrationWorks() {
|
||||
RelyingPartyRegistration registration = TestRelyingPartyRegistrations.relyingPartyRegistration()
|
||||
.providerDetails(p -> p.binding(Saml2MessageBinding.POST))
|
||||
.providerDetails(p -> p.signAuthNRequest(false))
|
||||
.providerDetails((p) -> p.binding(Saml2MessageBinding.POST))
|
||||
.providerDetails((p) -> p.signAuthNRequest(false))
|
||||
.assertionConsumerServiceBinding(Saml2MessageBinding.REDIRECT).build();
|
||||
RelyingPartyRegistration copy = RelyingPartyRegistration.withRelyingPartyRegistration(registration).build();
|
||||
compareRegistrations(registration, copy);
|
||||
@@ -77,9 +77,9 @@ public class RelyingPartyRegistrationTests {
|
||||
public void buildWhenUsingDefaultsThenAssertionConsumerServiceBindingDefaultsToPost() {
|
||||
RelyingPartyRegistration relyingPartyRegistration = RelyingPartyRegistration.withRegistrationId("id")
|
||||
.entityId("entity-id").assertionConsumerServiceLocation("location")
|
||||
.assertingPartyDetails(
|
||||
assertingParty -> assertingParty.entityId("entity-id").singleSignOnServiceLocation("location"))
|
||||
.credentials(c -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())).build();
|
||||
.assertingPartyDetails((assertingParty) -> assertingParty.entityId("entity-id")
|
||||
.singleSignOnServiceLocation("location"))
|
||||
.credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())).build();
|
||||
|
||||
assertThat(relyingPartyRegistration.getAssertionConsumerServiceBinding()).isEqualTo(Saml2MessageBinding.POST);
|
||||
}
|
||||
|
||||
+8
-8
@@ -42,25 +42,25 @@ public final class TestRelyingPartyRegistrations {
|
||||
|
||||
return RelyingPartyRegistration.withRegistrationId(registrationId).entityId(rpEntityId)
|
||||
.assertionConsumerServiceLocation(assertionConsumerServiceLocation)
|
||||
.credentials(c -> c.add(signingCredential))
|
||||
.providerDetails(c -> c.entityId(apEntityId).webSsoUrl(singleSignOnServiceLocation))
|
||||
.credentials(c -> c.add(verificationCertificate));
|
||||
.credentials((c) -> c.add(signingCredential))
|
||||
.providerDetails((c) -> c.entityId(apEntityId).webSsoUrl(singleSignOnServiceLocation))
|
||||
.credentials((c) -> c.add(verificationCertificate));
|
||||
}
|
||||
|
||||
public static RelyingPartyRegistration.Builder noCredentials() {
|
||||
return RelyingPartyRegistration.withRegistrationId("registration-id").entityId("rp-entity-id")
|
||||
.assertionConsumerServiceLocation("https://rp.example.org/acs").assertingPartyDetails(party -> party
|
||||
.assertionConsumerServiceLocation("https://rp.example.org/acs").assertingPartyDetails((party) -> party
|
||||
.entityId("ap-entity-id").singleSignOnServiceLocation("https://ap.example.org/sso"));
|
||||
}
|
||||
|
||||
public static RelyingPartyRegistration.Builder full() {
|
||||
return noCredentials()
|
||||
.signingX509Credentials(c -> c.add(org.springframework.security.saml2.core.TestSaml2X509Credentials
|
||||
.signingX509Credentials((c) -> c.add(org.springframework.security.saml2.core.TestSaml2X509Credentials
|
||||
.relyingPartySigningCredential()))
|
||||
.decryptionX509Credentials(c -> c.add(org.springframework.security.saml2.core.TestSaml2X509Credentials
|
||||
.decryptionX509Credentials((c) -> c.add(org.springframework.security.saml2.core.TestSaml2X509Credentials
|
||||
.relyingPartyDecryptingCredential()))
|
||||
.assertingPartyDetails(party -> party.verificationX509Credentials(
|
||||
c -> c.add(org.springframework.security.saml2.core.TestSaml2X509Credentials
|
||||
.assertingPartyDetails((party) -> party.verificationX509Credentials(
|
||||
(c) -> c.add(org.springframework.security.saml2.core.TestSaml2X509Credentials
|
||||
.relyingPartyVerifyingCredential())));
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -76,9 +76,9 @@ public class Saml2WebSsoAuthenticationRequestFilterTests {
|
||||
this.filterChain = new MockFilterChain();
|
||||
|
||||
this.rpBuilder = RelyingPartyRegistration.withRegistrationId("registration-id")
|
||||
.providerDetails(c -> c.entityId("idp-entity-id")).providerDetails(c -> c.webSsoUrl(IDP_SSO_URL))
|
||||
.providerDetails((c) -> c.entityId("idp-entity-id")).providerDetails((c) -> c.webSsoUrl(IDP_SSO_URL))
|
||||
.assertionConsumerServiceUrlTemplate("template")
|
||||
.credentials(c -> c.add(TestSaml2X509Credentials.assertingPartyPrivateCredential()));
|
||||
.credentials((c) -> c.add(TestSaml2X509Credentials.assertingPartyPrivateCredential()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,7 +121,7 @@ public class Saml2WebSsoAuthenticationRequestFilterTests {
|
||||
@Test
|
||||
public void doFilterWhenSignatureIsDisabledThenSignatureParametersAreNotInTheRedirectURL() throws Exception {
|
||||
given(this.repository.findByRegistrationId("registration-id"))
|
||||
.willReturn(this.rpBuilder.providerDetails(c -> c.signAuthNRequest(false)).build());
|
||||
.willReturn(this.rpBuilder.providerDetails((c) -> c.signAuthNRequest(false)).build());
|
||||
final String relayStateValue = "https://my-relay-state.example.com?with=param&other=param";
|
||||
final String relayStateEncoded = UriUtils.encode(relayStateValue, StandardCharsets.ISO_8859_1);
|
||||
this.request.setParameter("RelayState", relayStateValue);
|
||||
@@ -133,7 +133,7 @@ public class Saml2WebSsoAuthenticationRequestFilterTests {
|
||||
@Test
|
||||
public void doFilterWhenPostFormDataIsPresent() throws Exception {
|
||||
given(this.repository.findByRegistrationId("registration-id"))
|
||||
.willReturn(this.rpBuilder.providerDetails(c -> c.binding(Saml2MessageBinding.POST)).build());
|
||||
.willReturn(this.rpBuilder.providerDetails((c) -> c.binding(Saml2MessageBinding.POST)).build());
|
||||
final String relayStateValue = "https://my-relay-state.example.com?with=param&other=param&javascript{alert('1');}";
|
||||
final String relayStateEncoded = HtmlUtils.htmlEscape(relayStateValue);
|
||||
this.request.setParameter("RelayState", relayStateValue);
|
||||
@@ -147,8 +147,8 @@ public class Saml2WebSsoAuthenticationRequestFilterTests {
|
||||
|
||||
@Test
|
||||
public void doFilterWhenSetAuthenticationRequestFactoryThenUses() throws Exception {
|
||||
RelyingPartyRegistration relyingParty = this.rpBuilder.providerDetails(c -> c.binding(Saml2MessageBinding.POST))
|
||||
.build();
|
||||
RelyingPartyRegistration relyingParty = this.rpBuilder
|
||||
.providerDetails((c) -> c.binding(Saml2MessageBinding.POST)).build();
|
||||
Saml2PostAuthenticationRequest authenticationRequest = mock(Saml2PostAuthenticationRequest.class);
|
||||
given(authenticationRequest.getAuthenticationRequestUri()).willReturn("uri");
|
||||
given(authenticationRequest.getRelayState()).willReturn("relay");
|
||||
@@ -167,8 +167,8 @@ public class Saml2WebSsoAuthenticationRequestFilterTests {
|
||||
|
||||
@Test
|
||||
public void doFilterWhenCustomAuthenticationRequestFactoryThenUses() throws Exception {
|
||||
RelyingPartyRegistration relyingParty = this.rpBuilder.providerDetails(c -> c.binding(Saml2MessageBinding.POST))
|
||||
.build();
|
||||
RelyingPartyRegistration relyingParty = this.rpBuilder
|
||||
.providerDetails((c) -> c.binding(Saml2MessageBinding.POST)).build();
|
||||
Saml2PostAuthenticationRequest authenticationRequest = mock(Saml2PostAuthenticationRequest.class);
|
||||
given(authenticationRequest.getAuthenticationRequestUri()).willReturn("uri");
|
||||
given(authenticationRequest.getRelayState()).willReturn("relay");
|
||||
@@ -201,7 +201,7 @@ public class Saml2WebSsoAuthenticationRequestFilterTests {
|
||||
@Test
|
||||
public void doFilterWhenRequestMatcherFailsThenSkipsFilter() throws Exception {
|
||||
Saml2WebSsoAuthenticationRequestFilter filter = new Saml2WebSsoAuthenticationRequestFilter(this.repository);
|
||||
filter.setRedirectMatcher(request -> false);
|
||||
filter.setRedirectMatcher((request) -> false);
|
||||
filter.doFilter(this.request, this.response, this.filterChain);
|
||||
verifyNoInteractions(this.repository);
|
||||
}
|
||||
|
||||
+4
-4
@@ -50,7 +50,7 @@ public class DefaultSaml2AuthenticationRequestContextResolverTests {
|
||||
private RelyingPartyRegistration.Builder relyingPartyBuilder;
|
||||
|
||||
private Saml2AuthenticationRequestContextResolver authenticationRequestContextResolver = new DefaultSaml2AuthenticationRequestContextResolver(
|
||||
new DefaultRelyingPartyRegistrationResolver(id -> this.relyingPartyBuilder.build()));
|
||||
new DefaultRelyingPartyRegistrationResolver((id) -> this.relyingPartyBuilder.build()));
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -58,10 +58,10 @@ public class DefaultSaml2AuthenticationRequestContextResolverTests {
|
||||
this.request.setPathInfo("/saml2/authenticate/registration-id");
|
||||
this.relyingPartyBuilder = RelyingPartyRegistration.withRegistrationId(REGISTRATION_ID)
|
||||
.localEntityIdTemplate(RELYING_PARTY_ENTITY_ID)
|
||||
.providerDetails(c -> c.entityId(ASSERTING_PARTY_ENTITY_ID))
|
||||
.providerDetails(c -> c.webSsoUrl(ASSERTING_PARTY_SSO_URL))
|
||||
.providerDetails((c) -> c.entityId(ASSERTING_PARTY_ENTITY_ID))
|
||||
.providerDetails((c) -> c.webSsoUrl(ASSERTING_PARTY_SSO_URL))
|
||||
.assertionConsumerServiceUrlTemplate(RELYING_PARTY_SSO_URL)
|
||||
.credentials(c -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential()));
|
||||
.credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-3
@@ -109,14 +109,14 @@ public class Saml2MetadataFilterTests {
|
||||
// given
|
||||
this.request.setPathInfo("/saml2/service-provider-metadata/validRegistration");
|
||||
RelyingPartyRegistration validRegistration = TestRelyingPartyRegistrations.noCredentials()
|
||||
.assertingPartyDetails(party -> party.verificationX509Credentials(
|
||||
c -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())))
|
||||
.assertingPartyDetails((party) -> party.verificationX509Credentials(
|
||||
(c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())))
|
||||
.build();
|
||||
|
||||
String generatedMetadata = "<xml>test</xml>";
|
||||
given(this.resolver.resolve(validRegistration)).willReturn(generatedMetadata);
|
||||
|
||||
this.filter = new Saml2MetadataFilter(request -> validRegistration, this.resolver);
|
||||
this.filter = new Saml2MetadataFilter((request) -> validRegistration, this.resolver);
|
||||
|
||||
// when
|
||||
this.filter.doFilter(this.request, this.response, this.chain);
|
||||
|
||||
Reference in New Issue
Block a user