Search in sources :

Example 46 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class AbstractSecurityManagerRoundtripTest method checkGroupMembership.

@Test
public void checkGroupMembership() throws XMLDBException, PermissionDeniedException, EXistException, IOException, DatabaseConfigurationException {
    UserManagementService ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
    final String group1Name = "testGroup1";
    final String group2Name = "testGroup2";
    final String userName = "testUser";
    Group group1 = new GroupAider(group1Name);
    Group group2 = new GroupAider(group2Name);
    Account user = new UserAider(userName, group1);
    try {
        ums.addGroup(group1);
        ums.addGroup(group2);
        ums.addAccount(user);
        ums.getAccount(userName);
        user.addGroup(group2);
        ums.updateAccount(user);
        /**
         * RESTART THE SERVER **
         */
        restartServer();
        /**
         ***********************
         */
        ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
        user = ums.getAccount(userName);
        assertNotNull(user);
        Group defaultGroup = user.getDefaultGroup();
        assertNotNull(defaultGroup);
        assertEquals(group1Name, defaultGroup.getName());
        String[] groups = user.getGroups();
        assertNotNull(groups);
        assertEquals(2, groups.length);
        assertEquals(group1Name, groups[0]);
        assertEquals(group2Name, groups[1]);
    } finally {
        // cleanup
        final Account u1 = ums.getAccount(userName);
        if (u1 != null) {
            ums.removeAccount(u1);
        }
        final Group g1 = ums.getGroup(group1Name);
        if (g1 != null) {
            ums.removeGroup(g1);
        }
        final Group g2 = ums.getGroup(group2Name);
        if (g2 != null) {
            ums.removeGroup(g2);
        }
    }
}
Also used : UserManagementService(org.exist.xmldb.UserManagementService) GroupAider(org.exist.security.internal.aider.GroupAider) UserAider(org.exist.security.internal.aider.UserAider) Test(org.junit.Test)

Example 47 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class AbstractSecurityManagerRoundtripTest method checkPrimaryGroupStability.

@Test
public void checkPrimaryGroupStability() throws XMLDBException, PermissionDeniedException, EXistException, IOException, DatabaseConfigurationException {
    UserManagementService ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
    final String group1Name = "testGroupA";
    final String group2Name = "testGroupB";
    final String userName = "testUserA";
    Group group1 = new GroupAider(group1Name);
    Group group2 = new GroupAider(group2Name);
    // set users primary group as group1
    Account user = new UserAider(userName, group1);
    try {
        ums.addGroup(group1);
        ums.addGroup(group2);
        ums.addAccount(user);
        ums.getAccount(userName);
        user.addGroup(group2Name);
        ums.updateAccount(user);
        /**
         * RESTART THE SERVER **
         */
        restartServer();
        /**
         ***********************
         */
        ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
        user = ums.getAccount(userName);
        assertNotNull(user);
        Group defaultGroup = user.getDefaultGroup();
        assertNotNull(defaultGroup);
        assertEquals(group1Name, defaultGroup.getName());
        String[] groups = user.getGroups();
        assertNotNull(groups);
        assertEquals(2, groups.length);
        assertEquals(group1Name, groups[0]);
        assertEquals(group2Name, groups[1]);
    } finally {
        // cleanup
        final Account u1 = ums.getAccount(userName);
        if (u1 != null) {
            ums.removeAccount(u1);
        }
        final Group g1 = ums.getGroup(group1Name);
        if (g1 != null) {
            ums.removeGroup(g1);
        }
        final Group g2 = ums.getGroup(group2Name);
        if (g2 != null) {
            ums.removeGroup(g2);
        }
    }
}
Also used : UserManagementService(org.exist.xmldb.UserManagementService) GroupAider(org.exist.security.internal.aider.GroupAider) UserAider(org.exist.security.internal.aider.UserAider) Test(org.junit.Test)

Example 48 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class GetParameterTest method beforeClass.

