Search in sources :

Example 31 with SecurityManager

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

the class StoreResourceTest 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, GROUP1_NAME);
        removeCollection(broker, transaction, TEST_COLLECTION_URI);
        transaction.commit();
    }
}
Also used : SecurityManager(org.exist.security.SecurityManager) Txn(org.exist.storage.txn.Txn)

Example 32 with SecurityManager

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

the class CopyCollectionTest 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, TEST_COLLECTION_URI);
        chmod(broker, transaction, collection.getURI(), 511);
        broker.saveCollection(transaction, collection);
        createUser(broker, sm, USER1_NAME, USER1_PWD);
        createUser(broker, sm, USER2_NAME, USER2_PWD);
        transaction.commit();
    }
}
Also used : SecurityManager(org.exist.security.SecurityManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn)

Example 33 with SecurityManager

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

the class CopyCollectionTest 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);
        removeCollection(broker, transaction, TEST_COLLECTION_URI);
        transaction.commit();
    }
}
Also used : SecurityManager(org.exist.security.SecurityManager) Txn(org.exist.storage.txn.Txn)

Example 34 with SecurityManager

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

the class DocumentImplTest method isSameNode_differentDoc.

@Test
public void isSameNode_differentDoc() {
    final BrokerPool mockBrokerPool = EasyMock.createMock(BrokerPool.class);
    final Database mockDatabase = EasyMock.createMock(Database.class);
    final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
    final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
    final Group mockCurrentSubjectGroup = EasyMock.createMock(Group.class);
    final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
    // expectations
    expect(mockBrokerPool.getSecurityManager()).andReturn(mockSecurityManager).times(2);
    expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase).times(2);
    expect(mockDatabase.getActiveBroker()).andReturn(mockBroker).times(2);
    expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject).times(2);
    expect(mockCurrentSubject.getUserMask()).andReturn(Permission.DEFAULT_UMASK).times(2);
    expect(mockCurrentSubject.getId()).andReturn(RealmImpl.SYSTEM_ACCOUNT_ID).times(2);
    expect(mockCurrentSubject.getDefaultGroup()).andReturn(mockCurrentSubjectGroup).times(2);
    expect(mockCurrentSubjectGroup.getId()).andReturn(RealmImpl.DBA_GROUP_ID).times(2);
    replay(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
    // test setup
    final DocumentImpl doc = new DocumentImpl(mockBrokerPool, 99);
    final DocumentImpl doc2 = new DocumentImpl(mockBrokerPool, 765);
    assertFalse(doc.isSameNode(doc2));
    verify(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Database(org.exist.Database) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 35 with SecurityManager

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

the class DocumentImplTest method isSameNode_nonDoc.

@Test
public void isSameNode_nonDoc() {
    final BrokerPool mockBrokerPool = EasyMock.createMock(BrokerPool.class);
    final Database mockDatabase = EasyMock.createMock(Database.class);
    final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
    final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
    final Group mockCurrentSubjectGroup = EasyMock.createMock(Group.class);
    final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
    // expectations
    expect(mockBrokerPool.getSecurityManager()).andReturn(mockSecurityManager);
    expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase);
    expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
    expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject);
    expect(mockCurrentSubject.getUserMask()).andReturn(Permission.DEFAULT_UMASK);
    expect(mockCurrentSubject.getId()).andReturn(RealmImpl.SYSTEM_ACCOUNT_ID);
    expect(mockCurrentSubject.getDefaultGroup()).andReturn(mockCurrentSubjectGroup);
    expect(mockCurrentSubjectGroup.getId()).andReturn(RealmImpl.DBA_GROUP_ID);
    replay(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
    // test setup
    final DocumentImpl doc = new DocumentImpl(mockBrokerPool, 99);
    final TextImpl text = new TextImpl("hello");
    assertFalse(doc.isSameNode(text));
    verify(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Database(org.exist.Database) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

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