List<AccessRights> l = (List<AccessRights>) policyCache.retrieve(cacheKey);
if (l == null) {
l = new ArrayList<AccessRights>();
List resourcePermissions = getAccessRights();
AccessRights resourcePermission = null;
AccessRight accessRight = null;
/*
* First iterate through all of the resource permissions looking for
* what is visible at the top level.
*/
for (Iterator i = resourcePermissions.iterator(); i.hasNext();) {
resourcePermission = (AccessRights) i.next();
if (permissionClass == null
|| permissionClass.equals(resourcePermission
.getAccessRightsClass())) {
// Check the user is allowed
if (isPrincipalAllowed(
user, resourcePermission, true)) {
// Iterator through all permissions in the resource
for (Iterator j = resourcePermission
.getAccessRights().iterator(); j.hasNext();) {
accessRight = (AccessRight) j
.next();
// Until the resource type matches
if (resourceType == null
|| resourceType
.equals(accessRight
.getResourceType())) {
// Until at least one permission matches
if (permission == null
|| permission.getId() == accessRight
.getPermission()
.getId()) {
l.add(resourcePermission);
break;
}