use of io.milton.principal.Principal in project lobcder by skoulouzis.
the class WebDataResource method getAccessControlList.
@Override
public Map<Principal, List<Priviledge>> getAccessControlList() {
Logger.getLogger(WebDataResource.class.getName()).log(Level.FINE, "getAccessControlList for {0}", getPath());
Permissions resourcePermission;
HashMap<Principal, List<Priviledge>> acl = new HashMap<>();
try {
// Do the mapping
Principal p = new DavPrincipals.AbstractDavPrincipal(getPrincipalURL()) {
@Override
public boolean matches(Auth auth, Resource current) {
return true;
}
};
resourcePermission = getPermissions();
List<Priviledge> perm = new ArrayList<>();
if (getPrincipal().canRead(resourcePermission)) {
perm.add(Priviledge.READ);
perm.add(Priviledge.READ_ACL);
perm.add(Priviledge.READ_CONTENT);
perm.add(Priviledge.READ_CURRENT_USER_PRIVILEDGE);
perm.add(Priviledge.READ_PROPERTIES);
}
if (getPrincipal().canWrite(resourcePermission)) {
perm.add(Priviledge.WRITE);
perm.add(Priviledge.BIND);
perm.add(Priviledge.UNBIND);
perm.add(Priviledge.UNLOCK);
perm.add(Priviledge.WRITE_ACL);
perm.add(Priviledge.WRITE_CONTENT);
perm.add(Priviledge.WRITE_PROPERTIES);
}
acl.put(p, perm);
for (String r : resourcePermission.getRead()) {
perm = new ArrayList<>();
p = new DavPrincipals.AbstractDavPrincipal(getRoleUrlPrefix() + r) {
@Override
public boolean matches(Auth auth, Resource current) {
return true;
}
};
perm.add(Priviledge.READ);
perm.add(Priviledge.READ_ACL);
perm.add(Priviledge.READ_CONTENT);
perm.add(Priviledge.READ_CURRENT_USER_PRIVILEDGE);
perm.add(Priviledge.READ_PROPERTIES);
acl.put(p, perm);
}
for (String r : resourcePermission.getWrite()) {
perm = new ArrayList<>();
p = new DavPrincipals.AbstractDavPrincipal(getRoleUrlPrefix() + r) {
@Override
public boolean matches(Auth auth, Resource current) {
return true;
}
};
perm.add(Priviledge.WRITE);
perm.add(Priviledge.BIND);
perm.add(Priviledge.UNBIND);
perm.add(Priviledge.UNLOCK);
perm.add(Priviledge.WRITE_ACL);
perm.add(Priviledge.WRITE_CONTENT);
perm.add(Priviledge.WRITE_PROPERTIES);
acl.put(p, perm);
}
} catch (SQLException e) {
Logger.getLogger(WebDataResource.class.getName()).log(Level.SEVERE, "Cannot read permissions for resource " + getPath(), e);
}
return acl;
}
Aggregations