Package org.exist.xmldb

Examples of org.exist.xmldb.UserManagementService


        //create the /db/securityTest2/src collection
        Collection srcCollection = cms.createCollection("src");

        //create /db/securityTest2/parentCollection with owner "test1:users" and mode "rwxrwxrwx"
        Collection parentCollection = cms.createCollection("parentCollection");
        UserManagementService ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");
        ums.chmod("rwxrwxrwx");

        //now copy /db/securityTest2/src to /db/securityTest2/parentCollection/src
        //as "user3:guest", it should have it's group set to the primary group of "user3" i.e. 'guest'
        //as the collection is NOT setGid and it should NOT have it's setGid bit set
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test3", "test3");
        cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");
        cms.copy("src", "/db/securityTest2/parentCollection", "src");
        parentCollection = DatabaseManager.getCollection(baseUri + "/db/securityTest2/parentCollection", "test3", "test3");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");

        srcCollection = test.getChildCollection("src");
        final Collection destCollection = parentCollection.getChildCollection("src");

        final Permission permissions = ums.getPermissions(destCollection);
        assertEquals("guest", permissions.getGroup().getName());
        assertFalse(permissions.isSetGid());
    }
View Full Code Here


   
    @Test
    public void setGid_copyCollection_collectionGroupInheritedFromParent() throws XMLDBException {
        Collection test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test1", "test1");
        CollectionManagementServiceImpl cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");
        UserManagementService ums = (UserManagementService)test.getService("UserManagementService", "1.0");

        //create the /db/securityTest2/src collection with owner "test1:extusers" and default mode
        Collection srcCollection = cms.createCollection("src");
        ums = (UserManagementService)srcCollection.getService("UserManagementService", "1.0");
        ums.chgrp("extusers");

        //create /db/securityTest2/parentCollection with owner "test1:users" and mode "rwxrwsrwx"
        Collection parentCollection = cms.createCollection("parentCollection");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");
        ums.chmod("rwxrwsrwx");

        //now copy /db/securityTest2/src to /db/securityTest2/parentCollection/src
        //as "user3:guest", it should inherit the group ownership 'users' from the parent
        //collection which is setGid and it should have its setGid bit set
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test3", "test3");
        cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");
        cms.copy("src", "/db/securityTest2/parentCollection", "src");
        parentCollection = DatabaseManager.getCollection(baseUri + "/db/securityTest2/parentCollection", "test3", "test3");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");

        final Collection destCollection = parentCollection.getChildCollection("src");

        final Permission permissions = ums.getPermissions(destCollection);
        assertEquals("users", permissions.getGroup().getName());
        assertTrue(permissions.isSetGid());
    }
View Full Code Here

        resource.setContent("<test/>");
        test.storeResource(resource);

        //create /db/securityTest2/parentCollection with owner "test1:users" and mode "rwxrwxrwx"
        Collection parentCollection = cms.createCollection("parentCollection");
        UserManagementService ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");
        ums.chmod("rwxrwxrwx");

        //now copy /db/securityTest2/test.xml to /db/securityTest2/parentCollection/test.xml
        //as user3, it should have it's group set to the primary group of user3 i.e. 'guest'
        //as the collection is NOT setGid and it should not have the setGid bit
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test3", "test3");
        cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");
        cms.copyResource("test.xml", "/db/securityTest2/parentCollection", "test.xml");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");

        parentCollection = test.getChildCollection("parentCollection");
        resource = parentCollection.getResource("test.xml");

        final Permission permissions = ums.getPermissions(resource);
        assertEquals("guest", permissions.getGroup().getName());
        assertFalse(permissions.isSetGid());
    }
