Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/namnv2496/springboot_rbac
Role-Base Access control
https://github.com/namnv2496/springboot_rbac
basic-programming demo-app rbac role-based-access-control security spring-boot starter
Last synced: 4 days ago
JSON representation
Role-Base Access control
- Host: GitHub
- URL: https://github.com/namnv2496/springboot_rbac
- Owner: NamNV2496
- Created: 2022-10-04T13:16:57.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-21T02:47:39.000Z (7 months ago)
- Last Synced: 2024-11-09T02:35:18.407Z (about 2 months ago)
- Topics: basic-programming, demo-app, rbac, role-based-access-control, security, spring-boot, starter
- Language: Java
- Homepage:
- Size: 61.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# RBAC
```yml
spring:
messages:
basename: i18n/messages
```we need parse token and save username and role to securityContextHolder
```text
SecurityContextHolder.getContext().setAuthentication(authentication);
````@PreAuthorize("hasAuthority('admin')")` or `@PreAuthorize("hasAuthority('admin') || hasAuthority('user')")` will access and get role to compare automatically
```textmate
Role does not accesscurl --location --request GET 'http://localhost:8080/getSecureUser' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTY2NDQ2MjEyOCwiZXhwIjoxNjY0NDY1NzI4LCJkYXRhIjpbeyJyb2xlcyI6WyJhZG1pbiIsIm1lbWJlciJdfV19.YrwB4s_pe6Gg9GwwFhVGv3JW7AumivKLGxFudSMNDRM' \
--header 'Cookie: JSESSIONID=45F56EEF7853451443C13E5B6F6458D3' \
--data-raw ''Role access
curl --location --request GET 'http://localhost:8080/getSecure' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTY2NDQ2MjEyOCwiZXhwIjoxNjY0NDY1NzI4LCJkYXRhIjpbeyJyb2xlcyI6WyJhZG1pbiIsIm1lbWJlciJdfV19.YrwB4s_pe6Gg9GwwFhVGv3JW7AumivKLGxFudSMNDRM' \
--header 'Cookie: JSESSIONID=45F56EEF7853451443C13E5B6F6458D3' \
--data-raw ''
```# Way 2 use AOP
https://github.com/NamNV2496/Annotation