Skip to content

Make it possible to use Spring Security with functional bean registration #6624

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
sdeleuze opened this issue Mar 18, 2019 · 7 comments · Fixed by #6761
Closed

Make it possible to use Spring Security with functional bean registration #6624

sdeleuze opened this issue Mar 18, 2019 · 7 comments · Fixed by #6761
Assignees
Labels
in: config An issue in spring-security-config type: enhancement A general enhancement
Milestone

Comments

@sdeleuze
Copy link

We would like to start adding Spring Security support in Spring Fu (via an external contributor) but we are currently blocked because unlike Spring Boot configurations, it is not possible to inject programmatically required beans in Spring Security configuration classes.

Our goal is to provide a functional bean registration equivalent of @EnableWebFluxSecurity which imports following configurations:

  • ServerHttpSecurityConfiguration
  • WebFluxSecurityConfiguration
  • ReactiveOAuth2ClientImportSelector$OAuth2ClientWebFluxSecurityConfiguration

We would like to use these configuration classes like we use Spring Boot configuration classes in https://github.com/spring-projects/spring-fu/tree/master/autoconfigure-adapter, but autowired private field make that impossible.

To solve this, autowired fields should be injectable via protected/package private setters or constructor parameters. That has also the benefit to make these classes easily testable.

Any chance you could make these changes to allow us to move forward on functional configuration for Spring Security?

@rwinch
Copy link
Member

rwinch commented Mar 18, 2019

@sdeleuze Thanks for the report! We definitely want to enable this to progress. Are there reasons that the DSL only makes sense for functional beans and not allowing it to be used in standard Spring Security setups? I'm asking because we have had this sort of request before.

@sdeleuze
Copy link
Author

I have also that goal in mind, the Kotlin DSL that will arise on Spring Fu incubating side could be usable in regular Javaconfig mode as well, like we do on WebFlux router and bean registration side. My plan is to provide a PR for that at some point, when that will be mature enough.

@jgrandja
Copy link
Contributor

@sdeleuze I'm not sure it makes sense to expose setter/constructor params in the @Configuration classes. NOTE: ServerHttpSecurityConfiguration, WebFluxSecurityConfiguration and ReactiveOAuth2ClientImportSelector are package-private as well so these would need to be exposed as well, which again we're not really keen on.

We definitely want to help move this forward for you, I'm just not seeing how reusing @Configuration makes sense for functional @Bean registration. Maybe I'm missing something and you can help me better understand?

Would you consider using ServerHttpSecurity directly to configure it functionally and than register it as a @Bean via the ApplicationContextInitializer adaptor module? Let me know if this strategy would work for you.

@sdeleuze
Copy link
Author

sdeleuze commented Apr 4, 2019

Like for Spring Boot features I use in Spring Fu, the idea would be to use package private only setters, use the same Spring Security package on Spring Fu side and later reintegrating the DSL in Spring Security itself. That's why I am only asking for package private access, nothing more.

I will use ServerHttpSecurity but I think I need to be able to register the previously mentioned configurations functonaly in order to be able to get the ServerHttpSecurity instance.

@jgrandja jgrandja self-assigned this Apr 9, 2019
@jgrandja
Copy link
Contributor

jgrandja commented Apr 9, 2019

the idea would be to use package private only setters, use the same Spring Security package

I get it now...somehow I misunderstood when I read your comments previously. Let me put something together for you and we can review from there.

@jgrandja
Copy link
Contributor

jgrandja commented Apr 9, 2019

@sdeleuze See #6761 and please confirm if this is what you're looking for.

@rwinch Please review and let me know if you're good with this approach. I'll add tests to complete the PR after we're all on the same page.

@sdeleuze
Copy link
Author

sdeleuze commented Apr 9, 2019

@jgrandja Yes this is exactly that :-) I have just added a question in the PR, see 85abc75#r273683479.

@jgrandja jgrandja added type: enhancement A general enhancement in: config An issue in spring-security-config labels Apr 9, 2019
jgrandja added a commit to jgrandja/spring-security that referenced this issue Apr 23, 2019
@jgrandja jgrandja added this to the 5.2.0.RC1 milestone Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: config An issue in spring-security-config type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants