Search in sources :

Example 56 with SecurityManager

use of org.exist.security.SecurityManager in project exist by eXist-db.

the class PermissionsFunctionChmodTest method prepareDb.

@BeforeClass
public static void prepareDb() throws EXistException, PermissionDeniedException, IOException, TriggerException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final SecurityManager sm = pool.getSecurityManager();
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Collection collection = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        PermissionFactory.chmod(broker, collection, Optional.of(511), Optional.empty());
        broker.saveCollection(transaction, collection);
        createUser(broker, sm, USER1_NAME, USER1_PWD);
        createUser(broker, sm, USER2_NAME, USER2_PWD);
        final Group otherGroup = new GroupAider(OTHER_GROUP_NAME);
        sm.addGroup(broker, otherGroup);
        final Account user1 = sm.getAccount(USER1_NAME);
        user1.addGroup(OTHER_GROUP_NAME);
        sm.updateAccount(user1);
        final Account user2 = sm.getAccount(USER2_NAME);
        user2.addGroup(OTHER_GROUP_NAME);
        sm.updateAccount(user2);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) GroupAider(org.exist.security.internal.aider.GroupAider) BrokerPool(org.exist.storage.BrokerPool)

Example 57 with SecurityManager

use of org.exist.security.SecurityManager in project exist by eXist-db.

the class GroupManagementFunctionRemoveGroupTest method deleteUsersSupplementalGroups.

@Test
public void deleteUsersSupplementalGroups() throws PermissionDeniedException, EXistException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final SecurityManager sm = pool.getSecurityManager();
    // create user with personal group as primary group
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Account user1 = createUser(broker, sm, USER1_NAME, USER1_PWD);
        final Group otherGroup1 = createGroup(broker, sm, OTHER_GROUP1_NAME);
        addUserToGroup(sm, user1, otherGroup1);
        final Group otherGroup2 = createGroup(broker, sm, OTHER_GROUP2_NAME);
        addUserToGroup(sm, user1, otherGroup2);
        transaction.commit();
    }
    // check that the user is as we expect
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Account user1 = sm.getAccount(USER1_NAME);
        assertEquals(USER1_NAME, user1.getPrimaryGroup());
        final String[] user1Groups = user1.getGroups();
        assertArrayEquals(new String[] { USER1_NAME, OTHER_GROUP1_NAME, OTHER_GROUP2_NAME }, user1Groups);
        for (final String user1Group : user1Groups) {
            assertNotNull(sm.getGroup(user1Group));
        }
        transaction.commit();
    }
    // attempt to remove the supplemental groups of the user
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        assertTrue(sm.deleteGroup(OTHER_GROUP1_NAME));
        assertTrue(sm.deleteGroup(OTHER_GROUP2_NAME));
        transaction.commit();
    }
    // check that the user no longer has the supplemental groups
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Account user1 = sm.getAccount(USER1_NAME);
        final String user1PrimaryGroup = user1.getPrimaryGroup();
        assertEquals(USER1_NAME, user1PrimaryGroup);
        final String[] user1Groups = user1.getGroups();
        assertArrayEquals(new String[] { USER1_NAME, OTHER_GROUP1_NAME, OTHER_GROUP2_NAME }, user1Groups);
        for (final String user1Group : user1Groups) {
            if (user1PrimaryGroup.equals(user1Group)) {
                assertNotNull(sm.getGroup(user1Group));
            } else {
                // cannot retrieve groups which have been deleted!
                assertNull(sm.getGroup(user1Group));
            }
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 58 with SecurityManager

use of org.exist.security.SecurityManager in project exist by eXist-db.

the class PermissionsFunctionChownTest method cleanupDb.

@AfterClass
public static void cleanupDb() throws EXistException, PermissionDeniedException, IOException, TriggerException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final SecurityManager sm = pool.getSecurityManager();
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        removeUser(sm, USER2_NAME);
        removeUser(sm, USER1_NAME);
        removeGroup(sm, OTHER_GROUP_NAME);
        if (sm.hasAccount(USERRM_NAME)) {
            removeUser(sm, USERRM_NAME);
        }
        removeCollection(broker, transaction, TestConstants.TEST_COLLECTION_URI);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 59 with SecurityManager

use of org.exist.security.SecurityManager in project exist by eXist-db.

the class PersistentLoginFunctions method login.

private boolean login(final String user, final String pass) throws XPathException {
    try {
        final SecurityManager sm = BrokerPool.getInstance().getSecurityManager();
        final Subject subject = sm.authenticate(user, pass);
        // switch the user of the current broker
        switchUser(subject);
        return true;
    } catch (final AuthenticationException | EXistException e) {
        return false;
    }
}
Also used : SecurityManager(org.exist.security.SecurityManager) AuthenticationException(org.exist.security.AuthenticationException) EXistException(org.exist.EXistException) Subject(org.exist.security.Subject)

Example 60 with SecurityManager

use of org.exist.security.SecurityManager in project exist by eXist-db.

the class LocalUserManagementService method getAccounts.

@Override
public Account[] getAccounts() throws XMLDBException {
    return withDb((broker, transaction) -> {
        final SecurityManager sm = broker.getBrokerPool().getSecurityManager();
        final java.util.Collection<Account> users = sm.getUsers();
        return users.toArray(new Account[0]);
    });
}
Also used : SecurityManager(org.exist.security.SecurityManager) java.util(java.util)

Aggregations

SecurityManager (org.exist.security.SecurityManager)68 DBBroker (org.exist.storage.DBBroker)22 Txn (org.exist.storage.txn.Txn)16 Account (org.exist.security.Account)15 BrokerPool (org.exist.storage.BrokerPool)15 Subject (org.exist.security.Subject)12 EXistException (org.exist.EXistException)11 PermissionDeniedException (org.exist.security.PermissionDeniedException)9 XPathException (org.exist.xquery.XPathException)9 AuthenticationException (org.exist.security.AuthenticationException)8 GroupAider (org.exist.security.internal.aider.GroupAider)6 Collection (org.exist.collections.Collection)5 Group (org.exist.security.Group)5 Database (org.exist.Database)4 UserAider (org.exist.security.internal.aider.UserAider)4 LockedDocumentMap (org.exist.storage.lock.LockedDocumentMap)4 Test (org.junit.Test)4 java.util (java.util)2 List (java.util.List)2 HttpSession (javax.servlet.http.HttpSession)2