-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Add SingleResultAuthorizationManager #16612
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2002-2025 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.authorization; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.springframework.security.core.Authentication; | ||
|
||
/** | ||
* An {@link AuthorizationManager} which creates permit-all and deny-all | ||
* {@link AuthorizationManager} instances. | ||
* | ||
* @author Max Batischev | ||
* @since 6.5 | ||
*/ | ||
public final class SingleResultAuthorizationManager<C> implements AuthorizationManager<C> { | ||
|
||
private static final AuthorizationDecision DENY = new AuthorizationDecision(false); | ||
|
||
private static final AuthorizationDecision PERMIT = new AuthorizationDecision(true); | ||
|
||
/** | ||
* Creates permit-all {@link AuthorizationManager} instance. | ||
* @param <C> | ||
* @return permit-all {@link AuthorizationManager} instance | ||
*/ | ||
public static <C> AuthorizationManager<C> PERMIT_ALL() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring Security conventionally uses |
||
return (a, o) -> PERMIT; | ||
} | ||
|
||
/** | ||
* Creates deny-all {@link AuthorizationManager} instance. | ||
* @param <C> | ||
* @return deny-all {@link AuthorizationManager} instance | ||
*/ | ||
public static <C> AuthorizationManager<C> DENY_ALL() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring Security conventionally uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should return the concrete type. Just like constructors emit the concrete type. Can you please change both method to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we can't do this, java uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, you can ignore this comment :) |
||
return (a, o) -> DENY; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of a lambda, consider returning a |
||
} | ||
|
||
private SingleResultAuthorizationManager() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While having this for |
||
} | ||
|
||
@Override | ||
public AuthorizationDecision check(Supplier<Authentication> authentication, C object) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's please implement |
||
throw new UnsupportedOperationException("Not supported"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's still implement this. If the private member |
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests for the class.