* <p>Test get permissions from a collection of principals.</p>
*/
public void testGetPermissions()
{
// Init test.
UserPrincipal user = new UserPrincipalImpl("anon");
RolePrincipal role1 = new RolePrincipalImpl("anonrole1");
RolePrincipal role2 = new RolePrincipalImpl("anonrole2");
GroupPrincipal group1 = new GroupPrincipalImpl("anongroup1");
GroupPrincipal group2 = new GroupPrincipalImpl("anongroup2");
PortletPermission perm1 = new PortletPermission("anontestportlet", "view");
PortletPermission perm2 = new PortletPermission("anontestportlet", "view, edit");
PortletPermission perm3 = new PortletPermission("anontestportlet", "view, edit, secure");
PortletPermission perm4 = new PortletPermission("anontestportlet", "view, edit, secure, minimized");
try
{
ums.addUser(user.getName(), "password");
rms.addRole(role1.getName());
rms.addRole(role2.getName());
gms.addGroup(group1.getName());
gms.addGroup(group2.getName());
pms.addPermission(perm1);
pms.addPermission(perm2);
pms.addPermission(perm3);
pms.addPermission(perm4);
pms.grantPermission(role1, perm1);
pms.grantPermission(role2, perm1);
pms.grantPermission(role2, perm2);
pms.grantPermission(role2, perm3);
pms.grantPermission(role2, perm4);
pms.grantPermission(group1, perm1);
pms.grantPermission(group2, perm1);
pms.grantPermission(group2, perm2);
pms.grantPermission(group2, perm3);
pms.grantPermission(group2, perm4);
}
catch (SecurityException sex)
{
assertTrue("failed to init testGetPrincipalPermissions(), " + sex, false);
}
ArrayList principals = new ArrayList();
principals.add(user);
principals.add(role1);
principals.add(role2);
principals.add(group1);
principals.add(group2);
Permissions permissions = pms.getPermissions(principals);
assertTrue(
"should contain permission == {name = "
+ perm1.getName()
+ "}, {action = "
+ perm1.getActions()
+ "}, in collection of size == 4, actual size: "
+ (Collections.list(permissions.elements())).size(),
validatePermissions(permissions, perm1, 4));
assertTrue(
"should contain permission == {name = "
+ perm2.getName()
+ "}, {action = "
+ perm2.getActions()
+ "}, in collection of size == 4, actual size: "
+ (Collections.list(permissions.elements())).size(),
validatePermissions(permissions, perm2, 4));
assertTrue(
"should contain permission == {name = "
+ perm3.getName()
+ "}, {action = "
+ perm3.getActions()
+ "}, in collection of size == 4, actual size: "
+ (Collections.list(permissions.elements())).size(),
validatePermissions(permissions, perm3, 4));
assertTrue(
"should contain permission == {name = "
+ perm4.getName()
+ "}, {action = "
+ perm4.getActions()
+ "}, in collection of size == 4, actual size: "
+ (Collections.list(permissions.elements())).size(),
validatePermissions(permissions, perm4, 4));
// Cleanup test.
try
{
ums.removeUser(user.getName());
pms.removePermission(perm1);
pms.removePermission(perm2);
pms.removePermission(perm3);
pms.removePermission(perm4);
}