Search in sources :

Example 1 with WebSocketImpl

use of com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl in project azure-iot-sdk-java by Azure.

the class AmqpSendHandler method onConnectionBound.

/**
     * Event handler for the connection bound event
     * @param event The proton event object
     */
@Override
public void onConnectionBound(Event event) {
    // Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_010: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
    // Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_011: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
    Transport transport = event.getConnection().getTransport();
    if (transport != null) {
        if (this.iotHubServiceClientProtocol == IotHubServiceClientProtocol.AMQPS_WS) {
            WebSocketImpl webSocket = new WebSocketImpl();
            webSocket.configure(this.webSocketHostName, WEBSOCKET_PATH, 0, WEBSOCKET_SUB_PROTOCOL, null, null);
            ((TransportInternal) transport).addTransportLayer(webSocket);
        }
        Sasl sasl = transport.sasl();
        sasl.plain(this.userName, this.sasToken);
        SslDomain domain = makeDomain(SslDomain.Mode.CLIENT);
        domain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
        Ssl ssl = transport.ssl(domain);
    }
}
Also used : WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) TransportInternal(org.apache.qpid.proton.engine.impl.TransportInternal)

Example 2 with WebSocketImpl

use of com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl in project azure-iot-sdk-java by Azure.

the class AmqpSendHandlerTest method onConnectionBound_call_flow_and_init_ok_amqp_ws.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_009: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_024: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBound_call_flow_and_init_ok_amqp_ws() {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    String hostAddr = hostName + ":443";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
    AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            event.getConnection();
            result = connection;
            connection.getTransport();
            result = transportInternal;
            new WebSocketImpl();
            result = webSocket;
            webSocket.configure(anyString, anyString, 0, anyString, null, null);
            transportInternal.addTransportLayer(webSocket);
            sasl.plain(anyString, anyString);
            Proton.sslDomain();
            result = sslDomain;
            sslDomain.init(SslDomain.Mode.CLIENT);
            sslDomain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
            transportInternal.ssl(sslDomain);
        }
    };
    // Act
    amqpSendHandler.onConnectionBound(event);
}
Also used : Expectations(mockit.Expectations) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 3 with WebSocketImpl

use of com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnection method onConnectionBound.

/**
     * Event handler for the connection bound event. Sets Sasl authentication and proper authentication mode.
     * @param event The Proton Event object.
     */
@Override
public void onConnectionBound(Event event) {
    logger.LogDebug("Entered in method %s", logger.getMethodName());
    // Codes_SRS_AMQPSIOTHUBCONNECTION_15_030: [The event handler shall get the Transport (Proton) object from the event.]
    Transport transport = event.getConnection().getTransport();
    if (transport != null) {
        if (this.useWebSockets) {
            WebSocketImpl webSocket = new WebSocketImpl();
            webSocket.configure(this.hostName, WEB_SOCKET_PATH, 0, WEB_SOCKET_SUB_PROTOCOL, null, null);
            ((TransportInternal) transport).addTransportLayer(webSocket);
        }
        // Codes_SRS_AMQPSIOTHUBCONNECTION_15_031: [The event handler shall set the SASL_PLAIN authentication on the transport using the given user name and sas token.]
        Sasl sasl = transport.sasl();
        sasl.plain(this.userName, this.sasToken);
        SslDomain domain = makeDomain();
        transport.ssl(domain);
    }
    synchronized (openLock) {
        openLock.notifyLock();
    }
    logger.LogDebug("Exited from method %s", logger.getMethodName());
}
Also used : WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) TransportInternal(org.apache.qpid.proton.engine.impl.TransportInternal)

Example 4 with WebSocketImpl

use of com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl in project azure-iot-sdk-java by Azure.

the class AmqpFeedbackReceivedHandler method onConnectionBound.

@Override
public void onConnectionBound(Event event) {
    // Codes_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_009: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
    // Codes_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
    Transport transport = event.getConnection().getTransport();
    if (transport != null) {
        if (this.iotHubServiceClientProtocol == IotHubServiceClientProtocol.AMQPS_WS) {
            WebSocketImpl webSocket = new WebSocketImpl();
            webSocket.configure(this.webSocketHostName, WEBSOCKET_PATH, 0, WEBSOCKET_SUB_PROTOCOL, null, null);
            ((TransportInternal) transport).addTransportLayer(webSocket);
        }
        Sasl sasl = transport.sasl();
        sasl.plain(this.userName, this.sasToken);
        SslDomain domain = makeDomain(SslDomain.Mode.CLIENT);
        domain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
        Ssl ssl = transport.ssl(domain);
    }
}
Also used : WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) TransportInternal(org.apache.qpid.proton.engine.impl.TransportInternal)

Example 5 with WebSocketImpl

use of com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl in project azure-iot-sdk-java by Azure.

the class AmqpFileUploadNotificationReceivedHandler method onConnectionBound.

@Override
public void onConnectionBound(Event event) {
    // Codes_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_019: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
    // Codes_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
    Transport transport = event.getConnection().getTransport();
    if (transport != null) {
        if (this.iotHubServiceClientProtocol == IotHubServiceClientProtocol.AMQPS_WS) {
            // Codes_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_020: [** The event handler shall not initialize WebSocket if the protocol is AMQP **]
            WebSocketImpl webSocket = new WebSocketImpl();
            webSocket.configure(this.webSocketHostName, WEBSOCKET_PATH, 0, WEBSOCKET_SUB_PROTOCOL, null, null);
            ((TransportInternal) transport).addTransportLayer(webSocket);
        }
        Sasl sasl = transport.sasl();
        sasl.plain(this.userName, this.sasToken);
        SslDomain domain = makeDomain(SslDomain.Mode.CLIENT);
        domain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
        Ssl ssl = transport.ssl(domain);
    }
}
Also used : WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) TransportInternal(org.apache.qpid.proton.engine.impl.TransportInternal)

Aggregations

WebSocketImpl (com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl)8 TransportInternal (org.apache.qpid.proton.engine.impl.TransportInternal)4 Test (org.junit.Test)4 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)3 Expectations (mockit.Expectations)3 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)1 AmqpFeedbackReceivedHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler)1 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)1