use of com.azure.core.credential.AzureSasCredential in project azure-iot-sdk-java by Azure.
the class AzureSasCredentialSample method main.
public static void main(String[] args) {
SamplesArguments parsedArguments = new SamplesArguments(args);
String sharedAccessSignature = parsedArguments.getSharedAccessSignature();
// Shared access signatures can be generated by the SDK for you by using the service client constructors
// that take in your IoT Hub's connection string. This sample will demonstrate how to construct service clients
// without giving them the connection string by giving them shared access signatures instead.
// This sample's readme includes a helper function that shows how to build shared access signatures below.
//
// More details on how to build this shared access signature can be found here:
// https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-security#security-token-structure
AzureSasCredential credential = new AzureSasCredential(sharedAccessSignature);
// "my-azure-iot-hub.azure-devices.net" for example
String iotHubHostName = parsedArguments.getIotHubHostName();
String newDeviceId = runRegistryManagerSample(iotHubHostName, credential);
runTwinClientSample(iotHubHostName, credential, newDeviceId);
runServiceClientSample(iotHubHostName, credential, newDeviceId);
// The AzureSasCredential object supports updating the shared access signature which is important to do
// once the previous signature has expired, or is close to expiring. This sample assumes that no renewal will
// be necessary since the sample completes in a few seconds. After updating the credential object, any
// clients that were constructed with that credential will start using the updated signature
// String updatedSignature = "some new shared access signature";
// credential.update(updatedSignature);
runJobClientSample(iotHubHostName, credential);
runDeviceMethodClientSample(iotHubHostName, credential, newDeviceId);
}
use of com.azure.core.credential.AzureSasCredential in project azure-iot-sdk-java by Azure.
the class RegistryManagerTests method buildRegistryManagerWithAzureSasCredential.
private static RegistryManager buildRegistryManagerWithAzureSasCredential() {
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
RegistryManagerOptions options = RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build();
return new RegistryManager(iotHubConnectionStringObj.getHostName(), azureSasCredential, options);
}
use of com.azure.core.credential.AzureSasCredential in project azure-iot-sdk-java by Azure.
the class ServiceClientTests method buildServiceClientWithAzureSasCredential.
private static ServiceClient buildServiceClientWithAzureSasCredential(IotHubServiceClientProtocol protocol, ServiceClientOptions options) {
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
return new ServiceClient(iotHubConnectionStringObj.getHostName(), azureSasCredential, protocol, options);
}
use of com.azure.core.credential.AzureSasCredential in project azure-iot-sdk-java by Azure.
the class ServiceClientTests method feedbackMessageReceiverWithAzureSasCredential.
@Test
@StandardTierHubOnlyTest
public void feedbackMessageReceiverWithAzureSasCredential() throws Exception {
RegistryManager registryManager = RegistryManager.createFromConnectionString(iotHubConnectionString, RegistryManagerOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build());
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential sasTokenProvider = new AzureSasCredential(serviceSasToken.toString());
ServiceClient serviceClient = new ServiceClient(iotHubConnectionStringObj.getHostName(), sasTokenProvider, testInstance.protocol);
FeedbackReceiver feedbackReceiver = serviceClient.getFeedbackReceiver();
feedbackReceiver.open();
// received feedback message can be ignored since we no longer have any tests that need to consume them
// All this test cares about is that this API doesn't result in an unauthorized exception
feedbackReceiver.receive(2 * 1000);
feedbackReceiver.close();
serviceClient.close();
registryManager.close();
}
use of com.azure.core.credential.AzureSasCredential in project azure-iot-sdk-java by Azure.
the class DeviceMethodCommon method buildDeviceMethodClientWithAzureSasCredential.
protected static DeviceMethod buildDeviceMethodClientWithAzureSasCredential() {
IotHubConnectionString iotHubConnectionStringObj = IotHubConnectionStringBuilder.createIotHubConnectionString(iotHubConnectionString);
IotHubServiceSasToken serviceSasToken = new IotHubServiceSasToken(iotHubConnectionStringObj);
AzureSasCredential azureSasCredential = new AzureSasCredential(serviceSasToken.toString());
DeviceMethodClientOptions options = DeviceMethodClientOptions.builder().httpReadTimeout(HTTP_READ_TIMEOUT).build();
return new DeviceMethod(iotHubConnectionStringObj.getHostName(), azureSasCredential, options);
}
Aggregations