Search in sources :

Example 1 with Principal

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;
}
Also used : DavPrincipals(io.milton.principal.DavPrincipals) Permissions(nl.uva.cs.lobcder.auth.Permissions) HrefList(io.milton.http.values.HrefList) Principal(io.milton.principal.Principal) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal)

Aggregations

HrefList (io.milton.http.values.HrefList)1 DavPrincipals (io.milton.principal.DavPrincipals)1 Principal (io.milton.principal.Principal)1 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)1 Permissions (nl.uva.cs.lobcder.auth.Permissions)1