Search in sources :

Example 1 with InternalMessageHeader

use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.

the class ManagementNode method performManagementOperation.

private InternalMessage performManagementOperation(String operation, final InternalMessage msg) {
    final InternalMessage responseMessage;
    final InternalMessageHeader requestHeader = msg.getMessageHeader();
    final MutableMessageHeader responseHeader = new MutableMessageHeader();
    responseHeader.setCorrelationId(requestHeader.getCorrelationId() == null ? requestHeader.getMessageId() : requestHeader.getCorrelationId());
    responseHeader.setMessageId(UUID.randomUUID().toString());
    Map<?, ?> result;
    if (GET_TYPES.equals(operation)) {
        result = performGetTypes(requestHeader.getHeaderMap());
    } else if (GET_ATTRIBUTES.equals(operation)) {
        result = performGetAttributes(requestHeader.getHeaderMap());
    } else if (GET_OPERATIONS.equals(operation)) {
        result = performGetOperations(requestHeader.getHeaderMap());
    } else if (QUERY.equals(operation)) {
        if (msg.getMessageBody() instanceof Map) {
            result = performQuery(requestHeader.getHeaderMap(), (Map) (msg.getMessageBody()));
        } else {
            return createFailureResponse(msg, STATUS_CODE_BAD_REQUEST, "Body of a QUERY operation must be a map");
        }
    } else {
        return createFailureResponse(msg, STATUS_CODE_NOT_IMPLEMENTED, "Unknown operation {}", operation);
    }
    responseHeader.setHeader(STATUS_CODE_HEADER, STATUS_CODE_OK);
    responseMessage = InternalMessage.createMapMessage(_addressSpace.getMessageStore(), responseHeader, result);
    return responseMessage;
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with InternalMessageHeader

use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.

the class ManagementNode method performUpdateOperation.

private InternalMessage performUpdateOperation(final Class<? extends ConfiguredObject> clazz, final InternalMessage message) {
    InternalMessageHeader requestHeader = message.getMessageHeader();
    final Map<String, Object> headers = requestHeader.getHeaderMap();
    ConfiguredObject<?> object = findObject(clazz, headers);
    if (object != null) {
        if (message.getMessageBody() instanceof Map) {
            @SuppressWarnings("unchecked") final HashMap<String, Object> attributes = new HashMap<>((Map) message.getMessageBody());
            Object id = attributes.remove(IDENTITY_ATTRIBUTE);
            if (id != null && !String.valueOf(id).equals(object.getId().toString())) {
                return createFailureResponse(message, STATUS_CODE_FORBIDDEN, "Cannot change the value of '" + IDENTITY_ATTRIBUTE + "'");
            }
            String path = (String) attributes.remove(OBJECT_PATH);
            Class<? extends ConfiguredObject> parentType = _model.getParentType(clazz);
            if (parentType != null) {
                String attributeName = parentType.getSimpleName().toLowerCase();
                final Object parentValue = attributes.remove(attributeName);
                if (parentValue != null && !String.valueOf(parentValue).equals(object.getParent().getName())) {
                    return createFailureResponse(message, STATUS_CODE_FORBIDDEN, "Cannot change the value of '" + attributeName + "'");
                }
            }
            if (path != null && !attributes.containsKey(ConfiguredObject.NAME)) {
                String[] pathElements = getPathElements(path);
                attributes.put(ConfiguredObject.NAME, pathElements[pathElements.length - 1]);
            }
            object.setAttributes(attributes);
            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);
            return InternalMessage.createMapMessage(_addressSpace.getMessageStore(), responseHeader, _managementOutputConverter.convertToOutput(object, true));
        } else {
            return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, "Message body must be a map");
        }
    } else {
        return createFailureResponse(message, STATUS_CODE_NOT_FOUND, "No such object");
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with InternalMessageHeader

use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.

the class ManagementNode method performReadOperation.

private InternalMessage performReadOperation(final Class<? extends ConfiguredObject> clazz, final InternalMessage message) {
    InternalMessageHeader requestHeader = message.getMessageHeader();
    final Map<String, Object> headers = requestHeader.getHeaderMap();
    final boolean actuals = headers.get(ACTUALS_ATTRIBUTE) == null || Boolean.parseBoolean(String.valueOf(headers.get(ACTUALS_ATTRIBUTE)));
    ConfiguredObject<?> object = findObject(clazz, headers);
    if (object != null) {
        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);
        return InternalMessage.createMapMessage(_addressSpace.getMessageStore(), responseHeader, _managementOutputConverter.convertToOutput(object, actuals));
    } else {
        return createFailureResponse(message, STATUS_CODE_NOT_FOUND, "Not found");
    }
}
Also used : InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 4 with InternalMessageHeader

use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.

the class ManagementNode method performDeleteOperation.

private InternalMessage performDeleteOperation(final Class<? extends ConfiguredObject> clazz, final InternalMessage message) {
    InternalMessageHeader requestHeader = message.getMessageHeader();
    final Map<String, Object> headers = requestHeader.getHeaderMap();
    ConfiguredObject<?> object = findObject(clazz, headers);
    if (object != null) {
        try {
            object.delete();
            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_NO_CONTENT);
            return InternalMessage.createMapMessage(_addressSpace.getMessageStore(), responseHeader, Collections.emptyMap());
        } catch (IntegrityViolationException e) {
            return createFailureResponse(message, STATUS_CODE_FORBIDDEN, e.getMessage());
        }
    } else {
        return createFailureResponse(message, STATUS_CODE_NOT_FOUND, "Not Found");
    }
}
Also used : InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) IntegrityViolationException(org.apache.qpid.server.model.IntegrityViolationException)

Example 5 with InternalMessageHeader

use of org.apache.qpid.server.message.internal.InternalMessageHeader 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

InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)22 InternalMessageMetaData (org.apache.qpid.server.message.internal.InternalMessageMetaData)9 HashMap (java.util.HashMap)7 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)7 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)6 ManagedObject (org.apache.qpid.server.model.ManagedObject)6 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)5 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)3 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)2 AccessControlException (java.security.AccessControlException)1 Certificate (java.security.cert.Certificate)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 ArrayList (java.util.ArrayList)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 AmqpConnectionMetaData (org.apache.qpid.server.connection.AmqpConnectionMetaData)1 ConfiguredObjectOperation (org.apache.qpid.server.model.ConfiguredObjectOperation)1 IntegrityViolationException (org.apache.qpid.server.model.IntegrityViolationException)1 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)1