Search in sources :

Example 11 with AMQPConnection

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;
        }
    });
}
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)

Example 12 with AMQPConnection

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

Aggregations

AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)12 Principal (java.security.Principal)4 ConnectionPrincipal (org.apache.qpid.server.connection.ConnectionPrincipal)4 InetSocketAddress (java.net.InetSocketAddress)3 Subject (javax.security.auth.Subject)3 AbstractAMQPConnection (org.apache.qpid.server.transport.AbstractAMQPConnection)3 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 InetAddress (java.net.InetAddress)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)2 ManagementConnectionPrincipal (org.apache.qpid.server.security.auth.ManagementConnectionPrincipal)2 Iterators (com.google.common.collect.Iterators)1 PeekingIterator (com.google.common.collect.PeekingIterator)1 Sets (com.google.common.collect.Sets)1 Futures.allAsList (com.google.common.util.concurrent.Futures.allAsList)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SocketAddress (java.net.SocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 AccessControlContext (java.security.AccessControlContext)1 AccessControlException (java.security.AccessControlException)1