Skip to content

Generic type information provided by ResourceKeyConverterAdapter is insufficient for conversion service registration #9626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wilkinsona opened this issue Apr 12, 2021 · 0 comments
Assignees
Labels
in: core An issue in spring-security-core type: bug A general bug

Comments

@wilkinsona
Copy link
Member

Describe the bug

When a ResourceKeyConverterAdapter is registered with the conversion service, it's registered as a String -> java.security.Key converter as the adapter's type constraint is T extends Key. This means that the conversion service is incapable of a String to RSAPublicKey or RSAPrivateKey conversion.

To Reproduce

The following test will reproduce the problem:

@Test
void whenX509ConverterIsRegisteredWithConversionServiceThenConversionToRSAPublicKeyIsPossible() {
    GenericConversionService conversionService = new GenericConversionService();
    conversionService.addConverter(new ResourceKeyConverterAdapter<>(RsaKeyConverters.x509()));
    assertThat(conversionService.canConvert(String.class, RSAPublicKey.class)).isTrue();
}

Expected behavior
The above test should pass. A workaround is to sub-class ResourceKeyConverterAdapter to provide additional type information:

@Test
void whenX509ConverterIsRegisteredWithConversionServiceUsingSubclassedAdapterThenConversionToRSAPublicKeyIsPossible() {
    GenericConversionService conversionService = new GenericConversionService();
    conversionService.addConverter(new ResourceKeyConverterAdapter<RSAPublicKey>(RsaKeyConverters.x509()) {
    });
    assertThat(conversionService.canConvert(String.class, RSAPublicKey.class)).isTrue();
}

Sample

See above.

@wilkinsona wilkinsona added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Apr 12, 2021
@jzheaux jzheaux self-assigned this Apr 16, 2021
@jzheaux jzheaux added in: core An issue in spring-security-core and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 16, 2021
jzheaux added a commit to jzheaux/spring-security that referenced this issue Apr 21, 2021
akohli96 pushed a commit to akohli96/spring-security that referenced this issue Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core An issue in spring-security-core type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants