use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class AbstractSecurityManagerRoundtripTest method checkGroupManagerStability.
@Test
public void checkGroupManagerStability() throws XMLDBException, PermissionDeniedException, IOException {
UserManagementService ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
final String commonGroupName = "commonGroup";
Group commonGroup = new GroupAider(commonGroupName);
final String userName = "testUserA";
final Group userGroup = new GroupAider(userName);
// set users primary group as personal group
final Account userAccount = new UserAider(userName, userGroup);
try {
// create a user with personal group
ums.addGroup(userGroup);
ums.addAccount(userAccount);
// add user1 as a manager of common group
ums.addGroup(commonGroup);
commonGroup.addManager(userAccount);
ums.updateGroup(commonGroup);
/**
* RESTART THE SERVER **
*/
restartServer();
/**
***********************
*/
ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
// get the common group
commonGroup = ums.getGroup(commonGroupName);
assertNotNull(commonGroup);
// assert that user1 is still a manager of the common group
final List<Account> commonGroupManagers = commonGroup.getManagers();
assertNotNull(commonGroupManagers);
assertEquals(1, commonGroupManagers.size());
assertEquals(commonGroupManagers.get(0).getName(), userName);
} finally {
// cleanup
try {
ums.removeGroup(commonGroup);
} catch (Exception e) {
}
try {
ums.removeAccount(userAccount);
} catch (Exception e) {
}
try {
ums.removeGroup(userGroup);
} catch (Exception e) {
}
}
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class AbstractSecurityManagerRoundtripTest method checkPrimaryGroupRemainsDBA.
@Test
public void checkPrimaryGroupRemainsDBA() 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);
// set users primary group as DBA
Account user = new UserAider(userName, ums.getGroup(SecurityManager.DBA_GROUP));
try {
ums.addGroup(group1);
ums.addGroup(group2);
ums.addAccount(user);
ums.getAccount(userName);
user.addGroup(group1);
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(SecurityManager.DBA_GROUP, defaultGroup.getName());
String[] groups = user.getGroups();
assertNotNull(groups);
assertEquals(3, groups.length);
assertEquals(SecurityManager.DBA_GROUP, groups[0]);
assertEquals(group1Name, groups[1]);
assertEquals(group2Name, groups[2]);
} 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);
}
}
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method canUpdateBinaryResourceWithOnlyExecutePermissionOnParentCollection.
@Test
public void canUpdateBinaryResourceWithOnlyExecutePermissionOnParentCollection() throws XMLDBException {
Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
ums.chmod("--x------");
test.close();
test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
Resource resource = test.getResource("test.bin");
assertArrayEquals("binary-test".getBytes(), (byte[]) resource.getContent());
// update the resource
resource.setContent("testing".getBytes());
test.storeResource(resource);
resource = test.getResource("test.bin");
assertArrayEquals("testing".getBytes(), (byte[]) resource.getContent());
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method copyDocument_doesPreservePermissions_whenDestResourceExists.
@Test
public void copyDocument_doesPreservePermissions_whenDestResourceExists() throws XMLDBException {
Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest3", "test1", "test1");
EXistCollectionManagementService cms = (EXistCollectionManagementService) test.getService("CollectionManagementService", "1.0");
// create resource owned by "test1", and group "users" in /db/securityTest3
final Resource resSource = test.createResource("source.xml", XMLResource.RESOURCE_TYPE);
resSource.setContent("<test/>");
test.storeResource(resSource);
// pre-create the dest resource (before the copy) and set writable by all
final Resource resDest = test.createResource("copy-of-source.xml", XMLResource.RESOURCE_TYPE);
resDest.setContent("<old/>");
test.storeResource(resDest);
UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
ums.chmod(resDest, 0777);
// as the 'test3' user copy the resource
test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest3", "test3", "test3");
cms = (EXistCollectionManagementService) test.getService("CollectionManagementService", "1.0");
cms.copyResource("/db/securityTest3/source.xml", "/db/securityTest3", "copy-of-source.xml");
// as test3 user!
ums = (UserManagementService) test.getService("UserManagementService", "1.0");
final Permission permissions = ums.getPermissions(test.getResource("copy-of-source.xml"));
// resource should be owned by test3:guest, i.e. permissions were not preserved from the test1 users doc /db/securityTest3/source.xml
assertEquals("test1", permissions.getOwner().getName());
assertEquals("users", permissions.getGroup().getName());
// TODO copy collection should do the same??!?
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XMLDBSecurityTest method onlyExecuteRequiredToOpenCollectionContent.
@Test
public void onlyExecuteRequiredToOpenCollectionContent() throws XMLDBException {
final Collection test = DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
final UserManagementService ums = (UserManagementService) test.getService("UserManagementService", "1.0");
ums.chmod("--x------");
test.close();
DatabaseManager.getCollection(getBaseUri() + "/db/securityTest1", "test1", "test1");
}
Aggregations