Source:
public static boolean hasPermission(String userId, List<String> permissions, boolean isNeedFullAccess) { try { OrganizationService organizationService = WCMCoreUtils.getService(OrganizationService.class); startRequest(organizationService); Identity identity = ConversationState.getCurrent().getIdentity(); Collection<?> memberships = null; if (userId.equals(identity.getUserId())){ Collection<MembershipEntry> membershipsEntries = identity.getMemberships(); HashSet<MembershipImpl> membershipsHash = new HashSet<MembershipImpl>(); for (MembershipEntry membershipEntry : membershipsEntries) { MembershipImpl m = new MembershipImpl(); m.setGroupId(membershipEntry.getGroup()); m.setMembershipType(membershipEntry.getMembershipType()); m.setUserName(userId); membershipsHash.add(m); } memberships = new LinkedList(membershipsHash); } else { memberships = organizationService.getMembershipHandler().findMembershipsByUser(userId); } String userMembershipTmp; Membership userMembership; int count = 0; String permissionTmp = ""; for (String permission : permissions) { if (!permissionTmp.equals(permission)) count = 0; for (Object userMembershipObj : memberships) { userMembership = (Membership) userMembershipObj; if (permission.equals(userMembership.getUserName())) { return true; } else if ("any".equals(permission)) { if (isNeedFullAccess) { count++; if (count == 4) return true; } else return true; } else if (permission.startsWith("*") && permission.contains(userMembership.getGroupId())) { if (isNeedFullAccess) { count++; if (count == 4) return true; } else return true; } else { userMembershipTmp = userMembership.getMembershipType() + ":" + userMembership.getGroupId(); if (permission.equals(userMembershipTmp)) { if (isNeedFullAccess) { count++; if (count == 4) return true; } else return true; } } } permissionTmp = permission; } endRequest(organizationService); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("hasPermission() failed because of ", e); } } return false; }

Target:
public static boolean hasPermission(String userId, List<String> permissions, boolean isNeedFullAccess) { if (userId == null || userId.length() == 0) { return false; } try { OrganizationService organizationService = WCMCoreUtils.getService(OrganizationService.class); startRequest(organizationService); Identity identity = ConversationState.getCurrent().getIdentity(); Collection<?> memberships = null; if (userId.equals(identity.getUserId())){ Collection<MembershipEntry> membershipsEntries = identity.getMemberships(); HashSet<MembershipImpl> membershipsHash = new HashSet<MembershipImpl>(); for (MembershipEntry membershipEntry : membershipsEntries) { MembershipImpl m = new MembershipImpl(); m.setGroupId(membershipEntry.getGroup()); m.setMembershipType(membershipEntry.getMembershipType()); m.setUserName(userId); membershipsHash.add(m); } memberships = new LinkedList(membershipsHash); } else { memberships = organizationService.getMembershipHandler().findMembershipsByUser(userId); } String userMembershipTmp; Membership userMembership; int count = 0; String permissionTmp = ""; for (String permission : permissions) { if (!permissionTmp.equals(permission)) count = 0; for (Object userMembershipObj : memberships) { userMembership = (Membership) userMembershipObj; if (permission.equals(userMembership.getUserName())) { return true; } else if ("any".equals(permission)) { if (isNeedFullAccess) { count++; if (count == 4) return true; } else return true; } else if (permission.startsWith("*") && permission.contains(userMembership.getGroupId())) { if (isNeedFullAccess) { count++; if (count == 4) return true; } else return true; } else { userMembershipTmp = userMembership.getMembershipType() + ":" + userMembership.getGroupId(); if (permission.equals(userMembershipTmp)) { if (isNeedFullAccess) { count++; if (count == 4) return true; } else return true; } } } permissionTmp = permission; } endRequest(organizationService); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("hasPermission() failed because of ", e); } } return false; }