https://github.com/sdorra/junit-shiro-extension
Simplify unit tests with JUnit 5 and Apache Shiro
https://github.com/sdorra/junit-shiro-extension
apache-shiro java junit5 junit5-extension testing
Last synced: 8 months ago
JSON representation
Simplify unit tests with JUnit 5 and Apache Shiro
- Host: GitHub
- URL: https://github.com/sdorra/junit-shiro-extension
- Owner: sdorra
- License: mit
- Created: 2021-03-15T07:15:38.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-24T16:36:20.000Z (about 5 years ago)
- Last Synced: 2025-01-13T03:13:35.550Z (over 1 year ago)
- Topics: apache-shiro, java, junit5, junit5-extension, testing
- Language: Java
- Homepage:
- Size: 545 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JUnit Shiro Extension
Simplify unit tests with JUnit 5 and Apache Shiro.
## Usage
```java
@ExtendWith(ShiroExtension.class)
@SubjectAware(
value = "trillian",
roles = "user",
permissions = "one:*"
)
class ShiroExtensionTest {
@Test
void shouldHavePreparedSubject() {
Subject subject = SecurityUtils.getSubject();
assertThat(subject.getPrincipal()).isEqualTo("trillian");
assertThat(subject.hasRole("user")).isTrue();
assertThat(subject.isPermitted("one:dot:one")).isTrue();
}
}
```
The `SubjectAware` annotation can be placed on classes, nested classes or on methods.
Roles and permissions are merged. If the `value` is of `SubjectAware` is empty, no subject is bound.
For more samples have a look at the [ShiroExtensionTest](lib/src/test/java/org/github/sdorra/jse/ShiroExtensionTest.java).
## Installation
Get the latest stable version from [](https://search.maven.org/search?q=g:com.github.sdorra%20a:junit-shiro-extension)
### Gradle
```groovy
testImplementation 'com.github.sdorra:junit-shiro-extension:x.y.z'
```
### Maven
```xml
com.github.sdorra
junit-shiro-extension
x.y.z
test
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details