Search in sources :

Example 1 with GroupAider

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

the class AddGroupTask method execute.

/* (non-Javadoc)
     * @see org.apache.tools.ant.Task#execute()
     */
public void execute() throws BuildException {
    super.execute();
    if (name == null) {
        throw (new BuildException("Must specify a group name"));
    }
    try {
        final GroupAider group = new GroupAider(name);
        log("Adding group " + name, Project.MSG_INFO);
        service.addGroup(group);
    } catch (final XMLDBException e) {
        final String msg = "XMLDB exception caught: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException) GroupAider(org.exist.security.internal.aider.GroupAider)

Example 2 with GroupAider

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

the class SecurityManagerTest method setup.

@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException {
    final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
    final SecurityManager securityManager = brokerPool.getSecurityManager();
    // create the personal group
    final Group group = new GroupAider(TEST_GROUP_NAME);
    group.setMetadataValue(EXistSchemaType.DESCRIPTION, "Personal group for " + TEST_GROUP_NAME);
    try (final DBBroker broker = brokerPool.get(Optional.of(securityManager.getSystemSubject()))) {
        securityManager.addGroup(broker, group);
        // create the account
        final Account user = new UserAider(TEST_USER_NAME);
        user.setPassword(TEST_USER_NAME);
        user.addGroup(TEST_GROUP_NAME);
        securityManager.addAccount(user);
        // add the new account as a manager of their personal group
        final Group personalGroup = securityManager.getGroup(TEST_GROUP_NAME);
        personalGroup.addManager(securityManager.getAccount(TEST_USER_NAME));
        securityManager.updateGroup(personalGroup);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) GroupAider(org.exist.security.internal.aider.GroupAider) UserAider(org.exist.security.internal.aider.UserAider) BrokerPool(org.exist.storage.BrokerPool) BeforeClass(org.junit.BeforeClass)

Example 3 with GroupAider

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

the class FnCollectionSecurityTest method createUser.

private static void createUser(final SecurityManager securityManager, final DBBroker broker, final String username) throws PermissionDeniedException, EXistException {
    final UserAider user = new UserAider(username);
    user.setPassword(username);
    Group group = new GroupAider(username);
    group.setMetadataValue(EXistSchemaType.DESCRIPTION, "Personal group for " + username);
    group.addManager(user);
    securityManager.addGroup(broker, group);
    // add the personal group as the primary group
    user.addGroup(username);
    securityManager.addAccount(user);
    // add the new account as a manager of their personal group
    group = securityManager.getGroup(username);
    group.addManager(securityManager.getAccount(username));
    securityManager.updateGroup(group);
}
Also used : UserAider(org.exist.security.internal.aider.UserAider) GroupAider(org.exist.security.internal.aider.GroupAider)

Example 4 with GroupAider

use of org.exist.security.internal.aider.GroupAider 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 5 with GroupAider

use of org.exist.security.internal.aider.GroupAider 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)

Aggregations

GroupAider (org.exist.security.internal.aider.GroupAider)23 UserAider (org.exist.security.internal.aider.UserAider)15 UserManagementService (org.exist.xmldb.UserManagementService)8 XMLDBException (org.xmldb.api.base.XMLDBException)7 SecurityManager (org.exist.security.SecurityManager)6 DBBroker (org.exist.storage.DBBroker)5 EXistException (org.exist.EXistException)4 PermissionDeniedException (org.exist.security.PermissionDeniedException)4 Test (org.junit.Test)4 Collection (org.exist.collections.Collection)3 Group (org.exist.security.Group)3 BrokerPool (org.exist.storage.BrokerPool)3 Txn (org.exist.storage.txn.Txn)3 IOException (java.io.IOException)2 LockedDocumentMap (org.exist.storage.lock.LockedDocumentMap)2 Before (org.junit.Before)2 Collection (org.xmldb.api.base.Collection)2 Either (com.evolvedbinary.j8fu.Either)1 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1