Search in sources :

Example 11 with Builder

use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testBlockedByDefault.

private void testBlockedByDefault(Duration duration) {
    final Builder builder = RuleSet.newBuilder(LIMITER_NAME, duration);
    builder.addRule(Rule.newBlockingRule(TEST_PORT, RulePredicates.ALL_USERS));
    builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS, 10000, 10000, duration));
    builder.addRule(Rule.newNonBlockingRule(TEST_PORT, OTHER_USER, 1000, 1000, duration));
    builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, OTHER_GROUP, 1000, 1000, duration));
    testBlocked(builder.build());
    testBlocked(builder.logAllMessages(true).build());
    testBlocked(builder.logAllMessages(false).build());
}
Also used : Builder(org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder)

Example 12 with Builder

use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testInvalidRuleWithoutPeriod.

@Test
public void testInvalidRuleWithoutPeriod() {
    RuleSet.Builder builder = RuleSet.newBuilder(LIMITER_NAME, Duration.ofMinutes(1L));
    final NonBlockingRule rule = Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS, 2, 2, null);
    try {
        builder.addRule(rule);
        fail("An exception is expected, the rule is not valid.");
    } catch (IllegalArgumentException e) {
        assertNotNull(e.getMessage());
    }
    try {
        builder.addRules(Collections.singletonList(rule));
        fail("An exception is expected, the rule is not valid.");
    } catch (IllegalArgumentException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : Builder(org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder) Test(org.junit.Test)

Example 13 with Builder

use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testGroupConnectionCountLimit_Concurrency.

private void testGroupConnectionCountLimit_Concurrency(Duration frequencyPeriod, Integer frequencyLimit, int threadCount) {
    if (frequencyLimit != null) {
        if (frequencyLimit < 3) {
            frequencyLimit = 3;
        }
        if (frequencyLimit < threadCount) {
            frequencyLimit = threadCount;
        }
    }
    final Builder builder = RuleSet.newBuilder(LIMITER_NAME, frequencyPeriod);
    builder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_GROUP2, 1000, frequencyLimit, frequencyPeriod));
    builder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_GROUP1, 2, null, frequencyPeriod));
    builder.addRule(Rule.newNonBlockingRule(TEST_PORT, OTHER_USER, 1, 1, frequencyPeriod));
    builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, OTHER_GROUP, 1, 1, frequencyPeriod));
    builder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS));
    testParallelThreads(threadCount, builder.build(), false);
}
Also used : Builder(org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder)

Example 14 with Builder

use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testGroupConnectionCountLimit.

private void testGroupConnectionCountLimit(Duration duration, Integer frequencyLimit) {
    if (frequencyLimit != null && frequencyLimit < 3) {
        frequencyLimit = 3;
    }
    final Builder builder = RuleSet.newBuilder(LIMITER_NAME, duration);
    builder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_GROUP2, 1000, frequencyLimit, duration));
    builder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_GROUP1, 2, null, duration));
    builder.addRule(Rule.newNonBlockingRule(TEST_PORT, OTHER_USER, 1, 1, duration));
    builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, OTHER_GROUP, 1, 1, duration));
    builder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS));
    testConnectionCountLimit2(builder.build());
    testConnectionCountLimit2(builder.logAllMessages(true).build());
    testConnectionCountLimit2(builder.logAllMessages(false).build());
}
Also used : Builder(org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder)

Example 15 with Builder

use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.

the class RuleSetTest method testRegisterNullUser.

private void testRegisterNullUser(Duration duration) {
    final Builder builder = RuleSet.newBuilder(LIMITER_NAME, duration);
    builder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS));
    final RuleSet ruleSet = builder.build();
    assertNotNull(ruleSet);
    final AMQPConnection<?> connection = Mockito.mock(AMQPConnection.class);
    Mockito.doReturn(_port).when(connection).getPort();
    Mockito.doReturn(_subject).when(connection).getSubject();
    Mockito.doReturn(_eventLogger).when(connection).getEventLogger();
    try {
        ruleSet.register(connection);
        fail("An exception is expected");
    } catch (ConnectionLimitException e) {
        assertEquals("Unauthorized connection is forbidden", e.getMessage());
    }
}
Also used : ConnectionLimitException(org.apache.qpid.server.security.limit.ConnectionLimitException) Builder(org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder)

Aggregations

Builder (org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder)22 Duration (java.time.Duration)7 ConnectionLimitException (org.apache.qpid.server.security.limit.ConnectionLimitException)4 Test (org.junit.Test)3 ConnectionSlot (org.apache.qpid.server.security.limit.ConnectionSlot)2 Instant (java.time.Instant)1