0

答えは Page Not Found だったので、次のコードでパブリック IP のサイズを取得しようとしました。

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
        );

NetworkResourceProviderClient  networkResourceProviderClient = NetworkResourceProviderService.create(config);
           PublicIpAddressListResponse PublicIpAddressListResponse =networkResourceProviderClient.getPublicIpAddressesOperations().listAll();
           ArrayList<PublicIpAddress> PublicIpAddressList =PublicIpAddressListResponse.getPublicIpAddresses();
           System.out.println(PublicIpAddressList.size());

Azure AD ServicePrincipal 認証を使用すると、-0 が返されます

" https://management.azure.com/ " API で証明書認証を使用すると、 AuthenticationFailed: が返されます。

Exception in thread "main" com.microsoft.windowsazure.exception.ServiceException: AuthenticationFailed: Authentication failed. The 'Authorization' header is not present or provided in an invalid format.
    at com.microsoft.windowsazure.exception.ServiceException.createFromJson(ServiceException.java:290)
    at com.microsoft.azure.management.network.PublicIpAddressOperationsImpl.listAll(PublicIpAddressOperationsImpl.java:1443)
    at com.microsoft.azure.auth.Program.main(Program.java:50)

すべての仮想マシンのパブリック IP アドレスを取得する方法はありますか? または、IP値を取得するために認証する方法は?

4

1 に答える 1

1

この問題は、正しくない認証を使用したことが原因でした。

以下の認証コードは、Azure Service Management に対してのみ機能します。

Configuration config = ManagementConfiguration.configure(
          new URI("https://management.core.windows.net), 
          subscriptionId,
          keyStoreLocation, // the file path to the JKS
          keyStorePassword, // the password for the JKS
          KeyStoreType.jks // flags that I'm using a JKS keystore
        );

Azure Resource Management の認証について、ドキュメント「Authenticating Azure Resource Management request」( https://msdn.microsoft.com/en-us/library/azure/dn790557.aspx ) には、「次を使用してリソースに対して実行するすべてのタスクAzure Resource Manager は、Azure Active Directory で認証される必要があります。".

したがって、次のように、subscription-id、tenant-id、client-id、および client-secret を使用して認証構成コードを変更する必要があります。

private static AuthenticationResult getAccessTokenFromServicePrincipalCredentials() throws
            ServiceUnavailableException, MalformedURLException, ExecutionException, InterruptedException {
        AuthenticationContext context;
        AuthenticationResult result = null;
        ExecutorService service = null;
        try {
            service = Executors.newFixedThreadPool(1);
            // TODO: add your tenant id
            context = new AuthenticationContext("https://login.windows.net/" + "<your tenant id>",
                    false, service);
            // TODO: add your client id and client secret
            ClientCredential cred = new ClientCredential("<your client id>",
                    "<your client secret>");
            Future<AuthenticationResult> future = context.acquireToken(
                    "https://management.azure.com/", cred, null);
            result = future.get();
        } finally {
            service.shutdown();
        }

        if (result == null) {
            throw new ServiceUnavailableException(
                    "authentication result was null");
        }
        return result;
    }


Configuration config = ManagementConfiguration.configure(
          null,
          new URI("https://management.core.windows.net), 
          "<your-subscription-id>",
          getAccessTokenFromServicePrincipalCredentials()
.getAccessToken()
        );

Java の ServicePrincipal に関する完全な認証コードについては、 https://github.com/Azure/azure-sdk-for-java/blob/master/azure-mgmt-samples/src/main/java/com/microsoft/を参照してください。 azure/samples/authentication/ServicePrincipalExample.java .

スレッド ( azure Java SDK を使用した Windows azure のサブスクリプションのネットワークのリストの取得) の回答の URL については、https://github.com/Azure/azure-sdk-for-java/blob/master/service-management/に移動します。 azure-svc-mgmt-network/src/main/java/com/microsoft/windowsazure/management/network/NetworkOperations.java .

于 2015-10-19T08:15:35.130 に答える