for (String action : selectedActions)
{
if (!originalActions.contains(action))
{
grantedPermissions.add(new Permission(target, action, recipient));
}
}
for (String action : originalActions)
{
if (!selectedActions.contains(action))
{
revokedPermissions.add(new Permission(target, action, recipient));
}
}
if (!grantedPermissions.isEmpty()) permissionManager.grantPermissions(grantedPermissions);
if (!revokedPermissions.isEmpty()) permissionManager.revokePermissions(revokedPermissions);
}
// otherwise this is a set of new permissions
else
{
if (selectedActions.size() == 0)
{
FacesMessages.instance().add("You must select at least one action");
return "failure";
}
List<Permission> permissions = new ArrayList<Permission>();
for (String role : selectedRoles)
{
Principal r = new Role(role);
for (String action : selectedActions)
{
permissions.add(new Permission(target, action, r));
}
}
for (Member friend : selectedFriends)
{
MemberAccount acct = (MemberAccount) entityManager.createQuery(
"select a from MemberAccount a where a.member = :member")
.setParameter("member", friend)
.getSingleResult();
Principal p = new SimplePrincipal(acct.getUsername());
for (String action : selectedActions)
{
permissions.add(new Permission(target, action, p));
}
}
permissionManager.grantPermissions(permissions);
}