use of org.apache.qpid.server.security.AccessControl in project qpid-broker-j by apache.
the class AbstractConfiguredObject method authorise.
private void authorise(final ConfiguredObject<?> configuredObject, SecurityToken token, final Operation operation, Map<String, Object> arguments) {
AccessControl accessControl = getAccessControl();
if (accessControl != null) {
Result result = accessControl.authorise(token, operation, configuredObject, arguments);
LOGGER.debug("authorise returned {}", result);
if (result == Result.DEFER) {
result = accessControl.getDefault();
LOGGER.debug("authorise returned DEFER, returing default: {}", result);
}
if (result == Result.DENIED) {
Class<? extends ConfiguredObject> categoryClass = configuredObject.getCategoryClass();
String objectName = (String) configuredObject.getAttribute(ConfiguredObject.NAME);
String operationName = operation.getName().equals(operation.getType().name()) ? operation.getName() : (operation.getType().name() + "(" + operation.getName() + ")");
StringBuilder exceptionMessage = new StringBuilder(String.format("Permission %s is denied for : %s '%s'", operationName, categoryClass.getSimpleName(), objectName));
Model model = configuredObject.getModel();
Class<? extends ConfiguredObject> parentClass = model.getParentType(categoryClass);
if (parentClass != null) {
exceptionMessage.append(" on");
String objectCategory = parentClass.getSimpleName();
ConfiguredObject<?> parent = configuredObject.getParent();
exceptionMessage.append(" ").append(objectCategory);
if (parent != null) {
exceptionMessage.append(" '").append(parent.getAttribute(ConfiguredObject.NAME)).append("'");
}
}
throw new AccessControlException(exceptionMessage.toString());
}
}
}
use of org.apache.qpid.server.security.AccessControl in project qpid-broker-j by apache.
the class AbstractVirtualHostTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
SystemConfig systemConfig = mock(SystemConfig.class);
when(systemConfig.getEventLogger()).thenReturn(mock(EventLogger.class));
when(systemConfig.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
AccessControl accessControlMock = BrokerTestHelper.createAccessControlMock();
Principal systemPrincipal = mock(Principal.class);
Broker<?> broker = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(Broker.class, systemPrincipal, accessControlMock);
when(broker.getParent()).thenReturn(systemConfig);
when(broker.getModel()).thenReturn(BrokerModel.getInstance());
_taskExecutor = new TaskExecutorImpl();
_taskExecutor.start();
when(broker.getTaskExecutor()).thenReturn(_taskExecutor);
when(broker.getChildExecutor()).thenReturn(_taskExecutor);
_node = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, systemPrincipal, accessControlMock);
when(_node.getParent()).thenReturn(broker);
when(_node.getModel()).thenReturn(BrokerModel.getInstance());
when(_node.getTaskExecutor()).thenReturn(_taskExecutor);
when(_node.getChildExecutor()).thenReturn(_taskExecutor);
when(_node.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
when(_node.getCategoryClass()).thenReturn(VirtualHostNode.class);
when(_node.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
_failingStore = mock(MessageStore.class);
doThrow(new RuntimeException("Cannot open store")).when(_failingStore).openMessageStore(any(ConfiguredObject.class));
}
use of org.apache.qpid.server.security.AccessControl in project qpid-broker-j by apache.
the class VirtualHostQueueCreationTest method setUp.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void setUp() throws Exception {
super.setUp();
EventLogger eventLogger = mock(EventLogger.class);
ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
_taskExecutor = new CurrentThreadTaskExecutor();
_taskExecutor.start();
SystemConfig<?> context = mock(SystemConfig.class);
when(context.getEventLogger()).thenReturn(eventLogger);
when(context.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
Principal systemPrincipal = mock(Principal.class);
AccessControl accessControl = BrokerTestHelper.createAccessControlMock();
Broker broker = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(Broker.class, systemPrincipal, accessControl);
when(broker.getObjectFactory()).thenReturn(objectFactory);
when(broker.getCategoryClass()).thenReturn(Broker.class);
when(broker.getParent()).thenReturn(context);
when(broker.getModel()).thenReturn(objectFactory.getModel());
when(broker.getTaskExecutor()).thenReturn(_taskExecutor);
when(broker.getChildExecutor()).thenReturn(_taskExecutor);
_virtualHostNode = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, systemPrincipal, accessControl);
when(_virtualHostNode.getParent()).thenReturn(broker);
when(_virtualHostNode.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
when(_virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
when(_virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
when(_virtualHostNode.getTaskExecutor()).thenReturn(_taskExecutor);
when(_virtualHostNode.getChildExecutor()).thenReturn(_taskExecutor);
when(_virtualHostNode.getCategoryClass()).thenReturn(VirtualHostNode.class);
when(_virtualHostNode.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
_virtualHost = createHost();
}
use of org.apache.qpid.server.security.AccessControl in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNodeTest method testDeleteVHNDeniedByACL.
public void testDeleteVHNDeniedByACL() 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(null, Operation.DELETE, node, Collections.<String, Object>emptyMap())).thenReturn(Result.DENIED);
try {
node.delete();
fail("Exception not throws");
} catch (AccessControlException ace) {
// PASS
}
assertEquals("Virtual host node state changed unexpectedly", State.ACTIVE, node.getState());
node.close();
}
use of org.apache.qpid.server.security.AccessControl in project qpid-broker-j by apache.
the class VirtualHostLoggerTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
_taskExecutor = new TaskExecutorImpl();
_taskExecutor.start();
Model model = BrokerModel.getInstance();
EventLogger eventLogger = mock(EventLogger.class);
SystemConfig<?> systemConfig = mock(SystemConfig.class);
when(systemConfig.getModel()).thenReturn(model);
when(systemConfig.getChildExecutor()).thenReturn(_taskExecutor);
when(systemConfig.getEventLogger()).thenReturn(eventLogger);
when(systemConfig.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
doReturn(SystemConfig.class).when(systemConfig).getCategoryClass();
Principal systemPrincipal = mock(Principal.class);
AccessControl accessControlMock = BrokerTestHelper.createAccessControlMock();
Broker broker = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(Broker.class, systemPrincipal, accessControlMock);
when(broker.getModel()).thenReturn(model);
when(broker.getChildExecutor()).thenReturn(_taskExecutor);
when(broker.getParent()).thenReturn(systemConfig);
doReturn(Broker.class).when(broker).getCategoryClass();
VirtualHostNode node = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, systemPrincipal, accessControlMock);
when(node.getModel()).thenReturn(model);
when(node.getChildExecutor()).thenReturn(_taskExecutor);
when(node.getParent()).thenReturn(broker);
when(node.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
doReturn(VirtualHostNode.class).when(node).getCategoryClass();
when(node.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
// use real VH object rather then mock in order to test create/start/stop functionality
Map<String, Object> attributes = new HashMap<>();
attributes.put(VirtualHost.NAME, getName());
attributes.put(VirtualHost.TYPE, TestMemoryVirtualHost.VIRTUAL_HOST_TYPE);
_virtualHost = new TestMemoryVirtualHost(attributes, node);
_virtualHost.open();
_baseFolder = new File(TMP_FOLDER, "test-sub-folder");
_logFile = new File(_baseFolder, "tmp-virtual-host.log." + System.currentTimeMillis());
if (_baseFolder.exists()) {
FileUtils.delete(_baseFolder, true);
}
}
Aggregations