Skip to content

File-based Configuration for Asserting Party Metadata #9028

Closed
@ryan13mt

Description

@ryan13mt

Expected Behavior

String metadataLocation = "C:\\local\\temp\\saml\\meta.xml";

RelyingPartyRegistration registration = RelyingPartyRegistrations.fromMetadataLocation(metadataLocation)
 .registrationId("registration-id").build();

Current Behavior

String metadataLocation = "https://testAssertingParty.com/meta.xml";

RelyingPartyRegistration registration = RelyingPartyRegistrations.fromMetadataLocation(metadataLocation)
 .registrationId("registration-id")
.build();

Context

Currently the RelyingPartyRegistrations.fromMetadataLocation(metadataLocation) only accepts a URL. Basing on my old implementation with Spring Security SAML Extension it would be good if we could also provide a local directory path to this method. Some asserting parties will not host their metadata files but will instead email it to the relying party.

Suggested Solution

The OpenSamlRelyingPartyRegistrationBuilderHttpMessageConverter class introduced in 5.4 can still be used but the parsing logic should be extracted into a separate utility class that can be used elsewhere.

An example of the changes needed in RelyingPartyRegistrations.fromMetadataLocation(metadataLocation):

public static RelyingPartyRegistration.Builder fromMetadataLocation(String metadataLocation) {
	try {
		if (metadataLocation.matches("^(https?)://.*$")) {
			RestOperations rest = new RestTemplate(Arrays.asList(new OpenSamlRelyingPartyRegistrationBuilderHttpMessageConverter()));
			return rest.getForObject(metadataLocation, RelyingPartyRegistration.Builder.class);
		} else {
			OpenSamlRelyingPartyRegistrationBuilderConverter converter = new OpenSamlRelyingPartyRegistrationBuilderConverter();
			return converter.read(RelyingPartyRegistration.Builder.class, new FileInputStream(metadataLocation));
		}
	}
	catch (RestClientException | FileNotFoundException ex) {
		if (ex.getCause() instanceof Saml2Exception) {
			throw (Saml2Exception) ex.getCause();
		}
		throw new Saml2Exception(ex);
	}
}

This way if the metadataLocation is a url, it will use the OpenSamlRelyingPartyRegistrationBuilderHttpMessageConverter, if not, it will use the Utility class that holds the parsing code which in my example is named OpenSamlRelyingPartyRegistrationBuilderConverter.

Obviously my code can be greatly improved upon but this change should be an easy one since most of the logic and tests regarding the parsing is already there.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions