throw new GWTJahiaServiceException(
new StringBuilder(path).append(" could not be accessed :\n").append(e.toString()).toString());
}
Map<String, List<String[]>> m = node.getAclEntries();
GWTJahiaNodeACL acl = new GWTJahiaNodeACL();
try {
Map<String, List<JCRNodeWrapper>> roles = node.getAvailableRoles();
Map<String, List<String>> dependencies = new HashMap<String, List<String>>();
Map<String, List<String>> availablePermissions = new HashMap<String, List<String>>();
Set<String> allAvailablePermissions = new HashSet<String>();
Map<String, String> labels = new HashMap<String, String>();
Map<String, String> tooltips = new HashMap<String, String>();
for (Map.Entry<String, List<JCRNodeWrapper>> entry : roles.entrySet()) {
availablePermissions.put(entry.getKey(), new ArrayList<String>());
for (JCRNodeWrapper nodeWrapper : entry.getValue()) {
String nodeName = nodeWrapper.getName();
allAvailablePermissions.add(nodeName);
availablePermissions.get(entry.getKey()).add(nodeName);
if (nodeWrapper.hasProperty("jcr:title")) {
labels.put(nodeName, nodeWrapper.getProperty("jcr:title").getString());
} else {
labels.put(nodeName, nodeName);
}
if (nodeWrapper.hasProperty("jcr:description")) {
tooltips.put(nodeName, nodeWrapper.getProperty("jcr:description").getString());
}
List<String> d = new ArrayList<String>();
if (nodeWrapper.hasProperty("j:dependencies")) {
for (Value value : nodeWrapper.getProperty("j:dependencies").getValues()) {
d.add(((JCRValueWrapper) value).getNode().getName());
}
}
dependencies.put(nodeName, d);
}
}
acl.setAvailablePermissions(availablePermissions);
acl.setPermissionLabels(labels);
acl.setPermissionTooltips(tooltips);
acl.setPermissionsDependencies(dependencies);
List<GWTJahiaNodeACE> aces = new ArrayList<GWTJahiaNodeACE>();
Map<String, GWTJahiaNodeACE> map = new HashMap<String, GWTJahiaNodeACE>();
JahiaGroupManagerService groupManagerService = ServicesRegistry.getInstance().getJahiaGroupManagerService();
for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext();) {
String principal = iterator.next();
GWTJahiaNodeACE ace = new GWTJahiaNodeACE();
ace.setPrincipalType(principal.charAt(0));
ace.setPrincipal(principal.substring(2));
if (ace.getPrincipalType() == 'g') {
JahiaGroup g = groupManagerService.lookupGroup(node.getResolveSite().getID(), ace.getPrincipal());
if (g == null) {
g = groupManagerService.lookupGroup(ace.getPrincipal());
}
if (g != null) {
ace.setHidden(g.isHidden());
ace.setPrincipalKey(g.getGroupKey());
} else {
continue;
}
} else {
JahiaUser u = ServicesRegistry.getInstance().getJahiaUserManagerService().lookupUser(ace.getPrincipal());
if (u != null) {
ace.setPrincipalKey(u.getUserKey());
} else {
continue;
}
}
map.put(principal, ace);
List<String[]> st = m.get(principal);
Map<String, Boolean> perms = new HashMap<String, Boolean>();
Map<String, Boolean> inheritedPerms = new HashMap<String, Boolean>();
String inheritedFrom = null;
for (String[] strings : st) {
String pathFrom = strings[0];
String aclType = strings[1];
String role = strings[2];
if (!newAcl && path.equals(pathFrom)) {
perms.put(role, aclType.equals("GRANT"));
} else if (!inheritedPerms.containsKey(role)) {
if (inheritedFrom == null || inheritedFrom.length() < pathFrom.length()) {
inheritedFrom = pathFrom;
}
inheritedPerms.put(role, aclType.equals("GRANT"));
}
}
if (!CollectionUtils.intersection(allAvailablePermissions, inheritedPerms.keySet()).isEmpty() ||
!CollectionUtils.intersection(allAvailablePermissions, perms.keySet()).isEmpty()) {
aces.add(ace);
ace.setInheritedFrom(inheritedFrom);
ace.setInheritedPermissions(inheritedPerms);
ace.setPermissions(perms);
ace.setInherited(perms.isEmpty());
}
}
boolean aclInheritanceBreak = node.getAclInheritanceBreak();
acl.setBreakAllInheritance(aclInheritanceBreak);
if (aclInheritanceBreak) {
m = node.getParent().getAclEntries();
for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext();) {
String principal = iterator.next();
GWTJahiaNodeACE ace = map.get(principal);
if (ace == null) {
ace = new GWTJahiaNodeACE();
map.put(principal, ace);
aces.add(ace);
ace.setPrincipalType(principal.charAt(0));
ace.setPrincipal(principal.substring(2));
if (ace.getPrincipalType() == 'g') {
JahiaGroup g = groupManagerService.lookupGroup(node.getResolveSite().getID(),
ace.getPrincipal());
if (g == null) {
g = groupManagerService.lookupGroup(ace.getPrincipal());
}
if (g != null) {
ace.setHidden(g.isHidden());
}
}
ace.setPermissions(new HashMap<String, Boolean>());
}
Map<String, Boolean> inheritedPerms = new HashMap<String, Boolean>();
List<String[]> st = m.get(principal);
String inheritedFrom = null;
for (String[] strings : st) {
String pathFrom = strings[0];
String aclType = strings[1];
String role = strings[2];
if (!inheritedPerms.containsKey(role)) {
if (inheritedFrom == null || inheritedFrom.length() < pathFrom.length()) {
inheritedFrom = pathFrom;
}
inheritedPerms.put(role, aclType.equals("GRANT"));
}
}
ace.setInheritedFrom(inheritedFrom);
ace.setInheritedPermissions(inheritedPerms);
}
}
acl.setAce(aces);
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
}
return acl;