-
Notifications
You must be signed in to change notification settings - Fork 6k
Reactive PermissionEvaluator? #5046
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
Comments
@sp00m Could you please comment on why the ticket has been closed? Did you find a solution, if so - how does it look like? |
@marc-christian-schulze I gave up trying to use these magic methods to be honest, they did not really fit the complex multitenant authorisation system I'm working with anyway. Reopened the ticket though if you're facing this issue as well. |
Thank you to both of you for your feedback. We do not have plans to provide a |
Makes sense, thanks! |
@edeandrea You can create your own Bean as described above. This decouples your code from Spring Security's APIs. |
So would @PreAuthorize("hasPermission('someResource', 'someAction')") become @PreAuthorize("@myBean.someMethod('someResource', 'someAction')") ? |
Yes |
Ok thanks - I'll give it a try. |
Thanks @rwinch this seems to work. Does the reactive support for reactive method security allow for specifying custom expressions? Or would we have to rely on having purely bean references via the |
Hi @rwinch just an additional question on this. Within my organization we have pretty much standardized on the My question is this - would we be able to bring that functionality back in simply by doing something like the following code snippet in the auto-configuration within our own custom starter? When I try it out it seems to work fine. I just want to make sure by doing this I'm not overriding something or breaking something (i.e. the Essentially we try and abstract all the security details away from the applications so that there is 1 consistent interface when it comes to performing authorization. We want all of our authorization logic across all applications within the organization to be centralized. Applications themselves should not be making those decisions. @Configuration
@ConditionalOnWebApplication(type = Type.REACTIVE)
@EnableReactiveMethodSecurity
@EnableWebFluxSecurity
public class ReactiveSecurityConfig {
@ConditionalOnBean(MyCompanyCustomPermissionEvaluatorInterface.class)
@Bean
public DefaultMethodSecurityExpressionHandler methodSecurityExpressionHandler(MyCompanyCustomPermissionEvaluatorInterface permissionEvaluator) {
DefaultMethodSecurityExpressionHandler handler = new DefaultMethodSecurityExpressionHandler();
handler.setPermissionEvaluator(permissionEvaluator);
return handler;
}
} |
It's going to be very challenging to make this compatible between a reactive stack and non reactive stack because you cannot have any blocking methods in a reactive stack. All of the PermissionEvaluator implementations are blocking since they don't return a Publisher. This means they cannot perform a blocking operation (i.e. cannot call a remote service). |
Thank you @rwinch. Seems like the better way to go would be to deprecate our current use of Then for our current servlet stack build an adapter which can adapt a If we do that is there a way to configure spring security so that we can wire the hasPermission expression to something other than a |
You would extend DefaultWebSecurityExpressionHandler and override the createSecurityExpresssionRoot to create a root object that delegates hasPermission to another object |
It has been about 3 years since the last message in this thread; did anything change since then regarding permission evaluators in a reactive stack? |
If you don't mind sharing, how did your implementation look like @edeandrea? |
For anyone coming here in the future, here's how I was able to create a custom Authorization method: // Security config
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
class SecurityConfiguration {
// ... // Controller
@PreAuthorize("@customGuard.someMethod(#authentication, #someId, 'someAction')")
suspend fun getController(authentication: Authentication, @PathVariable someId: UUID): ResponseEntity<CustomResponseEntity> {
// ... // Custom guard
@Component
class CustomGuard {
fun someMethod(authentication: Authentication, resourceId: String, action: String): Boolean {
// Your authorization logic goes here
// return true if the authorization is granted; otherwise, return false
return false
}
} I still don't know how my controller imports |
Hi @rasmus-rudling I don't have any local changes anymore (this was a few years and several laptops ago :) ). All the work I had done on it is in #5980 It never got merged in due to some conflicts and breaking changes, and I just got too busy to work on it anymore. Feel free to continue with it and/or take any pieces from it. It has not been kept up to date with spring/spring security versions either. |
Because in spring your bean Then in spring expression language you reference a bean by name using |
Thank you for that! |
Summary
I plan to implement my own
PermissionEvaluator
, but the methods signatures don't allow me to use reactive types.Actual Behavior
Expected Behavior
Version
5.0.2.RELEASE
The text was updated successfully, but these errors were encountered: