-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Easier way to define Role Hierarchy #13300
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
Nice idea, @bwgjoseph. There may be a way with regular expressions to make this work. For example, if it meets this regex, then process it the new way; otherwise, process it the old way. Are you able to provide a PR? |
Hello! I'm not quite sure what you mean by using regular expression to make it work, can you expand on that? I don't mind working on a PR if there's a way to provide an easier way to declare the hierarchy. |
What about this way? String roles = RoleHierarchyUtils.roleHierarchyBuilder("ROLE") // sets the prefix, optional
.role("ADMIN").inherits("STAFF")
.role("STAFF").inherits("USER", "GUEST")
.build(); Then the output will be the same as: String roleHierarchyFromMap = """
ROLE_ADMIN > ROLE_STAFF
ROLE_STAFF > ROLE_USER
ROLE_STAFF > ROLE_GUEST
"""; It's more readable and less boilerplate, I can send a PR if needed. |
Hi @AugustoRavazoli, I'm not sure if that's straight-forward or satisfy all use case as well. String roles = RoleHierarchyUtils.roleHierarchyBuilder("ROLE") // sets the prefix, optional
.role("ADMIN").inherits("STAFF")
.role("STAFF").inherits("USER", "GUEST")
.build(); Based on your example, does Based on the |
Hello! Just created this PR to address this issue. While implementing found out that you can do something like the following:
And the So, just went ahead and created a class to just provide a fluent API to build the map and use the same existing utility method Let me here your thoughts! |
Hi @FdHerrera, That's interesting, let me try it out and update the result here. |
Hello, I have finally gotten the chance to try it out. So I have tested it, and while it works, it is still more involved / explicit than using The definition is have is slightly more complicated than above, which is something alone the line of
So what this translates to your sample would be
I guess it does works, and did actually fulfill what I had initially asked, to be created via a Map. So I can't argue against that 🤣 Initially, I didn't quite get you, and this is what I did.
And the output was different from what I had expected. Still appreciate you putting up the PR! |
Disclaimer: I'm hesitant to create this issue for sometime as this is quite subjective, but I thought that I still want to make the suggestion to see if there's any other ways to achieve it (that I've perhaps missed out on)
Currently, if I want to define a
RoleHierarchy
, I can do it likeThe result would be something like
Which is correct, but it is more prone to mistake (with more complex setup), and "uglier" to declare this way via
\n
Luckily, for most use case, I can replace it with
RoleHierarchyUtils.roleHierarchyFromMap
but not for this case where there's a repeated key. And since we are usingMap
,key
has to be unique.Note that for this use case,
ROLE_STAFF
inheritROLE_USER
AND inheritROLE_GUEST
butROLE_USER
does not inheritROLE_GUEST
. Hence, I can't simply do the followingWhich is a limitation for this use case.
I have another way to declare. Since Java now supports
TextBlock
, I can still define asWhich still works. But I do still like the way that I use
Map
to define my hierarchy, which is still clearer, better and straightforward IMO. And I think it's easier to support the declaration viaapplication.yaml
and construct through@ConfigurationProperties
and set it.I wonder if there's any way to support my use case which make the declaration easier.
Thanks!
The text was updated successfully, but these errors were encountered: