spring-security icon indicating copy to clipboard operation
spring-security copied to clipboard

Make OpenSamlMetadataRelyingPartyRegistrationConverter public

Open OrangeDog opened this issue 1 year ago • 2 comments

Expected Behavior

Class and its methods should be public.

Current Behavior

Class and its methods are package-private.

Context

To allow writing alternatives to RelyingPartyRegistrations and others by adapting OpenSAML APIs. For example, in order to implement verification (https://github.com/spring-projects/spring-security/issues/15018#issuecomment-2110477455) and refreshing (https://github.com/spring-projects/spring-security/issues/15027#issuecomment-2100971114).

OrangeDog avatar May 17 '24 15:05 OrangeDog

I believe this will be addressed in #12116. I'll leave this ticket open for the moment just in case the other evolves differently than I imagine.

jzheaux avatar May 31 '24 16:05 jzheaux

Workaround:

try {
    Class<?> converterClass = Class.forName("org.springframework.security.saml2.provider.service.registration.OpenSamlMetadataRelyingPartyRegistrationConverter");
    Constructor<?> converterConstructor = converterClass.getDeclaredConstructor();
    converterConstructor.setAccessible(true);
    Object converterInstance = converterConstructor.newInstance();
    Method converterMethod = converterClass.getDeclaredMethod("convert", EntityDescriptor.class);
    converterMethod.setAccessible(true);
    this.converter = value -> {
        try {
            return (RelyingPartyRegistration.Builder) converterMethod.invoke(converterInstance, value);
        } catch (InvocationTargetException ex) {
            if (ex.getTargetException() instanceof RuntimeException cause) {
                throw cause;
            } else {
                throw new RuntimeException("Cannot convert metadata", ex);
            }
        } catch (IllegalAccessException ex) {
            throw new IllegalStateException("Cannot convert metadata", ex);
        }
    };
}
catch (ReflectiveOperationException ex) {
    throw new IllegalStateException("Cannot initialise metadata converter", ex);
}

OrangeDog avatar Jul 03 '24 05:07 OrangeDog