尝试了基本的位置检索器代码(如下所示)
String uri = "https://management.core.windows.net/";
String subscriptionId = "XXXXXXXX-5fad-XXXXXX-9dfa-XXXXXX";
String keyStoreLocation = "D:\\test.jks";
String keyStorePassword = "123456";
Configuration config = ManagementConfiguration.configure(
new URI(uri),
subscriptionId,
keyStoreLocation, // the file path to the JKS
keyStorePassword, // the password for the JKS
KeyStoreType.jks // flags that I'm using a JKS keystore
);
ManagementClient client = ManagementService.create(config);
// get the list of regions
LocationsListResponse response = client.getLocationsOperations().list();
ArrayList<Location> locations = response.getLocations();
// write them out
for( int i=0; i<locations.size(); i++){
System.out.println(locations.get(i).getDisplayName());
}
它工作正常。但是当我尝试创建 ComputeManagementClient 并尝试重新启动 VM
ComputeManagementClient computeManagementClient = ComputeManagementService.create(config);
VirtualMachineOperations virtualMachinesOperations= computeManagementClient.getVirtualMachinesOperations();
virtualMachinesOperations.restart("SQLVM", "sqlvm.cloudapp.net");
我收到证书错误。
Exception in thread "main" java.util.concurrent.ExecutionException: com.microsoft.windowsazure.exception.ServiceException: ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at com.microsoft.azure.management.compute.VirtualMachineOperationsImpl.restart(VirtualMachineOperationsImpl.java:9973)
at com.microsoft.azure.compute.RestartVMExample.main(RestartVMExample.java:84)
PS:我从 Java Keystore 创建了一个 .cer 并毫无问题地上传到 Azure。
任何线索发生了什么?