use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testDefaultConnectionFrequencyLimit.
private void testDefaultConnectionFrequencyLimit(Integer countLimit) {
if (countLimit != null && countLimit < 3) {
countLimit = 3;
}
final Duration frequencyPeriod = Duration.ofDays(3650L);
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, frequencyPeriod);
builder.addRule(Rule.newNonBlockingRule(TEST_PORT, RulePredicates.ALL_USERS, null, 2, frequencyPeriod));
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS, countLimit, 2, frequencyPeriod));
builder.addRule(Rule.newNonBlockingRule(TEST_PORT, OTHER_USER, 1, 1, frequencyPeriod));
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, OTHER_GROUP, 1, 1, frequencyPeriod));
final RuleSet ruleSet = builder.build();
testConnectionFrequencyLimit2(ruleSet);
}
use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testDefaultConnectionCountLimit.
private void testDefaultConnectionCountLimit(Duration duration, Integer frequencyLimit) {
if (frequencyLimit != null && frequencyLimit < 3) {
frequencyLimit = 3;
}
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, duration);
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, TEST_USER, 2, frequencyLimit, 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.newNonBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS, 2, null, duration));
testConnectionCountLimit2(builder.build());
testConnectionCountLimit2(builder.logAllMessages(true).build());
testConnectionCountLimit2(builder.logAllMessages(false).build());
}
use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testRegisterNullSubject.
private void testRegisterNullSubject(Duration duration) {
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, duration);
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, TEST_GROUP1, 1000, 1000, duration));
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, TEST_GROUP2, 1000, 1000, 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(_principal).when(connection).getAuthorizedPrincipal();
Mockito.doReturn(_eventLogger).when(connection).getEventLogger();
try {
ruleSet.register(connection);
fail("An exception is expected");
} catch (ConnectionLimitException e) {
assertEquals("User user is blocked on port amqp", e.getMessage());
}
}
use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testAppend_FrequencyLimit.
private void testAppend_FrequencyLimit(Integer countLimit) {
if (countLimit != null && countLimit < 3) {
countLimit = 3;
}
final Duration frequencyPeriod = Duration.ofDays(3650L);
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, frequencyPeriod);
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, TEST_USER, 200, 20000, frequencyPeriod));
builder.addRule(Rule.newNonBlockingRule(TEST_PORT, OTHER_USER, 1, 1, frequencyPeriod));
builder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS));
final Builder secondaryBuilder = RuleSet.newBuilder(LIMITER_NAME, frequencyPeriod);
secondaryBuilder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_USER, countLimit, 2, frequencyPeriod));
secondaryBuilder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS));
testConnectionFrequencyLimit2((RuleSet) builder.build().append(secondaryBuilder.build()));
}
use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testBlockedGroup.
private void testBlockedGroup(Duration duration) {
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, duration);
builder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_GROUP1, 10000, null, duration));
builder.addRule(Rule.newBlockingRule(TEST_PORT, TEST_GROUP2));
builder.addRule(Rule.newNonBlockingRule(TEST_PORT, OTHER_USER, 1000, 1000, duration));
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, OTHER_GROUP, 1000, 1000, duration));
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS, 10000, 10000, duration));
testBlocked(builder.build());
testBlocked(builder.logAllMessages(true).build());
testBlocked(builder.logAllMessages(false).build());
}
Aggregations