Search in sources :

Example 1 with AmqpConnectionMetaData

use of org.apache.qpid.server.connection.AmqpConnectionMetaData in project qpid-broker-j by apache.

the class ManagementNode method performConfiguredObjectOperation.

private InternalMessage performConfiguredObjectOperation(final ConfiguredObject<?> object, final InternalMessage message, final ConfiguredObjectOperation<ConfiguredObject<?>> method) {
    final InternalMessageHeader requestHeader = message.getMessageHeader();
    final Map<String, Object> headers = requestHeader.getHeaderMap();
    try {
        Map<String, Object> parameters = new HashMap<>(headers);
        parameters.remove(KEY_ATTRIBUTE);
        parameters.remove(IDENTITY_ATTRIBUTE);
        parameters.remove(TYPE_ATTRIBUTE);
        parameters.remove(INDEX_ATTRIBUTE);
        parameters.remove(OPERATION_HEADER);
        parameters.keySet().removeIf(paramName -> paramName.startsWith("JMS_QPID"));
        AmqpConnectionMetaData callerConnectionMetaData = getCallerConnectionMetaData();
        if (method.isSecure(object, parameters) && !(callerConnectionMetaData.getTransport().isSecure() || callerConnectionMetaData.getPort().isAllowConfidentialOperationsOnInsecureChannels())) {
            return createFailureResponse(message, STATUS_CODE_FORBIDDEN, "Operation '" + method.getName() + "' can only be performed over a secure (AMQPS) connection");
        }
        final MutableMessageHeader responseHeader = new MutableMessageHeader();
        responseHeader.setCorrelationId(requestHeader.getCorrelationId() == null ? requestHeader.getMessageId() : requestHeader.getCorrelationId());
        responseHeader.setMessageId(UUID.randomUUID().toString());
        responseHeader.setHeader(STATUS_CODE_HEADER, STATUS_CODE_OK);
        final Object result = method.perform(object, parameters);
        return createManagedOperationResponse(method, responseHeader, result);
    } catch (IllegalArgumentException | IllegalStateException | IllegalConfigurationException e) {
        return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, e.getMessage());
    } catch (AccessControlException e) {
        return createFailureResponse(message, STATUS_CODE_FORBIDDEN, "Forbidden");
    }
}
Also used : AmqpConnectionMetaData(org.apache.qpid.server.connection.AmqpConnectionMetaData) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlException(java.security.AccessControlException) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Aggregations

AccessControlException (java.security.AccessControlException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 AmqpConnectionMetaData (org.apache.qpid.server.connection.AmqpConnectionMetaData)1 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 ManagedObject (org.apache.qpid.server.model.ManagedObject)1