Search in sources :

Example 21 with ACEAider

use of org.exist.security.internal.aider.ACEAider in project exist by eXist-db.

the class RemoteUserManagementService method listCollectionPermissions.

@Override
public Permission[] listCollectionPermissions() throws XMLDBException {
    try {
        final List<Object> params = new ArrayList<>();
        params.add(collection.getPath());
        final Map result = (Map) collection.execute("listCollectionPermissions", params);
        final Permission[] perm = new Permission[result.size()];
        final String[] collections = collection.listChildCollections();
        Object[] t;
        for (int i = 0; i < collections.length; i++) {
            t = (Object[]) result.get(collections[i]);
            final String owner = (String) t[0];
            final String group = (String) t[1];
            final int mode = (Integer) t[2];
            final Stream<ACEAider> aces = extractAces(t[3]);
            perm[i] = getPermission(owner, group, mode, aces);
        }
        return perm;
    } catch (final PermissionDeniedException pde) {
        throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, pde.getMessage(), pde);
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) ACEAider(org.exist.security.internal.aider.ACEAider) ACLPermission(org.exist.security.ACLPermission) Permission(org.exist.security.Permission) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Example 22 with ACEAider

use of org.exist.security.internal.aider.ACEAider in project exist by eXist-db.

the class RemoteUserManagementService method getPermissions.

@Override
public Permission getPermissions(final Collection coll) throws XMLDBException {
    if (coll == null) {
        throw new XMLDBException(ErrorCodes.INVALID_COLLECTION, "collection is null");
    }
    try {
        final List<Object> params = new ArrayList<>();
        params.add(((RemoteCollection) coll).getPath());
        final Map result = (Map) collection.execute("getPermissions", params);
        final String owner = (String) result.get("owner");
        final String group = (String) result.get("group");
        final int mode = (Integer) result.get("permissions");
        final Stream<ACEAider> aces = extractAces(result.get("acl"));
        return getPermission(owner, group, mode, aces);
    } catch (final PermissionDeniedException pde) {
        throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, pde.getMessage(), pde);
    }
}
Also used : ACEAider(org.exist.security.internal.aider.ACEAider) XMLDBException(org.xmldb.api.base.XMLDBException) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Example 23 with ACEAider

use of org.exist.security.internal.aider.ACEAider in project exist by eXist-db.

the class LocalUserManagementService method getAces.

private Optional<List<ACEAider>> getAces(@Nullable final Permission permission) {
    final Optional<List<ACEAider>> maybeAces;
    if (permission != null && permission instanceof ACLPermission) {
        final ACLPermission aclPerm = (ACLPermission) permission;
        final List<ACEAider> aces = new ArrayList<>(aclPerm.getACECount());
        for (int i = 0; i < aclPerm.getACECount(); i++) {
            aces.add(new ACEAider(aclPerm.getACEAccessType(i), aclPerm.getACETarget(i), aclPerm.getACEWho(i), aclPerm.getACEMode(i)));
        }
        maybeAces = Optional.of(aces);
    } else {
        maybeAces = Optional.empty();
    }
    return maybeAces;
}
Also used : ACEAider(org.exist.security.internal.aider.ACEAider)

Aggregations

ACEAider (org.exist.security.internal.aider.ACEAider)23 PermissionDeniedException (org.exist.security.PermissionDeniedException)8 XMLDBException (org.xmldb.api.base.XMLDBException)8 ACLPermission (org.exist.security.ACLPermission)7 Permission (org.exist.security.Permission)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)3 Collection (org.exist.collections.Collection)3 BrokerPool (org.exist.storage.BrokerPool)3 DBBroker (org.exist.storage.DBBroker)3 Txn (org.exist.storage.txn.Txn)3 ACE_ACCESS_TYPE (org.exist.security.ACLPermission.ACE_ACCESS_TYPE)2 ACE_TARGET (org.exist.security.ACLPermission.ACE_TARGET)2 BeforeClass (org.junit.BeforeClass)2 Collection (org.xmldb.api.base.Collection)2 Either (com.evolvedbinary.j8fu.Either)1 ConsumerE (com.evolvedbinary.j8fu.function.ConsumerE)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1