简体   繁体   中英

Role based Rest-API using JWT

I'm implementing a simple Rest-API in java with jax-rs. I use JWT and a ContainerRequestFilter to verify that the user is logged-in.

Now I want to be able to handle different roles. Is it ok to store the user roles in the JWT (claim) and fully trust it to give access or not to an endpoint ?

If not what's the best way to achieve this ?

Thanks for the help

Is it ok to store the user roles in the JWT (claim) and fully trust it to give access or not to an endpoint ?

Yes, that should be fine. As long as you make sure the JWT token is properly signed , you can be assured that no one can make changes to the token and assign themselves high-privilege roles.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM