Arquillian Extension Shiro
Target
Allow to run arquillian test methods in a shiro context.
Usage
First add the maven dependency:
<dependency> <groupId>com.github.rmannibucau</groupId> <artifactId>arquillian-extension-shiro</artifactId> <version>${arquillian.extension.shiro.version}</version> </dependency>
Then decorate your test with com.github.rmannibucau.arquillian.shiro.api.LoggedWithSubject
annotation.
Here are some examples:
// imports
@RunWith(Arquillian.class)
public class ShiroArquillianAPITest {
@Deployment
public static Archive<?> war() {
return generateMyWar();
}
@Test
@LoggedWithSubject("arquillian")
public void checkUserIsLogged() {
// logged as 'arquillian' with no role
}
@Test
@LoggedWithSubject(value = "arquillian", roles = "*")
public void checkUserHasRoles() {
// logged as 'arquillian' with all roles
}
@Test
@LoggedWithSubject(value = "foo", password = "bar", ini = "classpath:custom-shiro.ini")
public void checkOverridedCustomIni() {
// logged with user foo even if not in the specified ini file
}
@Test
@LoggedWithSubject(value = "jboss", password = "arquillian", ini = "classpath:custom-shiro.ini")
public void checkCustomIni() {
// logged with user jboss
}
}
Note
|
LoggedWithSubject can be put at class level |