use of org.apache.qpid.server.transport.AMQPConnection in project qpid-broker-j by apache.
the class RuleBasedAccessControlTest method testAccess.
public void testAccess() throws Exception {
final Subject subject = TestPrincipalUtils.createTestSubject("user1");
final String testVirtualHost = getName();
final InetAddress inetAddress = InetAddress.getLocalHost();
final InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 1);
AMQPConnection connectionModel = mock(AMQPConnection.class);
when(connectionModel.getRemoteSocketAddress()).thenReturn(inetSocketAddress);
subject.getPrincipals().add(new ConnectionPrincipal(connectionModel));
Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
RuleSet mockRuleSet = mock(RuleSet.class);
RuleBasedAccessControl accessControl = new RuleBasedAccessControl(mockRuleSet, BrokerModel.getInstance());
ObjectProperties properties = new ObjectProperties(testVirtualHost);
accessControl.authorise(LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, properties);
verify(mockRuleSet).check(subject, LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, properties, inetAddress);
return null;
}
});
}
use of org.apache.qpid.server.transport.AMQPConnection in project qpid-broker-j by apache.
the class RuleBasedAccessControlTest method testAccessIsDeniedIfRuleThrowsException.
public void testAccessIsDeniedIfRuleThrowsException() throws Exception {
final Subject subject = TestPrincipalUtils.createTestSubject("user1");
final InetAddress inetAddress = InetAddress.getLocalHost();
final InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 1);
AMQPConnection connectionModel = mock(AMQPConnection.class);
when(connectionModel.getRemoteSocketAddress()).thenReturn(inetSocketAddress);
subject.getPrincipals().add(new ConnectionPrincipal(connectionModel));
Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
RuleSet mockRuleSet = mock(RuleSet.class);
when(mockRuleSet.check(subject, LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY, inetAddress)).thenThrow(new RuntimeException());
RuleBasedAccessControl accessControl = new RuleBasedAccessControl(mockRuleSet, BrokerModel.getInstance());
Result result = accessControl.authorise(LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
assertEquals(Result.DENIED, result);
return null;
}
});
}
Aggregations