use of org.apache.qpid.server.security.access.config.Rule.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testVirtualHostAccessAllowPermissionWithNameSetToWildCard.
@Test
public void testVirtualHostAccessAllowPermissionWithNameSetToWildCard() {
_ruleCollector.addRule(0, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.ACCESS).withObject(ObjectType.VIRTUALHOST).withPredicate(Property.NAME, AclRulePredicatesBuilder.WILD_CARD).build());
final RuleSet ruleSet = createRuleSet();
assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, new ObjectProperties(ALLOWED_VH)));
assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, new ObjectProperties(DENIED_VH)));
}
use of org.apache.qpid.server.security.access.config.Rule.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testQueueCreateNamedVirtualHost.
@Test
public void testQueueCreateNamedVirtualHost() {
_ruleCollector.addRule(0, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.CREATE).withObject(ObjectType.QUEUE).withPredicate(Property.VIRTUALHOST_NAME, ALLOWED_VH).build());
final RuleSet ruleSet = createRuleSet();
final ObjectProperties allowedQueueObjectProperties = new ObjectProperties(_queueName);
allowedQueueObjectProperties.put(Property.VIRTUALHOST_NAME, ALLOWED_VH);
assertEquals(Result.ALLOWED, ruleSet.check(_testSubject, LegacyOperation.CREATE, ObjectType.QUEUE, new ObjectProperties(allowedQueueObjectProperties)));
final ObjectProperties deniedQueueObjectProperties = new ObjectProperties(_queueName);
deniedQueueObjectProperties.put(Property.VIRTUALHOST_NAME, DENIED_VH);
assertEquals(Result.DEFER, ruleSet.check(_testSubject, LegacyOperation.CREATE, ObjectType.QUEUE, deniedQueueObjectProperties));
}
use of org.apache.qpid.server.security.access.config.Rule.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testFirstNamedSecondTemporaryQueueDenied.
/*
* Test different rules for temporary queues.
*/
/**
* The more generic rule first is used, so both requests are allowed.
*/
@Test
public void testFirstNamedSecondTemporaryQueueDenied() {
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(named).build());
_ruleCollector.addRule(2, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.DENY).withOperation(LegacyOperation.CREATE).withObject(ObjectType.QUEUE).withPredicates(namedTemporary).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));
}
use of org.apache.qpid.server.security.access.config.Rule.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testFirstTemporarySecondNamedQueueDenied.
/**
* The more specific rule is first, so those requests are denied.
*/
@Test
public void testFirstTemporarySecondNamedQueueDenied() {
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.DENY).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.DENIED, ruleSet.check(_testSubject, LegacyOperation.CREATE, ObjectType.QUEUE, namedTemporary));
}
use of org.apache.qpid.server.security.access.config.Rule.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testGetDefault.
@Test
public void testGetDefault() {
final Rule rule = new Builder().withIdentity(TEST_USER).withOperation(LegacyOperation.ACCESS).withObject(ObjectType.VIRTUALHOST).withOutcome(RuleOutcome.ALLOW).build();
final EventLoggerProvider logger = mock(EventLoggerProvider.class);
final RuleSet ruleSet = RuleSet.newInstance(logger, Collections.singletonList(rule), Result.ALLOWED);
assertNotNull(ruleSet);
assertEquals(Result.ALLOWED, ruleSet.getDefault());
}
Aggregations