1

Azure Pack の STS からセキュリティ トークンを取得できるコードを Java で記述しようとしています。これを使用して、Azure Pack API への呼び出しを認証できます。C# でこのトークンを取得するためにMicrosoft が提供する (動作する) コードの例を次に示します。

        string windowsAuthSiteEndPoint = EnvironmentToUse + ":30072";
        var identityProviderEndpoint = new EndpointAddress(new Uri(windowsAuthSiteEndPoint + "/wstrust/issue/windowstransport"));
        var identityProviderBinding = new WS2007HttpBinding(SecurityMode.Transport);
        identityProviderBinding.Security.Message.EstablishSecurityContext = false;
        identityProviderBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;
        identityProviderBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

        var trustChannelFactory = new WSTrustChannelFactory(identityProviderBinding, identityProviderEndpoint)
        {
            TrustVersion = TrustVersion.WSTrust13,
        };

        var channel = trustChannelFactory.CreateChannel();
        var rst = new RequestSecurityToken(RequestTypes.Issue)
        {
            AppliesTo = new EndpointReference("http://azureservices/AdminSite"),
            KeyType = KeyTypes.Bearer,
        };

        RequestSecurityTokenResponse rstr = null;
        SecurityToken token = null;
        token = channel.Issue(rst, out rstr);

これが私が現在Javaで持っているもので、同じことをしようとしています:

    import org.apache.cxf.Bus;
    import org.apache.cxf.bus.spring.SpringBusFactory;
    import org.apache.cxf.sts.STSConstants;
    import org.apache.cxf.ws.security.SecurityConstants;
    import org.apache.cxf.ws.security.tokenstore.SecurityToken;
    import org.apache.cxf.ws.security.trust.STSClient;

    SpringBusFactory springBusFactory = new SpringBusFactory();
    Bus bus = springBusFactory.createBus();

    STSClient stsClient = new STSClient(bus);
    stsClient.setLocation("https://" + endpoint + ":30072/wstrust/issue/windowstransport");
    stsClient.setServiceName("{http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice}SecurityTokenService");
    stsClient.setEndpointName("{http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice}WS2007HttpBinding_IWSTrust13Sync");
    stsClient.setKeyType(STSConstants.BEARER_KEY_KEYTYPE);
    stsClient.isEnableAppliesTo();

    bus.setProperty(SecurityConstants.STS_CLIENT, stsClient);
    bus.setProperty(SecurityConstants.STS_APPLIES_TO, "http://azureservices/AdminSite");

    SecurityToken securityToken = stsClient.requestSecurityToken();

Java テスト コードを実行すると、401 Unauthorized HTTP 応答が返されます。

    Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '401: Unauthorized' when communicating with https://endpoint:30072/wstrust/issue/windowstransport

C# コードが行うことを再作成しようとすると、次の機能が欠落しているように見えますが、次のコードに相当するものが Java で/Apache CXF ライブラリを使用して何があるかわかりません。

1) identityProviderBinding.Security.Message.EstablishSecurityContext = false;

2) identityProviderBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;

3) identityProviderBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

また、他のことも間違っている可能性があります。何か考えや提案はありますか?

4

1 に答える 1

0

セキュリティ トークンの代わりに、管理証明書を使用してリクエストを認証しようとしましたか。https://msdn.microsoft.com/en-us/library/azure/ee460782.aspx#bk_certには、Azure でそれを行う方法に関する情報がありますが、Azure パックでもそれほど変わらないはずです。

于 2015-10-23T14:44:45.260 に答える