Search in sources :

Example 1 with AuthenticationParser

use of com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser in project azure-iot-sdk-java by Azure.

the class AuthenticationParserTest method testConstructor.

// Tests_SRS_AUTHENTICATION_PARSER_34_001: [This Constructor shall create a new instance of an authenticationParser object and return it.]
@Test
public void testConstructor() {
    // act
    AuthenticationParser parser = new AuthenticationParser();
    // assert
    assertNotNull(parser);
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) Test(org.junit.Test)

Example 2 with AuthenticationParser

use of com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser in project azure-iot-sdk-java by Azure.

the class AuthenticationParserTest method testThumbprintParserProperty.

// Tests_SRS_AUTHENTICATION_PARSER_34_004: [This method shall return the value of this object's thumbprint.]
// Tests_SRS_AUTHENTICATION_PARSER_34_005: [This method shall set the value of this object's thumbprint equal to the provided value.]
@Test
public void testThumbprintParserProperty() {
    // arrange
    AuthenticationParser parser = new AuthenticationParser();
    X509ThumbprintParser thumbprintParser = new X509ThumbprintParser();
    thumbprintParser.setPrimaryThumbprint("1234");
    thumbprintParser.setSecondaryThumbprint("5678");
    // act
    parser.setThumbprint(thumbprintParser);
    // assert
    assertEquals(thumbprintParser, parser.getThumbprint());
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) Test(org.junit.Test)

Example 3 with AuthenticationParser

use of com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser in project azure-iot-sdk-java by Azure.

the class Tools method addModules.

private static void addModules(Iterable<Module> modules, String connectionString) throws IOException, IotHubException {
    if (modules == null) {
        throw new IllegalArgumentException("modules cannot be null");
    }
    IotHubConnectionString iotHubConnectionString = IotHubConnectionString.createConnectionString(connectionString);
    URL url = getBulkDeviceAddUrl(iotHubConnectionString);
    List<ExportImportDeviceParser> parsers = new ArrayList<>();
    for (Module module : modules) {
        ExportImportDeviceParser exportImportDevice = new ExportImportDeviceParser();
        exportImportDevice.setId(module.getDeviceId());
        exportImportDevice.setModuleId(module.getId());
        AuthenticationParser authenticationParser = new AuthenticationParser();
        if (module.getAuthenticationType() == AuthenticationType.SAS) {
            authenticationParser.setType(AuthenticationTypeParser.SAS);
            authenticationParser.setSymmetricKey(new SymmetricKeyParser(module.getSymmetricKey().getPrimaryKey(), module.getSymmetricKey().getSecondaryKey()));
        } else {
            authenticationParser.setType(AuthenticationTypeParser.SELF_SIGNED);
            authenticationParser.setThumbprint(new X509ThumbprintParser(module.getPrimaryThumbprint(), module.getSecondaryThumbprint()));
        }
        exportImportDevice.setAuthentication(authenticationParser);
        exportImportDevice.setImportMode(IMPORT_MODE_CREATE);
        parsers.add(exportImportDevice);
    }
    ExportImportDevicesParser body = new ExportImportDevicesParser();
    body.setExportImportDevices(parsers);
    bulkRegistryOperation(body.toJson(), url, connectionString);
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) ExportImportDeviceParser(com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser) ArrayList(java.util.ArrayList) X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Module(com.microsoft.azure.sdk.iot.service.Module) URL(java.net.URL)

Example 4 with AuthenticationParser

use of com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser in project azure-iot-sdk-java by Azure.

the class Tools method addDevices.

private static void addDevices(Iterable<Device> devices, String connectionString) throws IOException, IotHubException {
    if (devices == null) {
        throw new IllegalArgumentException("devices cannot be null");
    }
    IotHubConnectionString iotHubConnectionString = IotHubConnectionString.createConnectionString(connectionString);
    URL url = getBulkDeviceAddUrl(iotHubConnectionString);
    List<ExportImportDeviceParser> parsers = new ArrayList<>();
    for (Device device : devices) {
        ExportImportDeviceParser exportImportDevice = new ExportImportDeviceParser();
        exportImportDevice.setId(device.getDeviceId());
        AuthenticationParser authenticationParser = new AuthenticationParser();
        if (device.getAuthenticationType() == AuthenticationType.SAS) {
            authenticationParser.setType(AuthenticationTypeParser.SAS);
            authenticationParser.setSymmetricKey(new SymmetricKeyParser(device.getSymmetricKey().getPrimaryKey(), device.getSymmetricKey().getSecondaryKey()));
        } else {
            authenticationParser.setType(AuthenticationTypeParser.SELF_SIGNED);
            authenticationParser.setThumbprint(new X509ThumbprintParser(device.getPrimaryThumbprint(), device.getSecondaryThumbprint()));
        }
        exportImportDevice.setAuthentication(authenticationParser);
        exportImportDevice.setImportMode(IMPORT_MODE_CREATE);
        parsers.add(exportImportDevice);
    }
    ExportImportDevicesParser body = new ExportImportDevicesParser();
    body.setExportImportDevices(parsers);
    bulkRegistryOperation(body.toJson(), url, connectionString);
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) Device(com.microsoft.azure.sdk.iot.service.Device) ExportImportDeviceParser(com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser) ArrayList(java.util.ArrayList) X509ThumbprintParser(com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) URL(java.net.URL)

Example 5 with AuthenticationParser

use of com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser in project azure-iot-sdk-java by Azure.

the class AuthenticationParserTest method testSymmetricKeyParserProperty.

// Tests_SRS_AUTHENTICATION_PARSER_34_006: [This method shall return the value of this object's symmetricKey.]
// Tests_SRS_AUTHENTICATION_PARSER_34_007: [This method shall set the value of symmetricKey equal to the provided value.]
@Test
public void testSymmetricKeyParserProperty() {
    // arrange
    AuthenticationParser parser = new AuthenticationParser();
    SymmetricKeyParser symmetricKeyParser = new SymmetricKeyParser();
    symmetricKeyParser.setPrimaryKey("1234");
    symmetricKeyParser.setPrimaryKey("5678");
    // act
    parser.setSymmetricKey(symmetricKeyParser);
    // assert
    assertEquals(symmetricKeyParser, parser.getSymmetricKey());
}
Also used : AuthenticationParser(com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser) SymmetricKeyParser(com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser) Test(org.junit.Test)

Aggregations

AuthenticationParser (com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser)6 Test (org.junit.Test)4 SymmetricKeyParser (com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser)3 X509ThumbprintParser (com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser)3 ExportImportDeviceParser (com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser)2 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Device (com.microsoft.azure.sdk.iot.service.Device)1 Module (com.microsoft.azure.sdk.iot.service.Module)1