ADD PermissionVoter for wildcard permissions gh-4611 #5467
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was in need a permission based method security. As I was already using spring-security, I did not want to integrate Apache Shiro too which already knows hierarchical wildcard permissions. Also I figured, it would not be to hard to implement it. Seeing in #4661 [Feature request] Featuren similar to Shiro Wildcard Permission that I wasn't the only one desiring this feature, I would like to make it my first contribution.
Hierarchical wildcard permission
A hierarchical wildcard permission is a dynaminc permission definition.
A permission consists of three parts:
Example:
myApp.userMgmt.**:read,write
->implies rights to read write on all components/resources of the userManagmentmyApp.logMgmt.systemLog:delete
->implies rights to delete system logsmyApp.fleetMgmt.trains:*:TR415,TR420
->implies full rights for the trains TR415,TR420**
->implies almighty powersWhat's implemented
The content of the pull request is basic. It contains a
PermissionVoter
, itsPermissionVoterTests
and aPermission
helper object which extendsGrantedAuthority
. The idea of extendingGrantedAuthority
is, thatPermission
can be added to anAuthentication
for further distinction.The current way to use the
PermissionVoter
is by defining a customGlobalMethodSecurityConfiguration
:Afterwards
@Secured
tags containing permission strings are supported.What's not implemented
It would be desirable to be able to have a
@Permitted
annotation. The given values of this annotation could be used to createPermissionConfigAttribute
objects which then further would allow asupports()
filtering inside of thePermissionVoter
. As this is not implemented yet, it might cause issues when combiningRoleVoter
andPermissionVoter
as thePermissionVoter
currently accepts everyConfigAttribute