Search in sources :

Example 1 with SignedOslpEnvelopeDto

use of org.opensmartgridplatform.oslp.SignedOslpEnvelopeDto in project open-smart-grid-platform by OSGP.

the class SigningService method doSignMessage.

private void doSignMessage(final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto, final String correlationUid, final String deviceIdentification, final Destination replyToQueue) {
    final byte[] deviceId = unsignedOslpEnvelopeDto.getDeviceId();
    final byte[] sequenceNumber = unsignedOslpEnvelopeDto.getSequenceNumber();
    final Message payloadMessage = unsignedOslpEnvelopeDto.getPayloadMessage();
    final String organisationIdentification = unsignedOslpEnvelopeDto.getOrganisationIdentification();
    final int messagePriority = unsignedOslpEnvelopeDto.getMessagePriority();
    final boolean scheduled = unsignedOslpEnvelopeDto.isScheduled();
    final OslpEnvelope oslpEnvelope = new OslpEnvelope.Builder().withDeviceId(deviceId).withSequenceNumber(sequenceNumber).withPrimaryKey(this.privateKey).withSignature(this.signature).withProvider(this.signatureProvider).withPayloadMessage(payloadMessage).build();
    ResponseMessage responseMessage;
    if (oslpEnvelope == null) {
        LOGGER.error("Message for device: {} with correlationId: {} NOT SIGNED, sending error to protocol-adapter", deviceIdentification, correlationUid);
        responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(new OsgpException(ComponentType.UNKNOWN, "Failed to build signed OslpEnvelope", null)).withDataObject(unsignedOslpEnvelopeDto).withMessagePriority(messagePriority).withScheduled(scheduled).withRetryHeader(new RetryHeader()).build();
    } else {
        LOGGER.info("Message for device: {} with correlationId: {} signed, sending response to protocol-adapter", deviceIdentification, correlationUid);
        final SignedOslpEnvelopeDto signedOslpEnvelopeDto = new SignedOslpEnvelopeDto(oslpEnvelope, unsignedOslpEnvelopeDto);
        responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(ResponseMessageResultType.OK).withDataObject(signedOslpEnvelopeDto).withMessagePriority(messagePriority).withScheduled(scheduled).withRetryHeader(new RetryHeader()).build();
    }
    this.signingServerResponseMessageSender.send(responseMessage, "SIGNING_RESPONSE", replyToQueue);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) Message(org.opensmartgridplatform.oslp.Oslp.Message) SignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.SignedOslpEnvelopeDto) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) RetryHeader(org.opensmartgridplatform.shared.infra.jms.RetryHeader) OslpEnvelope(org.opensmartgridplatform.oslp.OslpEnvelope)

Example 2 with SignedOslpEnvelopeDto

use of org.opensmartgridplatform.oslp.SignedOslpEnvelopeDto in project open-smart-grid-platform by OSGP.

the class SigningServerResponsesMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    try {
        LOGGER.info("Received message of type: {}", message.getJMSType());
        final ObjectMessage objectMessage = (ObjectMessage) message;
        final String messageType = objectMessage.getJMSType();
        final int messagePriority = objectMessage.getJMSPriority();
        final String correlationId = objectMessage.getJMSCorrelationID();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
        final ResponseMessageResultType result = responseMessage == null ? null : responseMessage.getResult();
        // Check the result.
        if (result.equals(ResponseMessageResultType.NOT_OK)) {
            LOGGER.error("OslpEnvelope was not signed by signing-server. Unable to send request to device: {}", deviceIdentification);
            this.oslpSigningService.handleError(deviceIdentification, responseMessage);
            return;
        }
        LOGGER.info("Read signed message, messageType: {}, messagePriority: {}, deviceIdentification: {}, result: {}, correlationId: {}", messageType, messagePriority, deviceIdentification, result, correlationId);
        // Get the DTO object containing signed OslpEnvelope.
        final SignedOslpEnvelopeDto signedOslpEnvelopeDto = (SignedOslpEnvelopeDto) responseMessage.getDataObject();
        this.oslpSigningService.handleSignedOslpEnvelope(signedOslpEnvelopeDto, deviceIdentification);
    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    }
}
Also used : ObjectMessage(javax.jms.ObjectMessage) SignedOslpEnvelopeDto(org.opensmartgridplatform.oslp.SignedOslpEnvelopeDto) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)

Aggregations

SignedOslpEnvelopeDto (org.opensmartgridplatform.oslp.SignedOslpEnvelopeDto)2 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)2 JMSException (javax.jms.JMSException)1 ObjectMessage (javax.jms.ObjectMessage)1 Message (org.opensmartgridplatform.oslp.Oslp.Message)1 OslpEnvelope (org.opensmartgridplatform.oslp.OslpEnvelope)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)1 RetryHeader (org.opensmartgridplatform.shared.infra.jms.RetryHeader)1