Search in sources :

Example 36 with UsernamePrincipal

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
    }
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) File(java.io.File) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) Principal(java.security.Principal) Test(org.junit.Test)

Example 37 with UsernamePrincipal

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));
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) Builder(org.apache.qpid.server.security.access.config.Rule.Builder) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Aggregations

UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)37 Test (org.junit.Test)14 AuthenticationResult (org.apache.qpid.server.security.auth.AuthenticationResult)13 Subject (javax.security.auth.Subject)12 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)11 Principal (java.security.Principal)8 IOException (java.io.IOException)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 InputStream (java.io.InputStream)6 HttpURLConnection (java.net.HttpURLConnection)6 URL (java.net.URL)6 GeneralSecurityException (java.security.GeneralSecurityException)6 Map (java.util.Map)6 TrustStore (org.apache.qpid.server.model.TrustStore)6 IdentityResolverException (org.apache.qpid.server.security.auth.manager.oauth2.IdentityResolverException)6 ConnectionBuilder (org.apache.qpid.server.util.ConnectionBuilder)6 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)6 X500Principal (javax.security.auth.x500.X500Principal)5 SaslNegotiator (org.apache.qpid.server.security.auth.sasl.SaslNegotiator)5 EventLogger (org.apache.qpid.server.logging.EventLogger)4