Building Custom Multi Tenant and Multi Factor Authentication and Authorization Platform
Bhargav Maddikera
Engineering Leader | Technology Leader | Enterprise Architect | Technical Architect | Big Data | Building Data Intensive & Large Scale Systems | EAI | SaaS | SOA | 0-1 B2B | 0-1 B2C | Payments | E-commerce | Fintech
Here is my approach on how to build a custom Authentication and Authorization platform
before i go into the approach and solution, a generic definition of authentication and authorization. suppose there is a floor with 10 rooms - 3 rooms for meetings, 3 rooms for training, 2 rooms for finance(say cash is stored here), 2 rooms for IT(say hardware is stored here). if the user can successfully go through security checks at the floor(like card access, thumb, face recognition or voice), its called authentication. lets say he clears the security checks at the floor level, what are the rooms can he enter? this is governed by roles and access. a normal person can enter into meeting, training rooms but not into finance and IT rooms. whereas a finance analyst might have access to enter the finance room but not have access to cash box which only a finance admin can. finance admin can enter into all the rooms and have access to cash box but will not have access to IT room. this constitutes authorization as roles and privileges govern this
1) Tech Stack
2) Multi Tenant and Multi Factor Authentication Platform
lets say you have the following auth modes applicable for all the tenants as a SaaS offering. tenants can opt for one or more of the following auth modes(we can also have other modes like facial recognition, thumb etc but confining to the following)
during tenant onboarding, each tenant can say what are the modes they would want to have and in what order. say for example one tenant might say, they would want to have user name and password first and email OTP second whereas another tenant might say, they would want to have user name and password first, google verification code second and verify security question as third mode. for a UI based authentication platform, we would configure second level domain and sub domain(for various environments) per tenant or a generic domain applicable for all the tenants
the UI will get the order of authentication modes for a given domain and will render the pages in that order
we will delay constructing the authentication data till the last mode is arrived at. for example, if a tenant wants user name and password, OTP email, OTP SMS authentication in this order, we will verify user name and password credentials in "verify user name and password API" Email OTP in "verify OTP via email API", SMS OTP in "verify OTP via sms API" and after this , we will do actual authentication in verify OTP via sms API since OTP SMS is the last mode preferred.
??????? ?????????? ????????????? ?????????????,? ??????? ????????????? ??????????????????? ??????????????????????????????????????????? ????????????
we will be using Hazelcast for storing data
????????????????????????????????????? ???????????????? ?????????? ???????????????? ????????????? ??????? ??????????????????? ?????????? ???????????????? ?????????????????????? ?????????? ????????????? ??????? ?????????? ???????????????????????????
with this, we have 2 tokens for Authentication - one token for 30 minutes and another token for every request
??????????????????? ?????????? ???????????????? ????????????? ??????? ??????????????????? ????????????
the above 2 points will remove the key(inVal) from the hazelcast map and successive calls passing the same key(inVal) will return access denied.
in addition to the above, the key(inVal) will be automatically removed from the Hazelcast map after 30 minutes as the expiration is set as 30 minutes for the tokenMap object
领英推荐
????????????? ??????? ?????????????????????? ?????????????????????????????????? ?????????? ?????????????????????????????????? ???????????????????????
yes, it addresses distributed problem as Hazelcast is a very good solution for storing and accessing data in a distributed environment. the keys added to hazelcast map is replicated synchronously across the cluster guaranteeing strong consistency. for a get, any node can receive the request but only the primary node will return the data
yes, Hazelcast addresses concurrency problem. however, if you want to have distributed lock across the cluster, then we can leverage Hazelcast lock by doing the following
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance() (can be configured to add to the cluster by configuring cluster settings)
Lock lock = hazelcastInstance.getLock( "myLock" );
try {
// insert into Hazelcast map
} finally {
lock.unlock();
}
the above code will acquired distributed lock on the Auth cluster for the critical region that will be used to add auth data
so for authentication, there will be 2 tokens that need to be passed in the header - inVal and fnVal for every request
3) Authorization Platform
Authorization can happen at screen level and at API level
??????????????????? ???????????????? ???????????????????????????????????????
In the Admin console
?????????? ???????????????? ???????????????????????????????????????
so for authorization, there will be 1 token that need to be passed in the header - service_role_token for every request
4) Tables Involved
I am highlighting the core tables that will be involved
Principal Java Full Stack Engineer
7 个月Good one ??
Product & Analytics @ Tekion | CRM, B2B SaaS, Finance
8 个月Yet again you are keeping things simple. Good Bhargav Maddikera Why do we need to use 2 token for auth?
Sr. Engineering Manager | Mobile Architect | Digital Transformation Leader | Problem Solver | Proud Father | Driving Innovation in Software Development
8 个月Insightful Bhargav Maddikera