Skip to content

Commit 1e29003

Browse files
committed
Add IterableRelyingPartyRegistrationRepository
Closes gh-15027
1 parent 850c0a4 commit 1e29003

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/registration/InMemoryRelyingPartyRegistrationRepository.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,8 +36,7 @@
3636
* @author Josh Cummings
3737
* @since 5.2
3838
*/
39-
public class InMemoryRelyingPartyRegistrationRepository
40-
implements RelyingPartyRegistrationRepository, Iterable<RelyingPartyRegistration> {
39+
public class InMemoryRelyingPartyRegistrationRepository implements IterableRelyingPartyRegistrationRepository {
4140

4241
private final Map<String, RelyingPartyRegistration> byRegistrationId;
4342

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.saml2.provider.service.registration;
18+
19+
/**
20+
* An interface that simplifies APIs which require the
21+
* {@link RelyingPartyRegistrationRepository} to also be {@link Iterable}
22+
*
23+
* @author Josh Cummings
24+
* @since 6.4
25+
* @see InMemoryRelyingPartyRegistrationRepository
26+
* @see CachingRelyingPartyRegistrationRepository
27+
*/
28+
public interface IterableRelyingPartyRegistrationRepository
29+
extends RelyingPartyRegistrationRepository, Iterable<RelyingPartyRegistration> {
30+
31+
}

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/metadata/RequestMatcherMetadataResponseResolver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.security.saml2.provider.service.metadata.Saml2MetadataResolver;
3131
import org.springframework.security.saml2.provider.service.metadata.Saml2MetadataResponse;
3232
import org.springframework.security.saml2.provider.service.metadata.Saml2MetadataResponseResolver;
33+
import org.springframework.security.saml2.provider.service.registration.IterableRelyingPartyRegistrationRepository;
3334
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
3435
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
3536
import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationPlaceholderResolvers;
@@ -105,6 +106,9 @@ public Saml2MetadataResponse resolve(HttpServletRequest request) {
105106
if (response != null) {
106107
return response;
107108
}
109+
if (this.registrations instanceof IterableRelyingPartyRegistrationRepository iterable) {
110+
return responseByIterable(request, iterable);
111+
}
108112
if (this.registrations instanceof Iterable<?>) {
109113
Iterable<RelyingPartyRegistration> registrations = (Iterable<RelyingPartyRegistration>) this.registrations;
110114
return responseByIterable(request, registrations);

0 commit comments

Comments
 (0)