Skip to content

RuntimeHintsUtils#registerAnnotation does not consider AliasFor in meta-annotation #28702

@marcusdacoregio

Description

@marcusdacoregio

The @EnableGlobalAuthentication in Spring Security uses @Configuration as a meta-annotation, which in turn uses @AliasFor. When using RuntimeHintsUtils.registerAnnotation(hints, EnableGlobalAuthentication.class) it does not work because the util method only considers @AliasFor inside the EnableGlobalAuthentication class, ignoring what is in the @Configuration, therefore leading to an error like this:

Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication, interface org.springframework.core.annotation.SynthesizedAnnotation] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=<comma-separated-config-files> and -H:DynamicProxyConfigurationResources=<comma-separated-config-resources> options.

If done manually, like so, it works:

hints.reflection().registerType(EnableGlobalAuthentication.class, RuntimeHintsUtils.ANNOTATION_HINT);
hints.proxies().registerJdkProxy(EnableGlobalAuthentication.class, SynthesizedAnnotation.class);

To simulate:
Change the security sample this way:

  1. Create this class:
class CoreSecurityHints implements RuntimeHintsRegistrar {

	private static final Consumer<TypeHint.Builder> HINT = builder -> builder.withMembers(
			MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);

	@Override
	public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
		registerDefaultAuthenticationEventPublisherTypes(hints);
		// hints.reflection().registerType(EnableGlobalAuthentication.class, RuntimeHintsUtils.ANNOTATION_HINT); it works if done this way
		// hints.proxies().registerJdkProxy(EnableGlobalAuthentication.class, SynthesizedAnnotation.class);
                 RuntimeHintsUtils.registerAnnotation(hints, EnableGlobalAuthentication.class);
	}

	private void registerDefaultAuthenticationEventPublisherTypes(RuntimeHints hints) {
		hints.reflection().registerType(AuthenticationFailureBadCredentialsEvent.class, HINT)
				.registerType(AuthenticationFailureCredentialsExpiredEvent.class, HINT)
				.registerType(AuthenticationFailureDisabledEvent.class, HINT)
				.registerType(AuthenticationFailureExpiredEvent.class, HINT)
				.registerType(AuthenticationFailureLockedEvent.class, HINT)
				.registerType(AuthenticationFailureProviderNotFoundEvent.class, HINT)
				.registerType(AuthenticationFailureProxyUntrustedEvent.class, HINT)
				.registerType(AuthenticationFailureServiceExceptionEvent.class, HINT)
				.registerType(AuthenticationServiceException.class, HINT)
				.registerType(AccountExpiredException.class, HINT)
				.registerType(BadCredentialsException.class, HINT)
				.registerType(CredentialsExpiredException.class, HINT)
				.registerType(DisabledException.class, HINT)
				.registerType(LockedException.class, HINT)
				.registerType(UsernameNotFoundException.class, HINT)
				.registerType(ProviderNotFoundException.class, HINT);
	}

}
  1. Add @ImportRuntimeHints(CoreSecurityHints.class) in the SecuringWebApplication class
  2. Run the build.sh script

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: supersededAn issue that has been superseded by anothertheme: aotAn issue related to Ahead-of-time processing

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions