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();
}
}
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();
}
}
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();
}
}
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;
}
}
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]);
});
}
Aggregations