Search in sources :

Example 1 with LdifReader

use of org.apache.directory.shared.ldap.model.ldif.LdifReader in project activemq-artemis by apache.

the class AbstractCachedLDAPAuthorizationMapLegacyTest method testSynchronousUpdate.

@Test
public void testSynchronousUpdate() throws Exception {
    map.setRefreshInterval(1);
    map.query();
    Set<?> readACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
    assertEquals("set size: " + readACLs, 2, readACLs.size());
    assertTrue("Contains admin group", readACLs.contains(ADMINS));
    assertTrue("Contains users group", readACLs.contains(USERS));
    Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
    assertEquals("set size: " + failedACLs, 0, failedACLs.size());
    LdifReader reader = new LdifReader(getRemoveLdif());
    for (LdifEntry entry : reader) {
        connection.delete(entry.getDn());
    }
    reader.close();
    assertTrue("did not get expected size. ", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return map.getReadACLs(new ActiveMQQueue("TEST.FOO")).size() == 0;
        }
    }));
    assertNull(map.getTempDestinationReadACLs());
    assertNull(map.getTempDestinationWriteACLs());
    assertNull(map.getTempDestinationAdminACLs());
}
Also used : LdifReader(org.apache.directory.shared.ldap.model.ldif.LdifReader) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) LdifEntry(org.apache.directory.shared.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 2 with LdifReader

use of org.apache.directory.shared.ldap.model.ldif.LdifReader in project activemq-artemis by apache.

the class AbstractCachedLDAPAuthorizationMapLegacyTest method testAdd.

@Test
public void testAdd() throws Exception {
    map.query();
    Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
    assertEquals("set size: " + failedACLs, 0, failedACLs.size());
    LdifReader reader = new LdifReader(getAddLdif());
    for (LdifEntry entry : reader) {
        connection.add(entry.getEntry());
    }
    reader.close();
    Thread.sleep(2000);
    failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
    assertEquals("set size: " + failedACLs, 2, failedACLs.size());
}
Also used : LdifReader(org.apache.directory.shared.ldap.model.ldif.LdifReader) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) LdifEntry(org.apache.directory.shared.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 3 with LdifReader

use of org.apache.directory.shared.ldap.model.ldif.LdifReader in project activemq-artemis by apache.

the class AbstractCachedLDAPAuthorizationMapLegacyTest method testRestart.

public void testRestart(final boolean sync) throws Exception {
    if (sync) {
        // ldap connection can be slow to close
        map.setRefreshInterval(1000);
    }
    map.query();
    Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("FAILED"));
    assertEquals("set size: " + failedACLs, 0, failedACLs.size());
    failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
    assertEquals("set size: " + failedACLs, 2, failedACLs.size());
    getLdapServer().stop();
    // wait for the context to be closed
    // as we can't rely on ldar server isStarted()
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            if (sync) {
                return !map.isContextAlive();
            } else {
                return map.context == null;
            }
        }
    });
    failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
    assertEquals("set size: " + failedACLs, 2, failedACLs.size());
    getLdapServer().start();
    Thread.sleep(2000);
    connection = getLdapConnection();
    LdifReader reader = new LdifReader(getAddLdif());
    for (LdifEntry entry : reader) {
        connection.add(entry.getEntry());
    }
    reader.close();
    assertTrue("did not get expected size. ", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return map.getReadACLs(new ActiveMQQueue("FAILED")).size() == 2;
        }
    }));
}
Also used : LdifReader(org.apache.directory.shared.ldap.model.ldif.LdifReader) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Wait(org.apache.activemq.util.Wait) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LdifEntry(org.apache.directory.shared.ldap.model.ldif.LdifEntry)

Example 4 with LdifReader

use of org.apache.directory.shared.ldap.model.ldif.LdifReader in project activemq-artemis by apache.

the class AbstractCachedLDAPAuthorizationMapLegacyTest method testRemove.

@Test
public void testRemove() throws Exception {
    map.query();
    Set<?> failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
    assertEquals("set size: " + failedACLs, 2, failedACLs.size());
    LdifReader reader = new LdifReader(getRemoveLdif());
    for (LdifEntry entry : reader) {
        connection.delete(entry.getDn());
    }
    reader.close();
    Thread.sleep(2000);
    failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
    assertEquals("set size: " + failedACLs, 0, failedACLs.size());
    assertTrue(map.getTempDestinationReadACLs() == null || map.getTempDestinationReadACLs().isEmpty());
    assertTrue(map.getTempDestinationWriteACLs() == null || map.getTempDestinationWriteACLs().isEmpty());
    assertTrue(map.getTempDestinationAdminACLs() == null || map.getTempDestinationAdminACLs().isEmpty());
}
Also used : LdifReader(org.apache.directory.shared.ldap.model.ldif.LdifReader) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) LdifEntry(org.apache.directory.shared.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Aggregations

ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)4 LdifEntry (org.apache.directory.shared.ldap.model.ldif.LdifEntry)4 LdifReader (org.apache.directory.shared.ldap.model.ldif.LdifReader)4 Test (org.junit.Test)3 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Wait (org.apache.activemq.util.Wait)1