I use the micro-services architecture. Each service uses bearer access type. The users get token by public service. Each service is business application with own privelegies. Rabbit mq is used as interprocess communication. Keycloak transfers user roles for each service by JWT. But I would like to transfer user privelegies in the user's token.
Like this :
priveleges:[
{resource: subjects,
roles:[ADMIN,OPER,COMPLAINCE],
categories:[
read:[1,2,3,4,5],
write:[3,4,5],
delete:[3,4,5]
],
notes:[
read:[1,2,3,4,5],
write:[3,4,5],
delete:[3,4,5]
],
subject:[
read:true,
write:true,
delete:false
],
addresses:[
read:true,
write:true,
delete:false
]
},
{resource: cards,
roles:[ADMIN,OPER,COMPLAINCE],
card:[
read:true,
write:true,
delete:false
],
fin-operation:[1,2,3,4,5],
non-fin-operation:[1,2,3,4]
}
]
I have two questions:
Can I set different privileges for each user in keycloak? I know it is possible to use a ProtocolMapper with a hardcoded mapper type in Keycloak. And in this case it will be one for all users but I need to have privileges claim for each user.
Is it correct to pass privileges in a token, so that later they can be processed on the backend and frontend?
Additional information: But if I try to add string value more 255 chars, I catch the error because it is constraint of it field. I have the error in logs jboss : ERROR: value too long for type character varying(255)
I try to add this claim:
{ "priveleges":[ { "resource":"subjects", "roles":[ "ADMIN", "OPER", "COMPLAINCE" ], "categories":[ { "read":[ 1, 2, 3, 8, 5 ] }, { "write":[ 3, 9, 5 ] }, { "delete":[ 3, 6, 5 ] } ], "notes":[ { "read":[ 1, 2, 3, 7, 5 ] }, { "write":[ 3, 4, 5 ] }, { "delete":[ 3, 4, 5 ] } ] }, { "resource":"cards", "roles":[ "ADMIN", "OPER", "COMPLAINCE" ], "fin-operation":[ 1, 2, 3, 4, 5 ], "non-fin-operation":[ 1, 2, 3, 4 ] } ] }




