Search in sources :

Example 1 with Builder

use of org.apache.qpid.server.security.access.config.Rule.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testList_Arrays.

@Test
public void testList_Arrays() {
    _ruleCollector.addRule(1, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.PUBLISH).withObject(ObjectType.EXCHANGE).withPredicate(Property.NAME, "broadcast").build());
    _ruleCollector.addRule(3, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.ACCESS).withObject(ObjectType.VIRTUALHOST).build());
    _ruleCollector.addRule(17, new Builder().withIdentity(Rule.ALL).withOutcome(RuleOutcome.DENY).withOperation(LegacyOperation.ALL).withObject(ObjectType.ALL).build());
    final RuleSet ruleSet = createRuleSet();
    assertNotNull(ruleSet);
    Object[] array = ruleSet.toArray();
    Rule[] ruleArray = ruleSet.toArray(new Rule[0]);
    assertEquals(3, array.length);
    assertEquals(3, ruleArray.length);
    for (int i = 0; i < array.length; i++) {
        assertEquals(ruleSet.get(i), array[i]);
        assertEquals(ruleSet.get(i), ruleArray[i]);
    }
}
Also used : Builder(org.apache.qpid.server.security.access.config.Rule.Builder) Test(org.junit.Test)

Example 2 with Builder

use of org.apache.qpid.server.security.access.config.Rule.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testVirtualHostAccessDenyPermissionWithNameSetToWildCard.

@Test
public void testVirtualHostAccessDenyPermissionWithNameSetToWildCard() {
    _ruleCollector.addRule(0, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.DENY).withOperation(LegacyOperation.ACCESS).withObject(ObjectType.VIRTUALHOST).withPredicate(Property.NAME, AclRulePredicatesBuilder.WILD_CARD).build());
    final RuleSet ruleSet = createRuleSet();
    assertEquals(Result.DENIED, ruleSet.check(_testSubject, LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, new ObjectProperties(ALLOWED_VH)));
    assertEquals(Result.DENIED, ruleSet.check(_testSubject, LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, new ObjectProperties(DENIED_VH)));
}
Also used : Builder(org.apache.qpid.server.security.access.config.Rule.Builder) Test(org.junit.Test)

Example 3 with Builder

use of org.apache.qpid.server.security.access.config.Rule.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testTemporaryQueueLastConsume.

/**
 * Test that temporary queue permissions after queue perms in the ACL config work correctly
 */
@Test
public void testTemporaryQueueLastConsume() {
    final ObjectProperties temporary = new ObjectProperties(_queueName);
    temporary.put(Property.AUTO_DELETE, Boolean.TRUE);
    final ObjectProperties normal = new ObjectProperties(_queueName);
    normal.put(Property.AUTO_DELETE, Boolean.FALSE);
    RuleSet ruleSet = createRuleSet();
    assertEquals(Result.DENIED, ruleSet.check(_testSubject, LegacyOperation.CONSUME, ObjectType.QUEUE, temporary));
    // should not matter if the temporary permission is processed first or last
    _ruleCollector.addRule(1, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.CONSUME).withObject(ObjectType.QUEUE).withPredicates(temporary).build());
    _ruleCollector.addRule(2, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.CONSUME).withObject(ObjectType.QUEUE).withPredicates(normal).build());
    ruleSet = createRuleSet();
    assertEquals(2, ruleSet.size());
    assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.CONSUME, ObjectType.QUEUE, normal));
    assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.CONSUME, ObjectType.QUEUE, temporary));
}
Also used : Builder(org.apache.qpid.server.security.access.config.Rule.Builder) Test(org.junit.Test)

Example 4 with Builder

use of org.apache.qpid.server.security.access.config.Rule.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testNamedTemporaryQueueAllowed.

@Test
public void testNamedTemporaryQueueAllowed() {
    final ObjectProperties named = new ObjectProperties(_queueName);
    final ObjectProperties namedTemporary = new ObjectProperties(_queueName);
    namedTemporary.put(Property.AUTO_DELETE, Boolean.TRUE);
    RuleSet ruleSet = createRuleSet();
    assertEquals(Result.DENIED, ruleSet.check(_testSubject, LegacyOperation.CREATE, ObjectType.QUEUE, named));
    assertEquals(Result.DENIED, ruleSet.check(_testSubject, LegacyOperation.CREATE, ObjectType.QUEUE, namedTemporary));
    _ruleCollector.addRule(1, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.CREATE).withObject(ObjectType.QUEUE).withPredicates(namedTemporary).build());
    _ruleCollector.addRule(2, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.CREATE).withObject(ObjectType.QUEUE).withPredicates(named).build());
    ruleSet = createRuleSet();
    assertEquals(2, ruleSet.size());
    assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.CREATE, ObjectType.QUEUE, named));
    assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.CREATE, ObjectType.QUEUE, namedTemporary));
}
Also used : Builder(org.apache.qpid.server.security.access.config.Rule.Builder) Test(org.junit.Test)

Example 5 with Builder

use of org.apache.qpid.server.security.access.config.Rule.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testTemporaryQueueFirstConsume.

/**
 * Test that temporary queue permissions before queue perms in the ACL config work correctly
 */
@Test
public void testTemporaryQueueFirstConsume() {
    final ObjectProperties temporary = new ObjectProperties(_queueName);
    temporary.put(Property.AUTO_DELETE, Boolean.TRUE);
    final ObjectProperties normal = new ObjectProperties(_queueName);
    normal.put(Property.AUTO_DELETE, Boolean.FALSE);
    RuleSet ruleSet = createRuleSet();
    assertEquals(Result.DENIED, ruleSet.check(_testSubject, LegacyOperation.CONSUME, ObjectType.QUEUE, temporary));
    // should not matter if the temporary permission is processed first or last
    _ruleCollector.addRule(1, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.CONSUME).withObject(ObjectType.QUEUE).withPredicates(normal).build());
    _ruleCollector.addRule(2, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.CONSUME).withObject(ObjectType.QUEUE).withPredicates(temporary).build());
    ruleSet = createRuleSet();
    assertEquals(2, ruleSet.size());
    assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.CONSUME, ObjectType.QUEUE, normal));
    assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.CONSUME, ObjectType.QUEUE, temporary));
}
Also used : Builder(org.apache.qpid.server.security.access.config.Rule.Builder) Test(org.junit.Test)

Aggregations

Builder (org.apache.qpid.server.security.access.config.Rule.Builder)30 Test (org.junit.Test)28 Subject (javax.security.auth.Subject)5 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 EventLogger (org.apache.qpid.server.logging.EventLogger)1 EventLoggerProvider (org.apache.qpid.server.logging.EventLoggerProvider)1 AuthenticationProvider (org.apache.qpid.server.model.AuthenticationProvider)1 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)1