-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
AuthorizationManager should add support check like AuthenticationProvider #15317
Comments
Instead of a Have you tried that approach and if so where is it causing trouble for you? |
Not sure if you misunderstand my idea here. Let me explain with some example code. Current: MyAuthorizationManager implement AuthorizationManager{
check(Supplier<Authentication> authentication, T object) {
// Can not safe cast the authentication here, need another support method for class check
}
} What I want: MyAuthorizationManager implement AuthorizationManager{
check(Supplier<Authentication> authentication, T object) {
// Can safe cast the authentication here
}
boolean supports(Class<?> authentication) {
return MyAuthentication.class.isAssignableFrom(authentication);
}
} And the supports method should called by the framework. Hope these code explain more clear what I want. |
I see your meaning, you want to be able to safely cast, and That said, you can safely cast in the following way as well: MyAuthorizationManager implement AuthorizationManager{
check(Supplier<Authentication> authentication, T object) {
if (!(authentication.get() instanceof MyAuthentication myAuthentication)) {
return null;
}
// ...
}
} I realize that it is a little different than what you are used to in |
Of course I can check the type by myself in check method. Or is there any reason that |
Good question. The main reason is that it seems unnecessary, and we like to keep APIs as lean as possible. Introducing this method would require that the rest of Spring Security now call Also, considering your interest in this, please consider following #11428 which details future efforts to deprecate |
I'm going to close this as |
Then why the AuthenticationProvider have In fact, I really like the By the way, I didn't see much relate information in that post, the post seems mainly talk about naming instead |
I think it's just another way to conceptualize the solution. That said, the interface was introduced before my time so I don't know. These days, we suggest that folks have just one
I'm not sure I follow the analogy; I think you are talking about isolating concerns, which I agree is an important design principle. My point is that this is an intrinsic part of the authorization concern. Consider that If you have to check for (Additionally, there is the issue of the Here is the difference: if (manager.supports(authentication.get())) {
AuthorizationDecision decision = manager.check(authentication, object);
if (decision == null) {
// do abstain logic
} else if (decision.isGranted()) {
// do granted logic
} else {
// do denied logic
}
} else {
// do abstain logic
} vs AuthorizationDecision decision = manager.check(authentication, object);
if (decision == null) {
// do abstain logic
} else if (decision.isGranted()) {
// do granted logic
} else {
// do denied logic
} This has the benefit that the manager returning
What I was saying with the link is that |
Expected Behavior
Can be safely cast the
Authentication
principal to tomyPrincipal
in thecheck(Supplier<Authentication> authentication, T object)
method.Current Behavior
Have no idea if the
MyAuthorizationManager
can handle theAuthentication
.Context
Need extra check if
Authentication
is instanceofMyAuthentication
.If have a method like
Then we can put the check code in the method, which make the authorization check code more clean.
The text was updated successfully, but these errors were encountered: