0

Spring security -how to add roles dynamically and depending on role there url access permission must change and when creating role we have to set url permissions dynamically
ex: for admin he can access all urls and when i am creating another role like support i can set which urls he can access dynamically

1 Answers1

0

This is specifically what Spring authorization handles.
You can use Spring expressions like -

@PreAuthorize("hasAuthority('PERM_ADD')")
@RequestMapping("/add")
public String add() {
  ...
}

Here is the documentation -
https://docs.spring.io/spring-security/site/docs/current/reference/html/authorization.html

You may want to implement something like this example - https://stackoverflow.com/a/60251931/1308685

Where the user roles are mapped to more granular permissions.

Jeremy
  • 2,970
  • 1
  • 26
  • 50