use of org.apache.qpid.server.security.access.firewall.NetworkFirewallRule in project qpid-broker-j by apache.
the class NetworkFirewallRuleTest method testEqualsAndHashCode.
public void testEqualsAndHashCode() {
NetworkFirewallRule rule = new NetworkFirewallRule(LOCALHOST_IP, OTHER_IP_1);
NetworkFirewallRule equalRule = new NetworkFirewallRule(LOCALHOST_IP, OTHER_IP_1);
assertTrue(rule.equals(rule));
assertTrue(rule.equals(equalRule));
assertTrue(equalRule.equals(rule));
assertTrue(rule.hashCode() == equalRule.hashCode());
assertFalse("Different networks should cause rules to be unequal", rule.equals(new NetworkFirewallRule(LOCALHOST_IP, OTHER_IP_2)));
}
use of org.apache.qpid.server.security.access.firewall.NetworkFirewallRule in project qpid-broker-j by apache.
the class MessagingACLTest method configureACL.
private void configureACL(String... rules) throws Exception {
EventLoggerProvider eventLoggerProvider = mock(EventLoggerProvider.class);
EventLogger eventLogger = mock(EventLogger.class);
when(eventLoggerProvider.getEventLogger()).thenReturn(eventLogger);
List<AclRule> aclRules = new ArrayList<>();
try (StringReader stringReader = new StringReader(Arrays.stream(rules).collect(Collectors.joining(LINE_SEPARATOR)))) {
RuleSet ruleSet = AclFileParser.parse(stringReader, eventLoggerProvider);
final List<Rule> parsedRules = ruleSet.getAllRules();
for (final Rule rule : parsedRules) {
aclRules.add(new AclRule() {
@Override
public String getIdentity() {
return rule.getIdentity();
}
@Override
public ObjectType getObjectType() {
return rule.getAction().getObjectType();
}
@Override
public LegacyOperation getOperation() {
return rule.getAction().getOperation();
}
@Override
public Map<ObjectProperties.Property, String> getAttributes() {
Map<ObjectProperties.Property, String> attributes = new HashMap<>(rule.getAction().getProperties().asPropertyMap());
FirewallRule firewallRule = rule.getAclAction().getFirewallRule();
if (firewallRule != null) {
if (firewallRule instanceof HostnameFirewallRule) {
attributes.put(ObjectProperties.Property.FROM_HOSTNAME, "127.0.0.1");
} else if (firewallRule instanceof NetworkFirewallRule) {
// tests use only 127.0.0.1 at the moment
attributes.put(ObjectProperties.Property.FROM_NETWORK, "127.0.0.1");
}
}
return attributes;
}
@Override
public RuleOutcome getOutcome() {
return rule.getRuleOutcome();
}
});
}
}
configureACL(aclRules.toArray(new AclRule[aclRules.size()]));
}
use of org.apache.qpid.server.security.access.firewall.NetworkFirewallRule in project qpid-broker-j by apache.
the class NetworkFirewallRuleTest method testMultipleNetworks.
public void testMultipleNetworks() throws Exception {
String[] ipAddressesInRule = new String[] { OTHER_IP_1, OTHER_IP_2 };
_networkFirewallRule = new NetworkFirewallRule(ipAddressesInRule);
assertFalse(_networkFirewallRule.matches(_addressNotInRule));
for (String ipAddressInRule : ipAddressesInRule) {
assertTrue(_networkFirewallRule.matches(InetAddress.getByName(ipAddressInRule)));
}
}
use of org.apache.qpid.server.security.access.firewall.NetworkFirewallRule in project qpid-broker-j by apache.
the class NetworkFirewallRuleTest method testNetMask.
public void testNetMask() throws Exception {
String ipAddressInRule = "192.168.23.0/24";
_networkFirewallRule = new NetworkFirewallRule(ipAddressInRule);
assertFalse(_networkFirewallRule.matches(InetAddress.getByName("192.168.24.1")));
assertTrue(_networkFirewallRule.matches(InetAddress.getByName("192.168.23.0")));
assertTrue(_networkFirewallRule.matches(InetAddress.getByName("192.168.23.255")));
}
use of org.apache.qpid.server.security.access.firewall.NetworkFirewallRule in project qpid-broker-j by apache.
the class NetworkFirewallRuleTest method testIpRule.
public void testIpRule() throws Exception {
String ipAddressInRule = OTHER_IP_1;
_networkFirewallRule = new NetworkFirewallRule(ipAddressInRule);
assertFalse(_networkFirewallRule.matches(_addressNotInRule));
assertTrue(_networkFirewallRule.matches(InetAddress.getByName(ipAddressInRule)));
}
Aggregations