JUnit Shiro Extension

Simplify unit tests with JUnit 5 and Apache Shiro.

License

License

Categories

Categories

JUnit Unit Testing
GroupId

GroupId

com.github.sdorra
ArtifactId

ArtifactId

junit-shiro-extension
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

JUnit Shiro Extension
Simplify unit tests with JUnit 5 and Apache Shiro.
Project URL

Project URL

https://github.com/sdorra/junit-shiro-extension
Source Code Management

Source Code Management

https://github.com/sdorra/junit-shiro-extension

Download junit-shiro-extension

Dependencies

compile (3)

Group / Artifact Type Version
org.apache.shiro : shiro-core jar 1.7.1
org.junit.jupiter : junit-jupiter-api jar 5.6.2
org.junit.jupiter : junit-jupiter-engine jar 5.6.2

Project Modules

There are no modules declared in this project.

JUnit Shiro Extension

JUnit Shiro Extension

Simplify unit tests with JUnit 5 and Apache Shiro.

Usage

@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.

Installation

Get the latest stable version from Maven Central

Gradle

testImplementation 'com.github.sdorra:junit-shiro-extension:x.y.z'

Maven

<dependency>
  <groupId>com.github.sdorra</groupId>
  <artifactId>junit-shiro-extension</artifactId>
  <version>x.y.z</version>
  <scope>test</scope>
</dependency>

License

This project is licensed under the MIT License - see the LICENSE file for details

Versions

Version
1.0.1
1.0.0