Skip to content
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

Request to add Custom Properties to AuthenticationConfiguration #14451

Closed
CHOICORE opened this issue Jan 14, 2024 · 1 comment
Closed

Request to add Custom Properties to AuthenticationConfiguration #14451

CHOICORE opened this issue Jan 14, 2024 · 1 comment
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@CHOICORE
Copy link

Dear. Spring Developers

Although late, I sincerely hope that you receive many blessings in the new year.

Expected Behavior
Would you be so kind as to create a method for utilizing the AuthenticationManager directly, or perhaps devise a property to bypass or eliminate the Default Provider, particularly in circumstances where the AuthenticationManager can be used outright?

Current Behavior
Currently, there is no way to register and use the AuthenticationManager object as a global bean.
I am trying to register a custom Provider, but...

I believe that the DaoAuthenticationProvider is not necessary in the Bearer Token authentication method. Therefore, I did not implement UserDetailsService. However, when I inject the ProviderManager and run authenticate, a proxy object is injected, and a StackOfFlow occurs when trying to find a Bean

    @Bean
    public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
        ProviderManager authenticationManager = (ProviderManager) authenticationConfiguration.getAuthenticationManager();
        authenticationManager.getProviders().add(new CustomProvider());
        return authenticationManager;
    }
public class CustomFilter extends OncePerRequestFilter {

    private final AuthenticationManager authenticationManager;

    public CustomFilter(final AuthenticationManager authenticationManager) {
        this.authenticationManager = authenticationManager;

    }

    @Override
    public void afterPropertiesSet() throws ServletException {
        super.afterPropertiesSet();
        ProviderManager providerManager = (ProviderManager) authenticationManager;
        providerManager.getProviders().removeAll(providerManager.getProviders());
        providerManager.getProviders().add(new CustomProvider());
    }

    @Override
    protected void doFilterInternal(
            final HttpServletRequest request,
            final HttpServletResponse response,
            final FilterChain filterChain)
            throws ServletException, IOException {
        CustomToken user = new CustomToken(List.of(new SimpleGrantedAuthority("USER")));
        authenticationManager.authenticate(user);
        filterChain.doFilter(request, response);
    }
}

image

image

@CHOICORE CHOICORE added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Jan 14, 2024
@marcusdacoregio
Copy link
Contributor

Hi, @CHOICORE. Thanks for the good wishes.

I believe that the documentation about how to publish a AuthenticationManager bean and this issue might help you fixing the issue.
If you still believe that there is some place for enhancement or if there is a bug, feel free to comment back in this issue and we can consider reopening it.

@marcusdacoregio marcusdacoregio self-assigned this Jan 17, 2024
@marcusdacoregio marcusdacoregio added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants