Browse Source

Add IterableRelyingPartyRegistrationRepository

Closes gh-15027
Josh Cummings 1 năm trước cách đây
mục cha
commit
1e2900328b

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

+ 31 - 0
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<RelyingPartyRegistration> {
+
+}

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