use of org.exist.security.Account in project exist by eXist-db.
the class CopyMoveTest method changePermissionsAfterCopy.
@Test
public void changePermissionsAfterCopy() throws XMLDBException {
final String collectionURL = XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION;
final String originalResource = "original.xml";
final String copyResource = "copy.xml";
final String resourceURL = collectionURL + "/" + originalResource;
// get collection & services
EXistCollection col = (EXistCollection) DatabaseManager.getCollection(collectionURL);
EXistCollectionManagementService service = (EXistCollectionManagementService) col.getService("CollectionManagementService", "1.0");
UserManagementService ums = (UserManagementService) DatabaseManager.getCollection(collectionURL, ADMIN_DB_USER, ADMIN_DB_PWD).getService("UserManagementService", "1.0");
// store xml document
XMLResource original = (XMLResource) col.createResource(originalResource, XMLResource.RESOURCE_TYPE);
original.setContent("<sample/>");
col.storeResource(original);
// get original resource
Resource orgnRes = col.getResource(originalResource);
// check permission before copy
Permission prm = ums.getPermissions(orgnRes);
assertEquals("rw-r--r--", prm.toString());
// copy
service.copyResource(XmldbURI.create(resourceURL), col.getPathURI(), XmldbURI.create(copyResource));
// check permission after copy
prm = ums.getPermissions(orgnRes);
assertEquals("rw-r--r--", prm.toString());
// get copy resource
Resource copyRes = col.getResource(copyResource);
// change permission on copy
Account admin = ums.getAccount(ADMIN_DB_USER);
ums.chown(copyRes, admin, admin.getPrimaryGroup());
ums.chmod(copyRes, "rwx--x---");
// check permission of copy
prm = ums.getPermissions(copyRes);
assertEquals("rwx--x---", prm.toString());
// check permission of original
prm = ums.getPermissions(orgnRes);
assertEquals("rw-r--r--", prm.toString());
}
use of org.exist.security.Account in project exist by eXist-db.
the class CollectionConfigurationTest method setUp.
@Before
public void setUp() throws Exception {
final CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
final Collection testCollection = service.createCollection(TEST_COLLECTION);
UserManagementService ums = (UserManagementService) testCollection.getService("UserManagementService", "1.0");
// change ownership to guest
final Account guest = ums.getAccount(GUEST_DB_USER);
ums.chown(guest, guest.getPrimaryGroup());
ums.chmod("rwxr-xr-x");
final Collection testConfCollection = service.createCollection(CONF_COLL_URI.toString());
ums = (UserManagementService) testConfCollection.getService("UserManagementService", "1.0");
// change ownership to guest
ums.chown(guest, guest.getPrimaryGroup());
ums.chmod("rwxr-xr-x");
// configColl = cms.createCollection(CONF_COLL_URI.toString());
}
use of org.exist.security.Account in project exist by eXist-db.
the class ContentAsDOMTest method setUp.
@Before
public void setUp() throws Exception {
CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
Collection testCollection = service.createCollection(TEST_COLLECTION);
UserManagementService ums = (UserManagementService) testCollection.getService("UserManagementService", "1.0");
// change ownership to guest
Account guest = ums.getAccount(GUEST_DB_USER);
ums.chown(guest, guest.getPrimaryGroup());
ums.chmod(Permission.DEFAULT_COLLECTION_PERM);
Resource resource = testCollection.createResource("test.xml", "XMLResource");
resource.setContent(XML);
testCollection.storeResource(resource);
// change resource ownership to guest
ums.chown(resource, guest, GUEST_DB_USER);
}
use of org.exist.security.Account in project exist by eXist-db.
the class TestEXistXMLSerialize method setUp.
@Before
public void setUp() throws Exception {
CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
Collection testCollection = service.createCollection(TEST_COLLECTION);
UserManagementService ums = (UserManagementService) testCollection.getService("UserManagementService", "1.0");
// change ownership to guest
Account guest = ums.getAccount(GUEST_DB_USER);
ums.chown(guest, guest.getPrimaryGroup());
ums.chmod("rwxr-xr-x");
}
use of org.exist.security.Account in project exist by eXist-db.
the class XMLDBRestoreTest method restoreUserWithGroups.
private void restoreUserWithGroups(final Path backupPath, final Path restorePath, final int expectedRestoredCount) throws IOException, XMLDBException {
final String username = UUID.randomUUID().toString() + "-user";
// personal group
final String primaryGroup = username;
final String group1 = UUID.randomUUID().toString() + "-group-1";
final String group2 = UUID.randomUUID().toString() + "-group-2";
final String group3 = UUID.randomUUID().toString() + "-group-3";
final TestRestoreListener listener = new TestRestoreListener();
final XmldbURI rootUri = XmldbURI.create(getBaseUri()).append(XmldbURI.ROOT_COLLECTION_URI);
createBackupWithUserInGroups(backupPath, username, primaryGroup, group1, group2, group3);
restoreBackup(rootUri, restorePath, null, listener);
assertEquals(expectedRestoredCount, listener.restored.size());
assertEquals(0, listener.warnings.size());
assertEquals(0, listener.errors.size());
final Collection collection = DatabaseManager.getCollection(rootUri.toString(), TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
final EXistUserManagementService userManagementService = (EXistUserManagementService) collection.getService("UserManagementService", "1.0");
final Account account = userManagementService.getAccount(username);
assertNotNull(account);
assertEquals(primaryGroup, account.getPrimaryGroup());
assertArrayEquals(new String[] { primaryGroup, group1, group2, group3 }, account.getGroups());
}
Aggregations