use of org.apache.qpid.server.connection.ConnectionPrincipal in project qpid-broker-j by apache.
the class RuleBasedAccessControlTest method testAccess.
@Test
public void testAccess() throws Exception {
final Subject subject = TestPrincipalUtils.createTestSubject("user1");
final String testVirtualHost = getTestName();
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);
return null;
}
});
}
Aggregations