Add IterableRelyingPartyRegistrationRepository

Closes gh-15027
This commit is contained in:
Josh Cummings 2024-07-01 17:20:35 -06:00
parent 850c0a4690
commit 1e2900328b
No known key found for this signature in database
GPG Key ID: A306A51F43B8E5A5
3 changed files with 37 additions and 3 deletions

View File

@ -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<RelyingPartyRegistration> {
public class InMemoryRelyingPartyRegistrationRepository implements IterableRelyingPartyRegistrationRepository {
private final Map<String, RelyingPartyRegistration> byRegistrationId;

View File

@ -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<RelyingPartyRegistration> {
}

View File

@ -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<RelyingPartyRegistration> registrations = (Iterable<RelyingPartyRegistration>) this.registrations;
return responseByIterable(request, registrations);