Remove OpenSamlRelyingPartyRegistration

Issue gh-17309

Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
This commit is contained in:
Tran Ngoc Nhan 2025-06-25 01:50:51 +07:00 committed by Josh Cummings
parent 8c100c5c27
commit a9e28a2ae9
3 changed files with 3 additions and 182 deletions

View File

@ -1,178 +0,0 @@
/*
* Copyright 2002-2025 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;
import java.util.Collection;
import java.util.function.Consumer;
import org.opensaml.saml.saml2.metadata.EntityDescriptor;
import org.springframework.security.saml2.core.Saml2X509Credential;
/**
* An OpenSAML implementation of {@link RelyingPartyRegistration} that contains OpenSAML
* objects like {@link EntityDescriptor}.
*
* @author Josh Cummings
* @since 6.1
* @deprecated This class no longer is needed in order to transmit the
* {@link EntityDescriptor} to {@link OpenSamlAssertingPartyDetails}. Instead of doing:
* <pre>
* if (registration instanceof OpenSamlRelyingPartyRegistration openSamlRegistration) {
* EntityDescriptor descriptor = openSamlRegistration.getAssertingPartyDetails.getEntityDescriptor();
* }
* </pre> do instead: <pre>
* if (registration.getAssertingPartyMetadata() instanceof openSamlAssertingPartyDetails) {
* EntityDescriptor descriptor = openSamlAssertingPartyDetails.getEntityDescriptor();
* }
* </pre>
*/
@Deprecated
public final class OpenSamlRelyingPartyRegistration extends RelyingPartyRegistration {
OpenSamlRelyingPartyRegistration(RelyingPartyRegistration registration) {
super(registration.getRegistrationId(), registration.getEntityId(),
registration.getAssertionConsumerServiceLocation(), registration.getAssertionConsumerServiceBinding(),
registration.getSingleLogoutServiceLocation(), registration.getSingleLogoutServiceResponseLocation(),
registration.getSingleLogoutServiceBindings(),
(OpenSamlAssertingPartyDetails) registration.getAssertingPartyMetadata(),
registration.getNameIdFormat(), registration.isAuthnRequestsSigned(),
registration.getDecryptionX509Credentials(), registration.getSigningX509Credentials());
}
/**
* {@inheritDoc}
*/
@Override
public OpenSamlRelyingPartyRegistration.Builder mutate() {
OpenSamlAssertingPartyDetails party = (OpenSamlAssertingPartyDetails) getAssertingPartyMetadata();
return new Builder(party).registrationId(getRegistrationId())
.entityId(getEntityId())
.signingX509Credentials((c) -> c.addAll(getSigningX509Credentials()))
.decryptionX509Credentials((c) -> c.addAll(getDecryptionX509Credentials()))
.assertionConsumerServiceLocation(getAssertionConsumerServiceLocation())
.assertionConsumerServiceBinding(getAssertionConsumerServiceBinding())
.singleLogoutServiceLocation(getSingleLogoutServiceLocation())
.singleLogoutServiceResponseLocation(getSingleLogoutServiceResponseLocation())
.singleLogoutServiceBindings((c) -> c.addAll(getSingleLogoutServiceBindings()))
.nameIdFormat(getNameIdFormat())
.authnRequestsSigned(isAuthnRequestsSigned());
}
/**
* Create a {@link Builder} from an entity descriptor
* @param entityDescriptor the asserting party's {@link EntityDescriptor}
* @return an {@link Builder}
*/
public static OpenSamlRelyingPartyRegistration.Builder withAssertingPartyEntityDescriptor(
EntityDescriptor entityDescriptor) {
return new Builder(entityDescriptor);
}
/**
* An OpenSAML version of
* {@link org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.AssertingPartyDetails.Builder}
* that contains the underlying {@link EntityDescriptor}
*/
public static final class Builder extends RelyingPartyRegistration.Builder {
private Builder(EntityDescriptor entityDescriptor) {
super(entityDescriptor.getEntityID(), OpenSamlAssertingPartyDetails.withEntityDescriptor(entityDescriptor));
}
Builder(OpenSamlAssertingPartyDetails details) {
super(details.getEntityDescriptor().getEntityID(), details.mutate());
}
@Override
public Builder registrationId(String id) {
return (Builder) super.registrationId(id);
}
public Builder entityId(String entityId) {
return (Builder) super.entityId(entityId);
}
public Builder signingX509Credentials(Consumer<Collection<Saml2X509Credential>> credentialsConsumer) {
return (Builder) super.signingX509Credentials(credentialsConsumer);
}
@Override
public Builder decryptionX509Credentials(Consumer<Collection<Saml2X509Credential>> credentialsConsumer) {
return (Builder) super.decryptionX509Credentials(credentialsConsumer);
}
@Override
public Builder assertionConsumerServiceLocation(String assertionConsumerServiceLocation) {
return (Builder) super.assertionConsumerServiceLocation(assertionConsumerServiceLocation);
}
@Override
public Builder assertionConsumerServiceBinding(Saml2MessageBinding assertionConsumerServiceBinding) {
return (Builder) super.assertionConsumerServiceBinding(assertionConsumerServiceBinding);
}
@Override
public Builder singleLogoutServiceBinding(Saml2MessageBinding singleLogoutServiceBinding) {
return singleLogoutServiceBindings((saml2MessageBindings) -> {
saml2MessageBindings.clear();
saml2MessageBindings.add(singleLogoutServiceBinding);
});
}
@Override
public Builder singleLogoutServiceBindings(Consumer<Collection<Saml2MessageBinding>> bindingsConsumer) {
return (Builder) super.singleLogoutServiceBindings(bindingsConsumer);
}
@Override
public Builder singleLogoutServiceLocation(String singleLogoutServiceLocation) {
return (Builder) super.singleLogoutServiceLocation(singleLogoutServiceLocation);
}
public Builder singleLogoutServiceResponseLocation(String singleLogoutServiceResponseLocation) {
return (Builder) super.singleLogoutServiceResponseLocation(singleLogoutServiceResponseLocation);
}
@Override
public Builder nameIdFormat(String nameIdFormat) {
return (Builder) super.nameIdFormat(nameIdFormat);
}
@Override
public Builder authnRequestsSigned(Boolean authnRequestsSigned) {
return (Builder) super.authnRequestsSigned(authnRequestsSigned);
}
@Override
public Builder assertingPartyMetadata(Consumer<AssertingPartyMetadata.Builder<?>> assertingPartyMetadata) {
return (Builder) super.assertingPartyMetadata(assertingPartyMetadata);
}
/**
* Build an {@link OpenSamlRelyingPartyRegistration}
* {@link org.springframework.security.saml2.provider.service.registration.OpenSamlRelyingPartyRegistration}
* @return an {@link OpenSamlRelyingPartyRegistration}
*/
@Override
public OpenSamlRelyingPartyRegistration build() {
return new OpenSamlRelyingPartyRegistration(super.build());
}
}
}

