https://github.com/l3r8yj/spring-x-roles-authorities-starter
Allows testing of role model for your Spring Boot application
https://github.com/l3r8yj/spring-x-roles-authorities-starter
spring-boot spring-security testing-tools
Last synced: 7 months ago
JSON representation
Allows testing of role model for your Spring Boot application
- Host: GitHub
- URL: https://github.com/l3r8yj/spring-x-roles-authorities-starter
- Owner: l3r8yJ
- License: mit
- Created: 2024-05-20T14:59:51.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-21T06:15:13.000Z (8 months ago)
- Last Synced: 2025-04-12T23:55:37.021Z (7 months ago)
- Topics: spring-boot, spring-security, testing-tools
- Language: Java
- Homepage:
- Size: 156 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
## Spring X-Roles Authorities starter
[](https://search.maven.org/artifact/ru.l3r8y/spring-x-roles-authorities-starter)
[](https://github.com/l3r8yJ/spring-x-roles-authorities-starter/blob/master/LICENSE.txt)
This starter allows you to test your role model for non-production scenarios.
[Link](https://www.l3r8y.ru/2024/05/24/role-model-testing-with-spring-boot) to blog post.
## How to
1. Add a dependency
```xml
ru.l3r8y
spring-x-roles-authorities-starter
```
2. Add to `application.yaml`
```yaml
x-roles:
enabled: true
```
Done! Now starter provides an ability to extract authorities from `X-Roles` header:
```http request
// Basic authentication
GET https://example.com/endpoint
Authorization: // any auth
X-Roles: my-role, another-role
```
Allows hitting this endpoint:
```java
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
final class Controller {
@GetMapping("/endpoint")
@PreAuthorize("hasAnyAuthority('my-role')")
public ResponseEntity sayHi() {
return "Hi!";
}
}
```
## How to Contribute
Fork repository, make changes, then send us a [pull request](https://www.yegor256.com/2014/04/15/github-guidelines.html).
We will review your changes and apply them to the `master` branch shortly,
provided they don't violate our quality standards.
To avoid frustration,
before sending us your pull request please run full Maven build:
```bash
mvn clean install
```
You will need [Maven 3.3+](https://maven.apache.org) and Java 8+ installed.