use of org.apache.qpid.server.security.auth.UsernamePrincipal in project qpid-broker-j by apache.
the class AbstractPasswordFilePrincipalDatabaseTest method testRejectUsernameWithColon.
@Test
public void testRejectUsernameWithColon() throws Exception {
String usernameWithColon = "user:name";
Principal principal = new UsernamePrincipal(usernameWithColon, null);
File testFile = createPasswordFile(0, 0);
loadPasswordFile(testFile);
try {
getDatabase().createPrincipal(principal, TEST_PASSWORD_CHARS);
fail("Username with colon should be rejected");
} catch (IllegalArgumentException e) {
// pass
}
}
use of org.apache.qpid.server.security.auth.UsernamePrincipal in project qpid-broker-j by apache.
the class RuleSetTest method testPublishToExchange_OwnerBased_withoutAuthPrincipal.
@Test
public void testPublishToExchange_OwnerBased_withoutAuthPrincipal() {
_ruleCollector.addRule(1, new Builder().withPredicate(Property.NAME, "broadcast").withPredicate(Property.ROUTING_KEY, "broadcast.*").withOwner().withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.PUBLISH).withObject(ObjectType.EXCHANGE).build());
_ruleCollector.addRule(3, new Builder().withPredicate(Property.NAME, "broadcast").withPredicate(Property.ROUTING_KEY, "rs.broadcast.*").withOwner().withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.PUBLISH).withObject(ObjectType.EXCHANGE).build());
_ruleCollector.addRule(11, new Builder().withPredicate(Property.NAME, "broadcast").withPredicate(Property.QUEUE_NAME, "QQ").withIdentity(TEST_USER).withOutcome(RuleOutcome.ALLOW).withOperation(LegacyOperation.PUBLISH).withObject(ObjectType.EXCHANGE).build());
_ruleCollector.addRule(17, new Builder().withIdentity(TEST_USER).withOutcome(RuleOutcome.DENY).withOperation(LegacyOperation.PUBLISH).withObject(ObjectType.ALL).build());
final RuleSet ruleSet = createRuleSet();
assertEquals(4, ruleSet.size());
// User without authentication principal
final Subject notAuthentificated = new Subject(false, Collections.singleton(new UsernamePrincipal(TEST_USER, Mockito.mock(AuthenticationProvider.class))), Collections.emptySet(), Collections.emptySet());
ObjectProperties object = new ObjectProperties("broadcast");
object.put(Property.ROUTING_KEY, "rs.broadcast.public");
object.setCreatedBy(TEST_USER);
assertEquals(Result.DENIED, ruleSet.check(notAuthentificated, LegacyOperation.PUBLISH, ObjectType.EXCHANGE, object));
object = new ObjectProperties("broadcast");
object.put(Property.QUEUE_NAME, "QQ");
assertEquals(Result.ALLOWED, ruleSet.check(notAuthentificated, LegacyOperation.PUBLISH, ObjectType.EXCHANGE, object));
}
Aggregations