Package org.exist.security

Examples of org.exist.security.Permission


        try {
            broker = pool.get(user);
            Collection collection = null;
            try {
              collection = broker.openCollection(resource, Lock.READ_LOCK);
              Permission perm = null;
              if (collection == null) {
          // TODO check XML/Binary resource
          // DocumentImpl doc = (DocumentImpl) broker.openDocument(resource, Lock.READ_LOCK);
                DocumentImpl doc = null;
                try {
                    doc = broker.getXMLResource(resource, Lock.READ_LOCK);
                    if (doc == null)
                        {throw new EXistException("document or collection " + resource + " not found");}
                    perm = doc.getPermissions();
                } finally {
                  if (doc != null)
                    {doc.getUpdateLock().release(Lock.READ_LOCK);}
                }
              } else {
                  perm = collection.getPermissionsNoLock();
              }
              final Permissions p = new Permissions();
              p.setOwner(perm.getOwner().getName());
              p.setGroup(perm.getGroup().getName());
              p.setPermissions(perm.getMode());
              return p;
            } finally {
              if (collection != null)
                {collection.release(Lock.READ_LOCK);}             
            }
View Full Code Here


                {throw new PermissionDeniedException(
                        "not allowed to read collection " + name);}
            final EntityPermissions[] result = new EntityPermissions[collection.getChildCollectionCount(broker)];
            XmldbURI child, path;
            Collection childColl;
            Permission perm;
            int cnt = 0;
            for (final Iterator<XmldbURI> i = collection.collectionIterator(broker); i.hasNext(); ) {
                child = i.next();
                path = name.append(child);
                childColl = broker.getCollection(path);
                perm = childColl.getPermissionsNoLock();
                result[cnt] = new EntityPermissions();
                result[cnt].setName(child.toString());
                result[cnt].setOwner(perm.getOwner().getName());
                result[cnt].setGroup(perm.getGroup().getName());
                result[cnt].setPermissions(perm.getMode());
                cnt++;
            }
            return new EntityPermissionsList(result);
        } catch (final Exception ex) {
            throw new RemoteException(ex.getMessage());
View Full Code Here

            if (!collection.getPermissionsNoLock().validate(user, Permission.READ))
                {throw new PermissionDeniedException(
                        "not allowed to read collection " + name);}
            final EntityPermissions[] result = new EntityPermissions[collection.getDocumentCount(broker)];
            DocumentImpl doc;
            Permission perm;
            int cnt = 0;
            for (final Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
                doc = i.next();
                perm = doc.getPermissions();
                result[cnt] = new EntityPermissions();
                result[cnt].setName(doc.getFileURI().toString());
                result[cnt].setOwner(perm.getOwner().getName());
                result[cnt].setGroup(perm.getGroup().getName());
                result[cnt].setPermissions(perm.getMode());
                cnt++;
            }
            return new EntityPermissionsList(result);
        } catch (final Exception ex) {
            throw new RemoteException(ex.getMessage());
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 Collection destCollection = EasyMock.createStrictMock(Collection.class);
        final Permission destPermissions = EasyMock.createStrictMock(Permission.class);

        final Collection newDestCollection = null;


        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);

        //no sub-documents
        expect(srcCollection.iterator(broker)).andReturn(new EmptyIterator<DocumentImpl>());

        //no sub-collections
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 Collection destCollection = EasyMock.createStrictMock(Collection.class);
        final Permission destPermissions = EasyMock.createStrictMock(Permission.class);

        final Collection newDestCollection = null; //EasyMock.createMock(Collection.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(false);

        //expectations for exception that should be thrown
        expect(srcCollection.getURI()).andReturn(src);
        expect(destCollection.getURI()).andReturn(dest);
        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 = null;


        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);

        //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 XmldbURI srcSubCollectionName = XmldbURI.create("sub-collection");
        final XmldbURI srcSubCollectionUri = src.append(srcSubCollectionName);
        final Collection srcSubCollection = EasyMock.createStrictMock(Collection.class);
        final Permission srcSubCollectionPermissions = EasyMock.createStrictMock(Permission.class);

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

        final Collection newDestCollection = null;

        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);

        //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 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);

        //no sub-documents
        expect(srcCollection.iterator(broker)).andReturn(new EmptyIterator<DocumentImpl>());

        //no sub-collections
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 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")
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 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(false);

        //expectations for exception that should be thrown
        expect(srcCollection.getURI()).andReturn(src);
        expect(newDestCollection.getURI()).andReturn(dest.append(newName));
        expect(broker.getSubject()).andReturn(subject);
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.