use of org.apache.shiro.subject.PrincipalCollection in project shiro by apache.
the class DelegatingSubject method popIdentity.
private PrincipalCollection popIdentity() {
PrincipalCollection popped = null;
List<PrincipalCollection> stack = getRunAsPrincipalsStack();
if (!CollectionUtils.isEmpty(stack)) {
popped = stack.remove(0);
Session session;
if (!CollectionUtils.isEmpty(stack)) {
// persist the changed stack to the session
session = getSession();
session.setAttribute(RUN_AS_PRINCIPALS_SESSION_KEY, stack);
} else {
// stack is empty, remove it from the session:
clearRunAsIdentities();
}
}
return popped;
}
use of org.apache.shiro.subject.PrincipalCollection in project shiro by apache.
the class TextConfigurationRealmTest method testHasRole.
/*
* Tests that roles can't be read while the realm is being loaded.
*/
@Test
public void testHasRole() throws InterruptedException {
setUpForReadConfigurationTest();
executeTest(new Runnable() {
public void run() {
PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1");
assertTrue("principal doesn't have role when it should", realm.hasRole(principalCollection, "role2"));
assertTrue("principal doesn't have all roles when it should", realm.hasAllRoles(principalCollection, Arrays.asList(new String[] { "role1", "role2" })));
}
});
}
use of org.apache.shiro.subject.PrincipalCollection in project shiro by apache.
the class TextConfigurationRealmTest method testCheckPermission.
/*
* Tests that a principal's permissions can't be checked while the realm is being loaded.
*/
@Test
public void testCheckPermission() throws InterruptedException {
setUpForReadConfigurationTest();
executeTest(new Runnable() {
public void run() {
PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1");
try {
realm.checkPermission(principalCollection, "role1_permission1");
realm.checkPermissions(principalCollection, new String[] { "role1_permission1", "role2_permission2" });
} catch (AuthorizationException ae) {
fail("principal doesn't have permission when it should");
}
}
});
}
use of org.apache.shiro.subject.PrincipalCollection in project shiro by apache.
the class TextConfigurationRealmTest method testIsPermitted.
/*
* Tests that a principal's permissions can't be checked while the realm is being loaded.
*/
@Test
public void testIsPermitted() throws InterruptedException {
setUpForReadConfigurationTest();
executeTest(new Runnable() {
public void run() {
PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1");
assertTrue("permission not permitted when it should be", realm.isPermitted(principalCollection, "role1_permission1"));
assertTrue("permission not permitted when it should be", realm.isPermittedAll(principalCollection, new String[] { "role1_permission1", "role2_permission2" }));
}
});
}
use of org.apache.shiro.subject.PrincipalCollection in project shiro by apache.
the class AccountInfoController method home.
@RequiresRoles("admin")
@RequestMapping("/account-info")
public String home(Model model) {
String name = "World";
Subject subject = SecurityUtils.getSubject();
PrincipalCollection principalCollection = subject.getPrincipals();
if (principalCollection != null && !principalCollection.isEmpty()) {
name = principalCollection.getPrimaryPrincipal().toString();
}
model.addAttribute("name", name);
return "account-info";
}
Aggregations