View File

@ -221,7 +221,7 @@ public final class RelyingPartyRegistrations {
OpenSamlAssertingPartyDetails assertingParty = OpenSamlAssertingPartyDetails
.withEntityDescriptor(descriptor)
.build();
builders.add(new OpenSamlRelyingPartyRegistration.Builder(assertingParty));
builders.add(RelyingPartyRegistration.withAssertingPartyMetadata(assertingParty));
}
}
if (builders.isEmpty()) {

View File

@ -253,8 +253,7 @@ public class RelyingPartyRegistrationsTests {
}
@Test
public void fromMetadataLocationWhenResolvableThenUsesEntityIdAndOpenSamlRelyingPartyRegistration()
throws Exception {
public void fromMetadataLocationWhenResolvableThenUsesEntityIdAndOpenSamlAssertingPartyDetails() throws Exception {
try (MockWebServer server = new MockWebServer()) {
server.enqueue(new MockResponse().setBody(this.metadata).setResponseCode(200));
RelyingPartyRegistration registration = RelyingPartyRegistrations
@ -263,7 +262,7 @@ public class RelyingPartyRegistrationsTests {
.build();
AssertingPartyMetadata details = registration.getAssertingPartyMetadata();
assertThat(registration.getRegistrationId()).isEqualTo(details.getEntityId());
assertThat(registration).isInstanceOf(OpenSamlRelyingPartyRegistration.class);
assertThat(details).isInstanceOf(OpenSamlAssertingPartyDetails.class);
}
}