Skip to content

Commit

Permalink
Remove Unneeded OpenSAML 4 References
Browse files Browse the repository at this point in the history
This will reduce the number of components that need to be
duplicated between the OpenSAML 4 and 5 support

Issue spring-projectsgh-11658
  • Loading branch information
jzheaux committed Aug 7, 2024
1 parent ab842b7 commit 54a4792
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.util.List;
import java.util.function.Consumer;

import org.opensaml.xmlsec.signature.support.SignatureConstants;

import org.springframework.security.saml2.core.Saml2X509Credential;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -838,7 +836,7 @@ public Builder singleLogoutServiceBinding(Saml2MessageBinding singleLogoutServic
*/
public AssertingPartyDetails build() {
List<String> signingAlgorithms = this.signingAlgorithms.isEmpty()
? Collections.singletonList(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256)
? Collections.singletonList("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
: Collections.unmodifiableList(this.signingAlgorithms);

return new AssertingPartyDetails(this.entityId, this.wantAuthnRequestsSigned, signingAlgorithms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.jupiter.api.Test;
import org.opensaml.core.config.ConfigurationService;
import org.opensaml.core.xml.config.XMLObjectProviderRegistry;
import org.opensaml.saml.saml2.core.AuthnRequest;

import org.springframework.security.saml2.Saml2Exception;

Expand All @@ -36,7 +37,7 @@ public class OpenSamlInitializationServiceTests {
public void initializeWhenInvokedMultipleTimesThenInitializesOnce() {
OpenSamlInitializationService.initialize();
XMLObjectProviderRegistry registry = ConfigurationService.get(XMLObjectProviderRegistry.class);
assertThat(registry.getParserPool()).isNotNull();
assertThat(registry.getBuilderFactory().getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME)).isNotNull();
assertThatExceptionOfType(Saml2Exception.class)
.isThrownBy(() -> OpenSamlInitializationService.requireInitialize((r) -> {
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.security.KeyException;
import java.security.PrivateKey;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

import org.opensaml.security.crypto.KeySupport;

import org.springframework.security.converter.RsaKeyConverters;
import org.springframework.security.saml2.Saml2Exception;
import org.springframework.security.saml2.core.Saml2X509Credential.Saml2X509CredentialType;

Expand Down Expand Up @@ -84,12 +82,7 @@ private static X509Certificate certificate(String cert) {
}

private static PrivateKey privateKey(String key) {
try {
return KeySupport.decodePrivateKey(key.getBytes(StandardCharsets.UTF_8), new char[0]);
}
catch (KeyException ex) {
throw new Saml2Exception(ex);
}
return RsaKeyConverters.pkcs8().convert(new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)));
}

private static X509Certificate idpCertificate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.security.KeyException;
import java.security.PrivateKey;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

import org.opensaml.security.crypto.KeySupport;

import org.springframework.security.converter.RsaKeyConverters;
import org.springframework.security.saml2.Saml2Exception;
import org.springframework.security.saml2.core.Saml2X509Credential;

Expand Down Expand Up @@ -74,12 +72,7 @@ private static X509Certificate certificate(String cert) {
}

private static PrivateKey privateKey(String key) {
try {
return KeySupport.decodePrivateKey(key.getBytes(StandardCharsets.UTF_8), new char[0]);
}
catch (KeyException ex) {
throw new Saml2Exception(ex);
}
return RsaKeyConverters.pkcs8().convert(new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)));
}

private static X509Certificate idpCertificate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ public CustomSamlObjectUnmarshaller() {
protected void processChildElement(@Nonnull XMLObject parentXMLObject, @Nonnull XMLObject childXMLObject)
throws UnmarshallingException {
final CustomOpenSamlObject customSamlObject = (CustomOpenSamlObject) parentXMLObject;
super.processChildElement(customSamlObject, childXMLObject);
customSamlObject.getUnknownXMLObjects().add(childXMLObject);
}

Expand Down

0 comments on commit 54a4792

Please sign in to comment.