View Full Code Here

    @Test
    public void setGid_copyResource_resourceGroupInheritedFromParent() throws XMLDBException {
        Collection test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test1", "test1");
        CollectionManagementServiceImpl cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");       
        UserManagementService ums = (UserManagementService)test.getService("UserManagementService", "1.0");

        //create the /db/securityTest2/test.xml resource
        Resource resource = test.createResource("test.xml", XMLResource.RESOURCE_TYPE);
        resource.setContent("<test/>");
        test.storeResource(resource);
        ums.chgrp(resource, "extusers");

        //create /db/securityTest2/parentCollection with owner "test1:users" and mode "rwxrwsrwx"
        Collection parentCollection = cms.createCollection("parentCollection");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");
        ums.chmod("rwxrwsrwx");

        //now copy /db/securityTest2/test.xml to /db/securityTest2/parentCollection/test.xml
        //as "user3:guest", it should inherit the group ownership 'users' from the parent collection which is setGid
        //and it should NOT have its setGid bit set as it is a resource
        test = DatabaseManager.getCollection(baseUri + "/db/securityTest2", "test3", "test3");
        cms = (CollectionManagementServiceImpl)test.getService("CollectionManagementService", "1.0");
        cms.copyResource("test.xml", "/db/securityTest2/parentCollection", "test.xml");
        ums = (UserManagementService)parentCollection.getService("UserManagementService", "1.0");

        parentCollection = test.getChildCollection("parentCollection");
        resource = parentCollection.getResource("test.xml");

        final Permission permissions = ums.getPermissions(resource);
        assertEquals("users", permissions.getGroup().getName());
        assertFalse(permissions.isSetGid());
    }
View Full Code Here

     */
    @Before
    public void setup() {
        try {
            final Collection root = DatabaseManager.getCollection(baseUri + "/db", "admin", "");
            UserManagementService ums = (UserManagementService) root.getService("UserManagementService", "1.0");

            ums.chmod("rwxr-xr-x"); //ensure /db is always 755

            //remove accounts 'test1', 'test2' and 'test3'
            removeAccounts(ums, new String[]{"test1", "test2", "test3"});

            //remove group 'users'
            removeGroups(ums, new String[]{"users"});

            final Group group = new GroupAider("exist", "users");
            ums.addGroup(group);

            UserAider user = new UserAider("test1", group);
            user.setPassword("test1");
            ums.addAccount(user);
           
            final Group extGroup = new GroupAider("exist", "extusers");
            ums.addGroup(extGroup);
            ums.addAccountToGroup("test1", "extusers");

            user = new UserAider("test2", group);
            user.setPassword("test2");
            ums.addAccount(user);

            user = new UserAider("test3", ums.getGroup("guest"));
            user.setPassword("test3");
            ums.addAccount(user);

            // create a collection /db/securityTest1 as owned by "test1:users" and mode 0770
            CollectionManagementService cms = (CollectionManagementService)root.getService("CollectionManagementService", "1.0");
            Collection test = cms.createCollection("securityTest1");
            ums = (UserManagementService) test.getService("UserManagementService", "1.0");
            //change ownership to test1
            final Account test1 = ums.getAccount("test1");
            ums.chown(test1, "users");
            // full permissions for user and group, none for world
            ums.chmod(0770);

            test = DatabaseManager.getCollection(baseUri + "/db/securityTest1", "test1", "test1");

            // create a resource /db/securityTest1/test.xml owned by "test1:users" and mode 0770
            Resource resource = test.createResource("test.xml", XMLResource.RESOURCE_TYPE);
            resource.setContent("<test/>");
            test.storeResource(resource);
            ums.chmod(resource, 0770);

            resource = test.createResource("test.bin", BinaryResource.RESOURCE_TYPE);
            resource.setContent("binary-test".getBytes());
            test.storeResource(resource);
            ums.chmod(resource, 0770);

            // create a collection /db/securityTest2 as user "test1"
            cms = (CollectionManagementService)root.getService("CollectionManagementService", "1.0");
            Collection testCol2 = cms.createCollection("securityTest2");
            ums = (UserManagementService) testCol2.getService("UserManagementService", "1.0");
            //change ownership to test1
            ums.chown(test1, "users");
            // full permissions for user and group, none for world
            ums.chmod(0775);

            // create a collection /db/securityTest3 as user "test3"
            cms = (CollectionManagementService)root.getService("CollectionManagementService", "1.0");
            Collection testCol3 = cms.createCollection("securityTest3");
            ums = (UserManagementService) testCol3.getService("UserManagementService", "1.0");
            //change ownership to test3
            final Account test3 = ums.getAccount("test3");
            ums.chown(test3, "users");
            // full permissions for all
            ums.chmod(0777);
        } catch(final XMLDBException xmldbe) {
            xmldbe.printStackTrace();
            fail(xmldbe.getMessage());
        }
    }
