Search in sources :

Example 11 with Account

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());
}
Also used : Account(org.exist.security.Account) Permission(org.exist.security.Permission) Test(org.junit.Test)

Example 12 with Account

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());
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Account(org.exist.security.Account) Collection(org.xmldb.api.base.Collection)

Example 13 with Account

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);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Account(org.exist.security.Account) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) Before(org.junit.Before)

Example 14 with Account

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");
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Account(org.exist.security.Account) Collection(org.xmldb.api.base.Collection) Before(org.junit.Before)

Example 15 with Account

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());
}
Also used : Account(org.exist.security.Account) Collection(org.xmldb.api.base.Collection)

Aggregations

Account (org.exist.security.Account)60 PermissionDeniedException (org.exist.security.PermissionDeniedException)18 SecurityManager (org.exist.security.SecurityManager)17 EXistException (org.exist.EXistException)12 XMLDBException (org.xmldb.api.base.XMLDBException)11 Group (org.exist.security.Group)10 Collection (org.xmldb.api.base.Collection)10 AuthenticationException (org.exist.security.AuthenticationException)9 DBBroker (org.exist.storage.DBBroker)9 AbstractAccount (org.exist.security.AbstractAccount)7 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)7 Txn (org.exist.storage.txn.Txn)6 DocumentImpl (org.exist.dom.persistent.DocumentImpl)5 Subject (org.exist.security.Subject)5 UserAider (org.exist.security.internal.aider.UserAider)5 UserManagementService (org.exist.xmldb.UserManagementService)5 Permission (org.exist.security.Permission)4 XPathException (org.exist.xquery.XPathException)4 Before (org.junit.Before)4 Test (org.junit.Test)4