Search in sources :

Example 6 with AccessControl

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

the class BrokerTestHelper method createAccessControlMock.

public static AccessControl createAccessControlMock() {
    AccessControl mock = mock(AccessControl.class);
    when(mock.authorise(any(SecurityToken.class), any(Operation.class), any(ConfiguredObject.class))).thenReturn(Result.DEFER);
    when(mock.authorise(any(SecurityToken.class), any(Operation.class), any(ConfiguredObject.class), any(Map.class))).thenReturn(Result.DEFER);
    when(mock.getDefault()).thenReturn(Result.ALLOWED);
    return mock;
}
Also used : SecurityToken(org.apache.qpid.server.security.SecurityToken) Operation(org.apache.qpid.server.security.access.Operation) HashMap(java.util.HashMap) Map(java.util.Map) AccessControl(org.apache.qpid.server.security.AccessControl)

Example 7 with AccessControl

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

the class AbstractStandardVirtualHostNodeTest method testUpdateVHNDeniedByACL.

// ***************  VHN Access Control Tests  ***************
public void testUpdateVHNDeniedByACL() throws Exception {
    AccessControl mockAccessControl = mock(AccessControl.class);
    DurableConfigurationStore configStore = configStoreThatProducesNoRecords();
    Map<String, Object> nodeAttributes = new HashMap<>();
    nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
    nodeAttributes.put(VirtualHostNode.ID, _nodeId);
    TestVirtualHostNode node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
    node.setAccessControl(mockAccessControl);
    node.open();
    node.start();
    when(mockAccessControl.authorise(eq(null), eq(Operation.UPDATE), same(node), any())).thenReturn(Result.DENIED);
    assertNull(node.getDescription());
    try {
        node.setAttributes(Collections.<String, Object>singletonMap(VirtualHostNode.DESCRIPTION, "My virtualhost node"));
        fail("Exception not throws");
    } catch (AccessControlException ace) {
    // PASS
    }
    assertNull("Description unexpected updated", node.getDescription());
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) AccessControlException(java.security.AccessControlException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AccessControl(org.apache.qpid.server.security.AccessControl)

Example 8 with AccessControl

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

the class AbstractStandardVirtualHostNodeTest method testStopVHNDeniedByACL.

public void testStopVHNDeniedByACL() throws Exception {
    AccessControl mockAccessControl = mock(AccessControl.class);
    DurableConfigurationStore configStore = configStoreThatProducesNoRecords();
    Map<String, Object> nodeAttributes = new HashMap<>();
    nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
    nodeAttributes.put(VirtualHostNode.ID, _nodeId);
    TestVirtualHostNode node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
    node.setAccessControl(mockAccessControl);
    node.open();
    node.start();
    when(mockAccessControl.authorise(eq(null), eq(Operation.UPDATE), same(node), any())).thenReturn(Result.DENIED);
    try {
        node.stop();
        fail("Exception not throws");
    } catch (AccessControlException ace) {
    // PASS
    }
    assertEquals("Virtual host node state changed unexpectedly", State.ACTIVE, node.getState());
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) AccessControlException(java.security.AccessControlException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AccessControl(org.apache.qpid.server.security.AccessControl)

Aggregations

AccessControl (org.apache.qpid.server.security.AccessControl)8 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)6 HashMap (java.util.HashMap)5 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)5 AccessControlException (java.security.AccessControlException)4 Principal (java.security.Principal)3 EventLogger (org.apache.qpid.server.logging.EventLogger)3 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)3 PreferenceStore (org.apache.qpid.server.store.preferences.PreferenceStore)3 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)2 Broker (org.apache.qpid.server.model.Broker)2 File (java.io.File)1 Map (java.util.Map)1 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 BrokerModel (org.apache.qpid.server.model.BrokerModel)1 ConfiguredObjectFactory (org.apache.qpid.server.model.ConfiguredObjectFactory)1 ConfiguredObjectFactoryImpl (org.apache.qpid.server.model.ConfiguredObjectFactoryImpl)1 Model (org.apache.qpid.server.model.Model)1 SystemConfig (org.apache.qpid.server.model.SystemConfig)1