Package org.exist.security

Examples of org.exist.security.Permission


        final XmldbURI src = XmldbURI.create("/db/test/source");
        final XmldbURI dest = XmldbURI.create("/db/test");
        final XmldbURI newName = XmldbURI.create("dest");

        final Collection srcCollection = EasyMock.createStrictMock(Collection.class);
        final Permission srcPermissions = EasyMock.createStrictMock(Permission.class);

        final DocumentImpl srcSubDocument = EasyMock.createStrictMock(DocumentImpl.class);
        final Permission srcSubDocumentPermissions = EasyMock.createStrictMock(Permission.class);

        final Collection destCollection = EasyMock.createStrictMock(Collection.class);
        final Permission destPermissions = EasyMock.createStrictMock(Permission.class);

        final Collection newDestCollection = EasyMock.createStrictMock(Collection.class);
        final Permission newDestPermissions = EasyMock.createStrictMock(Permission.class);

        final NativeBroker broker = EasyMock.createMockBuilder(NativeBroker.class)
                .addMockedMethod("getCollection")
                .addMockedMethod("getSubject")
                .createStrictMock();

        final Subject subject = EasyMock.createStrictMock(Subject.class);

        //grant EXECUTE and READ permissions on the src
        expect(srcCollection.getPermissionsNoLock()).andReturn(srcPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(srcPermissions.validate(subject, Permission.EXECUTE | Permission.READ)).andReturn(true);

        //grant EXECUTE and WRITE permission on the dest
        expect(broker.getCollection(dest)).andReturn(destCollection);
        final Capture<XmldbURI> newDestURICapture = new Capture<XmldbURI>();
        expect(broker.getCollection(capture(newDestURICapture))).andReturn(newDestCollection);
        expect(destCollection.getPermissionsNoLock()).andReturn(destPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(destPermissions.validate(subject, Permission.EXECUTE | Permission.WRITE)).andReturn(true);
        expect(newDestCollection.getPermissionsNoLock()).andReturn(newDestPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(newDestPermissions.validate(subject, Permission.EXECUTE | Permission.WRITE)).andReturn(true);

        //one sub-document with READ permission
        expect(srcCollection.iterator(broker)).andReturn(new ArrayIterator<DocumentImpl>(srcSubDocument));
        expect(srcSubDocument.getPermissions()).andReturn(srcSubDocumentPermissions);
        expect(broker.getSubject()).andReturn(subject);
View Full Code Here


        final XmldbURI src = XmldbURI.create("/db/test/source");
        final XmldbURI dest = XmldbURI.create("/db/test");
        final XmldbURI newName = XmldbURI.create("dest");

        final Collection srcCollection = EasyMock.createStrictMock(Collection.class);
        final Permission srcPermissions = EasyMock.createStrictMock(Permission.class);

        final DocumentImpl srcSubDocument = EasyMock.createStrictMock(DocumentImpl.class);
        final Permission srcSubDocumentPermissions = EasyMock.createStrictMock(Permission.class);

        final Collection destCollection = EasyMock.createStrictMock(Collection.class);
        final Permission destPermissions = EasyMock.createStrictMock(Permission.class);

        final Collection newDestCollection = EasyMock.createStrictMock(Collection.class);
        final Permission newDestPermissions = EasyMock.createStrictMock(Permission.class);

        final NativeBroker broker = EasyMock.createMockBuilder(NativeBroker.class)
                .addMockedMethod("getCollection")
                .addMockedMethod("getSubject")
                .createStrictMock();

        final Subject subject = EasyMock.createStrictMock(Subject.class);

        //grant EXECUTE and READ permissions on the src
        expect(srcCollection.getPermissionsNoLock()).andReturn(srcPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(srcPermissions.validate(subject, Permission.EXECUTE | Permission.READ)).andReturn(true);

        //grant EXECUTE and WRITE permission on the dest
        expect(broker.getCollection(dest)).andReturn(destCollection);
        final Capture<XmldbURI> newDestURICapture = new Capture<XmldbURI>();
        expect(broker.getCollection(capture(newDestURICapture))).andReturn(newDestCollection);
        expect(destCollection.getPermissionsNoLock()).andReturn(destPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(destPermissions.validate(subject, Permission.EXECUTE | Permission.WRITE)).andReturn(true);
        expect(newDestCollection.getPermissionsNoLock()).andReturn(newDestPermissions);
        expect(broker.getSubject()).andReturn(subject);
        expect(newDestPermissions.validate(subject, Permission.EXECUTE | Permission.WRITE)).andReturn(true);

        //one sub-document with READ permission
        expect(srcCollection.iterator(broker)).andReturn(new ArrayIterator<DocumentImpl>(srcSubDocument));
        expect(srcSubDocument.getPermissions()).andReturn(srcSubDocumentPermissions);
        expect(broker.getSubject()).andReturn(subject);
View Full Code Here

            final Vector<Map<String, Object>> docs = new Vector<Map<String, Object>>();
            final Vector<String> collections = new Vector<String>();
            if (collection.getPermissionsNoLock().validate(user, Permission.READ)) {
                for(final Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
                    final DocumentImpl doc = i.next();
                    final Permission perms = doc.getPermissions();
                   
                    final HashMap<String, Object> hash = new HashMap<String, Object>(4);
                    hash.put("name", doc.getFileURI().toString());
                    hash.put("owner", perms.getOwner().getName());
                    hash.put("group", perms.getGroup().getName());
                    hash.put("permissions", Integer.valueOf(perms.getMode()));
                    hash.put("type", doc.getResourceType() == DocumentImpl.BINARY_FILE ? "BinaryResource" : "XMLResource");
                    docs.addElement(hash);
                }
                for(final Iterator<XmldbURI> i = collection.collectionIterator(broker); i.hasNext(); ) {
                    collections.addElement(i.next().toString());
                }
            }
           
            final Permission perms = collection.getPermissionsNoLock();
            desc.put("collections", collections);
            desc.put("documents", docs);
            desc.put("name", collection.getURI().toString());
            desc.put("created", Long.toString(collection.getCreationTime()));
            desc.put("owner", perms.getOwner().getName());
            desc.put("group", perms.getGroup().getName());
            desc.put("permissions", Integer.valueOf(perms.getMode()));
           
            return desc;
        } finally {
            if(collection != null) {
                collection.release(Lock.READ_LOCK);
View Full Code Here

            doc = broker.getXMLResource(resourceUri, Lock.READ_LOCK);
            if (doc == null) {
                LOG.debug("document " + resourceUri + " not found!");
                return hash;
            }
            final Permission perms = doc.getPermissions();
            hash.put("name", resourceUri.toString());
            hash.put("owner", perms.getOwner().getName());
            hash.put("group", perms.getGroup().getName());
            hash.put("permissions", Integer.valueOf(perms.getMode()));
           
            if(perms instanceof ACLPermission) {
                hash.put("acl", getACEs(perms));
            }
View Full Code Here

            if (collection.getPermissionsNoLock().validate(user, Permission.READ)) {
                for (final Iterator<XmldbURI> i = collection.collectionIterator(broker); i.hasNext(); ) {
                    collections.add(i.next().toString());
                }
            }
            final Permission perms = collection.getPermissionsNoLock();
            desc.put("collections", collections);
            desc.put("name", collection.getURI().toString());
            desc.put("created", Long.toString(collection.getCreationTime()));
            desc.put("owner", perms.getOwner().getName());
            desc.put("group", perms.getGroup().getName());
            desc.put("permissions", Integer.valueOf(perms.getMode()));
            if(perms instanceof ACLPermission) {
                desc.put("acl", getACEs(perms));
            }
            return desc;
        } finally {
View Full Code Here

        Collection collection = null;

        try {
            broker = factory.getBrokerPool().get(user);
            collection = broker.openCollection(uri, Lock.READ_LOCK);
            Permission perm = null;
            if(collection == null) {
                DocumentImpl doc = null;
                try {
                    doc = broker.getXMLResource(uri, Lock.READ_LOCK);
                    if(doc == null) {
                        throw new EXistException("document or collection " + uri + " not found");
                    }
                    perm = doc.getPermissions();
                } finally {
                    if(doc != null) {
                        doc.getUpdateLock().release(Lock.READ_LOCK);
                    }
                }
            } else {
                perm = collection.getPermissionsNoLock();
            }

            final HashMap<String, Object> result = new HashMap<String, Object>();
            result.put("owner", perm.getOwner().getName());
            result.put("group", perm.getGroup().getName());
            result.put("permissions", Integer.valueOf(perm.getMode()));

            if(perm instanceof ACLPermission) {
                result.put("acl", getACEs(perm));
            }
            return result;
View Full Code Here

        Collection collection = null;

        try {
            broker = factory.getBrokerPool().get(user);
            collection = broker.openCollection(uri, Lock.READ_LOCK);
            Permission perm = null;
            if(collection == null) {
                throw new EXistException("collection " + uri + " not found");
            } else {
                perm = collection.getSubCollectionEntry(broker, name).getPermissions();
            }

            final HashMap<String, Object> result = new HashMap<String, Object>();
            result.put("owner", perm.getOwner().getName());
            result.put("group", perm.getGroup().getName());
            result.put("permissions", Integer.valueOf(perm.getMode()));

            if(perm instanceof ACLPermission) {
                result.put("acl", getACEs(perm));
            }
            return result;
View Full Code Here

        Collection collection = null;

        try {
            broker = factory.getBrokerPool().get(user);
            collection = broker.openCollection(uri, Lock.READ_LOCK);
            Permission perm = null;
            if(collection == null) {
                throw new EXistException("collection " + uri + " not found");
            } else {
                perm = collection.getResourceEntry(broker, name).getPermissions();
            }

            final HashMap<String, Object> result = new HashMap<String, Object>();
            result.put("owner", perm.getOwner().getName());
            result.put("group", perm.getGroup().getName());
            result.put("permissions", Integer.valueOf(perm.getMode()));

            if(perm instanceof ACLPermission) {
                result.put("acl", getACEs(perm));
            }
            return result;
View Full Code Here

            final HashMap<String, List<Object>> result = new HashMap<String, List<Object>>(collection.getDocumentCount(broker));

            for (final Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
              final DocumentImpl doc = i.next();

                final Permission perm = doc.getPermissions();

                final List<Object> tmp = new ArrayList<Object>(3);
                tmp.add(perm.getOwner().getName());
                tmp.add(perm.getGroup().getName());
                tmp.add(Integer.valueOf(perm.getMode()));
                if(perm instanceof ACLPermission) {
                    tmp.add(getACEs(perm));
                }
                result.put(doc.getFileURI().toString(), tmp);
            }
View Full Code Here

            final HashMap<XmldbURI, List<Object>> result = new HashMap<XmldbURI, List<Object>>(collection.getChildCollectionCount(broker));
            for (final Iterator<XmldbURI> i = collection.collectionIterator(broker); i.hasNext(); ) {
              final XmldbURI child = i.next();
              final XmldbURI path = collUri.append(child);
                final Collection childColl = broker.getCollection(path);
                final Permission perm = childColl.getPermissionsNoLock();
                final List<Object> tmp = new ArrayList<Object>(3);
                tmp.add(perm.getOwner().getName());
                tmp.add(perm.getGroup().getName());
                tmp.add(Integer.valueOf(perm.getMode()));
                if(perm instanceof ACLPermission) {
                    tmp.add(getACEs(perm));
                }
                result.put(child, tmp);
            }
View Full Code Here

TOP

Related Classes of org.exist.security.Permission

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.