From 1e2900328b05b6164d29aa1148096cf7a651a3db Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Mon, 1 Jul 2024 17:20:35 -0600 Subject: [PATCH] Add IterableRelyingPartyRegistrationRepository Closes gh-15027 --- ...oryRelyingPartyRegistrationRepository.java | 5 ++- ...bleRelyingPartyRegistrationRepository.java | 31 +++++++++++++++++++ ...equestMatcherMetadataResponseResolver.java | 4 +++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/registration/IterableRelyingPartyRegistrationRepository.java diff --git a/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/registration/InMemoryRelyingPartyRegistrationRepository.java b/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/registration/InMemoryRelyingPartyRegistrationRepository.java index 738f00952f..01f4778027 100644 --- a/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/registration/InMemoryRelyingPartyRegistrationRepository.java +++ b/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/registration/InMemoryRelyingPartyRegistrationRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,7 @@ import org.springframework.util.MultiValueMap; * @author Josh Cummings * @since 5.2 */ -public class InMemoryRelyingPartyRegistrationRepository - implements RelyingPartyRegistrationRepository, Iterable { +public class InMemoryRelyingPartyRegistrationRepository implements IterableRelyingPartyRegistrationRepository { private final Map byRegistrationId; diff --git a/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/registration/IterableRelyingPartyRegistrationRepository.java b/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/registration/IterableRelyingPartyRegistrationRepository.java new file mode 100644 index 0000000000..c41261f6a1 --- /dev/null +++ b/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/registration/IterableRelyingPartyRegistrationRepository.java @@ -0,0 +1,31 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.security.saml2.provider.service.registration; + +/** + * An interface that simplifies APIs which require the + * {@link RelyingPartyRegistrationRepository} to also be {@link Iterable} + * + * @author Josh Cummings + * @since 6.4 + * @see InMemoryRelyingPartyRegistrationRepository + * @see CachingRelyingPartyRegistrationRepository + */ +public interface IterableRelyingPartyRegistrationRepository + extends RelyingPartyRegistrationRepository, Iterable { + +} diff --git a/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/metadata/RequestMatcherMetadataResponseResolver.java b/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/metadata/RequestMatcherMetadataResponseResolver.java index 96850d3661..79dcb34dcc 100644 --- a/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/metadata/RequestMatcherMetadataResponseResolver.java +++ b/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/metadata/RequestMatcherMetadataResponseResolver.java @@ -30,6 +30,7 @@ import org.springframework.security.saml2.Saml2Exception; import org.springframework.security.saml2.provider.service.metadata.Saml2MetadataResolver; import org.springframework.security.saml2.provider.service.metadata.Saml2MetadataResponse; import org.springframework.security.saml2.provider.service.metadata.Saml2MetadataResponseResolver; +import org.springframework.security.saml2.provider.service.registration.IterableRelyingPartyRegistrationRepository; import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration; import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository; import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationPlaceholderResolvers; @@ -105,6 +106,9 @@ public class RequestMatcherMetadataResponseResolver implements Saml2MetadataResp if (response != null) { return response; } + if (this.registrations instanceof IterableRelyingPartyRegistrationRepository iterable) { + return responseByIterable(request, iterable); + } if (this.registrations instanceof Iterable) { Iterable registrations = (Iterable) this.registrations; return responseByIterable(request, registrations);