Search in sources :

Example 11 with ConnectionPrincipal

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;
        }
    });
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConnectionPrincipal(org.apache.qpid.server.connection.ConnectionPrincipal) Subject(javax.security.auth.Subject) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

ConnectionPrincipal (org.apache.qpid.server.connection.ConnectionPrincipal)11 Subject (javax.security.auth.Subject)9 AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)5 InetSocketAddress (java.net.InetSocketAddress)4 ManagementConnectionPrincipal (org.apache.qpid.server.security.auth.ManagementConnectionPrincipal)4 Test (org.junit.Test)4 InetAddress (java.net.InetAddress)3 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 SessionPrincipal (org.apache.qpid.server.connection.SessionPrincipal)2 TaskPrincipal (org.apache.qpid.server.security.auth.TaskPrincipal)2 SocketAddress (java.net.SocketAddress)1 LogMessage (org.apache.qpid.server.logging.LogMessage)1 LogSubject (org.apache.qpid.server.logging.LogSubject)1 GenericPrincipal (org.apache.qpid.server.model.preferences.GenericPrincipal)1 Result (org.apache.qpid.server.security.Result)1 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)1 AuthenticationResult (org.apache.qpid.server.security.auth.AuthenticationResult)1 SocketConnectionPrincipal (org.apache.qpid.server.security.auth.SocketConnectionPrincipal)1 Before (org.junit.Before)1