- Java 100%
| src | ||
| .gitignore | ||
| pom.xml | ||
| README.md | ||
Hans Gruper
Hit it again
Java group/privilege management library
What and why
We assign groups to users to mange permissions. Groups can be single groups such as api.users.create; which allows a user to access the create user api, or arrays of groups such as ["api.users.create", "api.keys.read"]; which allows this user to access the create user api but only read API keys.
Gruper is simply a shared utility to compare the groups arrays/strings with preset permissions set in code.
Usage
In this example, we have a API controller endpoint for creating a new user. Within the controller, we can compare the current users groups with a pre-set permission id to see if they have correct access permissions
...
List<String> usersGroups = Arrays.asList("api.users.create", "api.keys.read");
if (!Gruper.compare(usersGroups, "api.users.create")) {
return "Access denied";
}
...
In this example, if the user had the permissions api.users, this would allow them to access ALL of the api.users sub-groups too, such as api.users.create.
