Search in sources :

Example 11 with Result

use of org.apache.qpid.server.security.Result 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)

Example 12 with Result

use of org.apache.qpid.server.security.Result in project qpid-broker-j by apache.

the class RuleBasedAccessControlTest method testNoSubjectAlwaysDefers.

/**
 * ACL plugin must always defer if there is no  subject attached to the thread.
 */
public void testNoSubjectAlwaysDefers() {
    setUpGroupAccessControl();
    final Result result = _plugin.authorise(LegacyOperation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
    assertEquals(Result.DEFER, result);
}
Also used : Result(org.apache.qpid.server.security.Result)

Aggregations

Result (org.apache.qpid.server.security.Result)12 Subject (javax.security.auth.Subject)2 AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)2 Iterators.cycle (com.google.common.collect.Iterators.cycle)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 BufferedInputStream (java.io.BufferedInputStream)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Serializable (java.io.Serializable)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1