Skip to content

Jackson2 AOT contribution not registered when extending JdbcOAuth2AuthorizationService #1737

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
billkoch opened this issue Oct 15, 2024 · 4 comments
Assignees
Labels
status: duplicate A duplicate of another issue type: bug A general bug

Comments

@billkoch
Copy link
Contributor

billkoch commented Oct 15, 2024

Expected Behavior
When extending the JdbcOAuth2AuthorizationService or JdbcRegisteredClientRepository, the Jackson2ConfigurationBeanRegistrationAotContribution should be registered.

Current Behavior
The Jackson2ConfigurationBeanRegistrationAotContribution is not registered as an AOT contribution.

Context
This is due to the OAuth2AuthorizationServerBeanRegistrationAotProcessor checking for the relevant classes by the String class name (i.e. "org.springframework.security.oauth2.server.authorization.JdbcOAuth2AuthorizationService" and "org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository").

My current workaround is to provide my own BeanRegistrationAotProcessor implementation that JdbcOAuth2AuthorizationService and JdbcRegisteredClientRepository are assignable from registeredBean.getBeanClass(), and then use reflection to instantiate the package-private Jackson2ConfigurationBeanRegistrationAotContribution:

@Override
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
    boolean isJdbcBasedOAuth2AuthorizationService =
        JdbcOAuth2AuthorizationService.class.isAssignableFrom(registeredBean.getBeanClass());

    boolean isJdbcBasedRegisteredClientRepository =
        JdbcRegisteredClientRepository.class.isAssignableFrom(registeredBean.getBeanClass());

    BeanRegistrationAotContribution contribution = null;
    if ((isJdbcBasedOAuth2AuthorizationService || isJdbcBasedRegisteredClientRepository)
        && !this.jackson2Contributed) {

    this.jackson2Contributed = true;
    contribution = createJackson2ConfigurationBeanRegistrationAotContribution();
    }
    return contribution;
}

Is there a reason to use String-based class references over Class references?

@billkoch billkoch added the type: enhancement A general enhancement label Oct 15, 2024
@billkoch
Copy link
Contributor Author

I would be happy to work on a pull request if my proposed changes make sense.

@jgrandja
Copy link
Collaborator

@billkoch Thank you for reporting this.

Is there a reason to use String-based class references over Class references?

I'm not sure why the String-based class equality check was used but it should use the class reference instead, as per your workaround.

Would you be interested in submitting a PR for this fix?

@jgrandja jgrandja added type: bug A general bug and removed type: enhancement A general enhancement labels Oct 16, 2024
@jgrandja jgrandja added this to the 1.2.7 milestone Oct 16, 2024
@billkoch
Copy link
Contributor Author

@jgrandja Thank you for the quick response! I'd be happy to submit a PR for this. 👍

billkoch added a commit to billkoch/spring-authorization-server that referenced this issue Oct 17, 2024
…e subclasses

Prior to this commit, String-based class name comparisons were used for determining if a bean was of type JdbcOAuth2AuthorizationService or
JdbcRegisteredClientRepository.

Now JdbcOAuth2AuthorizationService.class.isAssignableFrom(...) and JdbcRegisteredClientRepository.class.isAssignableFrom(...) is used so that any subclasses are
detected and the necessary AOT hints are contributed.

closes spring-projectsgh-1737
@billkoch
Copy link
Contributor Author

@jgrandja I opened #1778 to address this. Please let me know what you think.

@jgrandja jgrandja added the status: duplicate A duplicate of another issue label Oct 18, 2024
@jgrandja jgrandja removed this from the 1.2.7 milestone Oct 18, 2024
billkoch added a commit to billkoch/spring-authorization-server that referenced this issue Oct 18, 2024
…e subclasses

Prior to this commit, String-based class name comparisons were used for determining if a bean was of type JdbcOAuth2AuthorizationService or
JdbcRegisteredClientRepository.

Now JdbcOAuth2AuthorizationService.class.isAssignableFrom(...) and JdbcRegisteredClientRepository.class.isAssignableFrom(...) is used so that any subclasses are
detected and the necessary AOT hints are contributed.

closes spring-projectsgh-1737
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue type: bug A general bug
Projects
None yet
2 participants