Search in sources :

Example 11 with Builder

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

the class RuleSetTest method testExchangeCreateNamedVirtualHost.

@Test
public void testExchangeCreateNamedVirtualHost() {
    _ruleCollector.addRule(0, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.CREATE).withObject(ObjectType.EXCHANGE).withPredicate(Property.VIRTUALHOST_NAME, ALLOWED_VH).build());
    final RuleSet ruleSet = createRuleSet();
    final ObjectProperties allowedExchangeProperties = new ObjectProperties(_exchangeName);
    allowedExchangeProperties.put(Property.TYPE, _exchangeType);
    allowedExchangeProperties.put(Property.VIRTUALHOST_NAME, ALLOWED_VH);
    assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.CREATE, ObjectType.EXCHANGE, allowedExchangeProperties));
    final ObjectProperties deniedExchangeProperties = new ObjectProperties(_exchangeName);
    deniedExchangeProperties.put(Property.TYPE, _exchangeType);
    deniedExchangeProperties.put(Property.VIRTUALHOST_NAME, DENIED_VH);
    assertEquals(Result.DEFER, ruleSet.check(_testSubject, LegacyOperation.CREATE, ObjectType.EXCHANGE, deniedExchangeProperties));
}
Also used : Builder(org.apache.qpid.server.security.access.config.Rule.Builder) Test(org.junit.Test)

Example 12 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.

@Test
public void testList() {
    _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);
    assertEquals(3, ruleSet.size());
    assertFalse(ruleSet.isEmpty());
    final Rule rule = new Builder().withIdentity(TEST_USER).withOperation(LegacyOperation.ACCESS).withObject(ObjectType.VIRTUALHOST).withOutcome(RuleOutcome.ALLOW).build();
    final Rule all = new Builder().withIdentity(Rule.ALL).withOperation(LegacyOperation.ALL).withObject(ObjectType.ALL).withOutcome(RuleOutcome.DENY).build();
    assertTrue(ruleSet.contains(rule));
    assertTrue(ruleSet.containsAll(Arrays.asList(rule, all)));
    assertEquals(rule, ruleSet.get(1));
    assertEquals(1, ruleSet.indexOf(rule));
    assertEquals(1, ruleSet.lastIndexOf(rule));
}
Also used : Builder(org.apache.qpid.server.security.access.config.Rule.Builder) Test(org.junit.Test)

Example 13 with Builder

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

the class RuleSetTest method testSuppressedRules.

@Test
public void testSuppressedRules() {
    _ruleCollector.addRule(1, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.PUBLISH).withObject(ObjectType.EXCHANGE).withPredicate(Property.NAME, "testExchange").build());
    _ruleCollector.addRule(2, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.DENY).withOperation(LegacyOperation.PUBLISH).withObject(ObjectType.EXCHANGE).build());
    _ruleCollector.addRule(3, new Builder().withIdentity(Rule.ALL).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.PUBLISH).withObject(ObjectType.EXCHANGE).build());
    _ruleCollector.addRule(4, new Builder().withIdentity(Rule.ALL).withOutcome(RuleOutcome.DENY).withOperation(LegacyOperation.ALL).withObject(ObjectType.ALL).build());
    final RuleSet ruleSet = createRuleSet();
    assertEquals(4, ruleSet.size());
    assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.PUBLISH, ObjectType.EXCHANGE, new ObjectProperties("testExchange")));
    assertEquals(Result.DENIED, ruleSet.check(_testSubject, LegacyOperation.PUBLISH, ObjectType.EXCHANGE, new ObjectProperties("exchange")));
    assertEquals(Result.DENIED, ruleSet.check(_testSubject, LegacyOperation.PUBLISH, ObjectType.EXCHANGE, new ObjectProperties()));
}
Also used : Builder(org.apache.qpid.server.security.access.config.Rule.Builder) Test(org.junit.Test)

Example 14 with Builder

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

the class AclFileParser method parseAcl.

private void parseAcl(Integer number, Queue<String> args, final RuleCollector ruleCollector, final int line) {
    if (args.size() < 3) {
        throw new IllegalConfigurationException(String.format(NOT_ENOUGH_ACL_MSG, line));
    }
    final Builder builder = new Builder().withOutcome(parsePermission(args.poll(), line)).withIdentity(args.poll()).withOperation(parseOperation(args.poll(), line));
    if (!args.isEmpty()) {
        builder.withObject(parseObjectType(args.poll(), line));
        final Iterator<String> tokenIterator = args.iterator();
        while (tokenIterator.hasNext()) {
            builder.withPredicate(tokenIterator.next(), readValue(tokenIterator, line));
        }
    }
    ruleCollector.addRule(number, builder.build());
}
Also used : Builder(org.apache.qpid.server.security.access.config.Rule.Builder) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException)

Example 15 with Builder

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

the class RuleSetTest method testVirtualHostAccessAllowPermissionWithVirtualHostName.

@Test
public void testVirtualHostAccessAllowPermissionWithVirtualHostName() {
    _ruleCollector.addRule(0, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.ACCESS).withObject(ObjectType.VIRTUALHOST).withPredicate(Property.NAME, ALLOWED_VH).build());
    final RuleSet ruleSet = createRuleSet();
    assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, new ObjectProperties(ALLOWED_VH)));
    assertEquals(Result.DEFER, 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)

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