@BeforeClass
public static void beforeClass() throws XMLDBException {
    root = DatabaseManager.getCollection("xmldb:exist://localhost:" + existWebServer.getPort() + "/xmlrpc/db", "admin", "");
    BinaryResource res = (BinaryResource) root.createResource(XQUERY_FILENAME, "BinaryResource");
    ((EXistResource) res).setMimeType("application/xquery");
    res.setContent(XQUERY);
    root.storeResource(res);
    UserManagementService ums = (UserManagementService) root.getService("UserManagementService", "1.0");
    ums.chmod(res, 0777);
}
Also used : EXistResource(org.exist.xmldb.EXistResource) BinaryResource(org.xmldb.api.modules.BinaryResource) UserManagementService(org.exist.xmldb.UserManagementService) BeforeClass(org.junit.BeforeClass)

Example 49 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class XmldbApiSecurityTest method addCollectionUserAce.

@Override
protected void addCollectionUserAce(final String collectionUri, final String user_uid, final String mode, final boolean allow, final String uid, final String pwd) throws ApiException {
    Collection parentCol = null;
    Collection subCol = null;
    try {
        final String parentColUri = collectionUri.substring(0, collectionUri.lastIndexOf('/'));
        final String subColName = collectionUri.substring(collectionUri.lastIndexOf('/') + 1);
        parentCol = DatabaseManager.getCollection(getBaseUri() + parentColUri, uid, pwd);
        final UserManagementService ums = (UserManagementService) parentCol.getService("UserManagementService", "1.0");
        final Permission subColPermissions = ums.getSubCollectionPermissions(parentCol, subColName);
        subCol = DatabaseManager.getCollection(getBaseUri() + collectionUri, uid, pwd);
        final List<ACEAider> aces = new ArrayList<>();
        final ACEAider ace = new ACEAider(allow ? ACLPermission.ACE_ACCESS_TYPE.ALLOWED : ACLPermission.ACE_ACCESS_TYPE.DENIED, ACLPermission.ACE_TARGET.USER, user_uid, SimpleACLPermission.aceSimpleSymbolicModeToInt(mode));
        aces.add(ace);
        ums.setPermissions(subCol, subColPermissions.getOwner().getName(), subColPermissions.getGroup().getName(), subColPermissions.getMode(), aces);
    } catch (final XMLDBException | PermissionDeniedException e) {
        throw new ApiException(e);
    } finally {
        if (subCol != null) {
            try {
                subCol.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
        if (parentCol != null) {
            try {
                parentCol.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : ACEAider(org.exist.security.internal.aider.ACEAider) ArrayList(java.util.ArrayList) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Example 50 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class XmldbApiSecurityTest method chownRes.

@Override
protected void chownRes(final String resourceUri, final String owner_uid, final String group_gid, final String uid, final String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + getCollectionUri(resourceUri), uid, pwd);
        final Resource resource = col.getResource(getResourceName(resourceUri));
        final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
        ums.chown(resource, ums.getAccount(owner_uid), group_gid);
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Aggregations

UserManagementService (org.exist.xmldb.UserManagementService)106 Collection (org.xmldb.api.base.Collection)91 Test (org.junit.Test)79 BinaryResource (org.xmldb.api.modules.BinaryResource)55 Resource (org.xmldb.api.base.Resource)52 XMLResource (org.xmldb.api.modules.XMLResource)51 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)26 XMLDBException (org.xmldb.api.base.XMLDBException)15 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)14 UserAider (org.exist.security.internal.aider.UserAider)9 GroupAider (org.exist.security.internal.aider.GroupAider)8 ResourceSet (org.xmldb.api.base.ResourceSet)8 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)7 EXistResource (org.exist.xmldb.EXistResource)6 Account (org.exist.security.Account)5 Before (org.junit.Before)3 BeforeClass (org.junit.BeforeClass)3 URISyntaxException (java.net.URISyntaxException)2 ExtendedResource (org.exist.xmldb.ExtendedResource)2 WindowAdapter (java.awt.event.WindowAdapter)1