I have a user permission system in place where i have a set of permissions within the database, for example
id | Permission |
---|---|
1 | POST:CreateBooking |
2 | GET:AllBookings |
And i have another table (junction table) where i put dependent permissions
such as
if i want to create a Booking
, i need to fetch Package
details and so POST:CreateBooking
requires the user to also have GET:AllPackages
permission.
There’s a template system in place as well, where the users can group multiple permissions together and once that template is assigned to any employee, that employee will get THAT
set of permissions and it’s dependent permissions.
What my nodejs system does is that when user logs in, it fetches all permissions from DB and puts it in a redis set
from where on each request, the permission is checked against user id.
Is there any tool from where i can do exactly this but in an intuitive and better way?
I tried keycloak
but i don’t know how to cover my needs mentioned above.
Thank you
2
Answers
if I’m understanding correctly and trying to generify your scenario, you have a classical situation where:
groups
which can have multiplepermissions
assigned;groups
can be created dinamically;permission
correspond to a specific functionality.So, implementing the OIDC (Open Id Connect) protocol might fit you needs. As you suggested youself you might be interested in a OpenID provider (do not reinvent the wheel)
keycloak
is good, you can give a look also toVault Hashicorp
.So assuming that your backend have an already existing framework to handle security and permissions (eg. Spring Security) you can produce JWT token with the OpenId provider and check throught
PreAuthorize
claims (permissions) inside the token.At the end your security layer it’s just an annotation you need to insert before your method controller or before you class controller.
Behind the scenes, instead, this is what will happen:
403 Forbidden
it’s returned.OIDC – as the conceptual model/backdrop to any tool of choice, is certainly a popular/good choice, but as long as you’re willing to deal with an element of complexity – the understanding required to implement an OIDC arrangement (- think of it as a possible investment – effort up front with hopefully the rewards tricking-in over time); e.g. OIDC is an ideal choice for supporting SSO (Single Sign On), especially when it comes to supporting/allowing for authentication/login via providers such as Facebook, LinkedIn & Google, etc (- as well as more Corporate OPs (OIDC Providers) including AAD/Azure AD).
Try to first step-back, and consider the possible bigger/future picture, before selecting a tool based upon only your starting/current requirements.