View Full Code Here

            if(secTest3 != null) {
                secTest3.close();
                cms.removeCollection("securityTest3");
            }

            final UserManagementService ums = (UserManagementService) root.getService("UserManagementService", "1.0");

            //remove accounts 'test1', 'test2' and 'test3'
            removeAccounts(ums, new String[]{"test1", "test2", "test3"});

            //remove group 'users'
View Full Code Here

            this.resource = resource;
            addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent ev) {
                    try {
                        final UserManagementService service = (UserManagementService) collection
                            .getService("UserManagementService", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$
                        service.unlockResource(resource);
                    } catch (final XMLDBException e) {
                        e.printStackTrace();
                    }
                }
            });
View Full Code Here

     */
  public Sequence evalWithCollection(Collection collection, Sequence[] args, Sequence contextSequence)
  throws XPathException {

    try {
      final UserManagementService ums = (UserManagementService) collection.getService("UserManagementService", "1.0");
      final Resource res = collection.getResource(new AnyURIValue(args[1].getStringValue()).toXmldbURI().toString());
      if (res != null) {
        final String lockUser = ums.hasUserLock(res);
        if (lockUser != null && isCalledAs("clear-lock")) {
          ums.unlockResource(res);
        }
                return lockUser == null ? Sequence.EMPTY_SEQUENCE : new StringValue(lockUser);
      } else {
                logger.error("Unable to locate resource " + args[1].getStringValue());
          throw new XPathException(this, "Unable to locate resource " + args[1].getStringValue());
View Full Code Here

 
    @Override
    public Sequence evalWithCollection(final Collection collection, final Sequence[] args, final Sequence contextSequence) throws XPathException {

        try {
            final UserManagementService ums = (UserManagementService) collection.getService("UserManagementService", "1.0");
            final String user = args[1].getStringValue();
            final String group = args[2].getStringValue();
            final int mode = ((IntegerValue) args[3].convertTo(Type.INTEGER)).getInt();
           
            if (null == user || 0 == user.length()) {
                logger.error("Needs a valid user name, not: " + user);

                throw new XPathException(this, "Needs a valid user name, not: " + user);
            }
            if (null == group || 0 == group.length()) {
                logger.error("Needs a valid group name, not: " + group);

                throw new XPathException(this, "Needs a valid group name, not: " + group);
            }

            final Account usr = ums.getAccount(user);
            if (usr == null) {
                logger.error("Needs a valid user name, not: " + user);
               
                throw new XPathException(this, "Needs a valid user name, not: " + user);
            }

            ums.chown(usr, group);
            ums.chmod(mode);

        } catch(final XMLDBException xe) {
            throw new XPathException(this, "Unable to change collection permissions: " + xe.getMessage(), xe);
        }
View Full Code Here

        throw xPathException;
      } else {
            Collection collection = null;
        try {
                collection = new LocalCollection(contextUser, context.getBroker().getBrokerPool(), XmldbURI.ROOT_COLLECTION_URI, context.getAccessContext());
          final UserManagementService ums = (UserManagementService) collection.getService("UserManagementService", "1.0");
                final Account userObj = ums.getAccount(user);
                if (null != userObj)
                    {ums.removeAccount(userObj);}
        } catch (final XMLDBException xe) {
          throw new XPathException(this, "Failed to remove user " + user, xe);
            } finally {
                if (null != collection)
                    try { collection.close(); } catch (final XMLDBException e) { /* ignore */ }
View Full Code Here

TOP

Related Classes of org.exist.xmldb.UserManagementService

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.