短いバージョン: Windows ストア アプリによって作成された Web 要求を偽装すると、正しいユーザー名で WindowsIdentity オブジェクトを取得するのに、その IsAuthenticated プロパティが False を返すのはなぜですか? ブラウザー (Metro IE10 を含む) から同じ要求を行うと、IsAuthenticated==true が返されます。
長いバージョン:
WCF サービスと WinJS アプリケーションで構成される内部エンタープライズ ソリューションのプロトタイプを作成しています。WCF サービスは、webHttpBinding (つまり、単純な GET/POST 要求) に基づいています。
特定のアクションは、リクエストを行うユーザーに代わって処理する必要があるため、サービスは呼び出し元を偽装するように構成されています。設定例は次のとおりです。
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="CustomizedWebBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="Web">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="CustomizedWebBinding" contract="IWcfService" behaviorConfiguration="Web">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8787/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
...そしてコード:
public class WcfService : IWcfService
{
[OperationBehavior(Impersonation=ImpersonationOption.Required)]
public UserInfo GetUserInfo()
{
UserInfo ui = new UserInfo();
WindowsIdentity identity = ServiceSecurityContext.Current.WindowsIdentity;
ui.UserName = identity.Name;
ui.IsAuthenticated = identity.IsAuthenticated;
ui.ImpersonationLevel = identity.ImpersonationLevel.ToString();
ui.IsAnonymous = identity.IsAnonymous;
ui.IsGuest = identity.IsGuest;
ui.IsSystem = identity.IsSystem;
ui.AuthenticationType = identity.AuthenticationType;
return ui;
}
}
したがって、この操作は呼び出し元に関する情報を収集し、json 文字列で送り返すだけです。
クライアントに移動します。自動認証を有効にするために、Windows ストア アプリのマニフェスト ファイルで「エンタープライズ認証」、「インターネット (クライアント)」、および「プライベート ネットワーク」をチェックしました。
Windows ストア アプリ内から、WinJS.xhr 関数を使用して要求を送信します。
var options = {
url: "http://localhost:8787/getuserinfo"
};
WinJS.xhr(options).then(function (xhrResponse) {
var userInfoBlock = document.getElementById("userInfoBlock");
var data = JSON.parse(xhrResponse.response);
userInfoBlock.innerHTML += "<ul>"
for (var p in data) {
if (data.hasOwnProperty(p)) {
userInfoBlock.innerHTML += "<li>" + p + ": " + data[p] + "</li>";
}
}
userInfoBlock.innerHTML += "</ul>";
});
ここで、Windows ストア アプリを実行して要求を送信すると、次のような応答が返されます。
AuthenticationType: "NTLM"
ImpersonationLevel: "Impersonation"
IsAnonymous: false
IsAuthenticated: false
IsGuest: false
IsSystem: false
UserName: "TESTBOX\dev"
ブラウザのアドレスバーを使用してリクエストを送信すると、同じ応答が返されますが、「IsAuthenticated: true」という唯一の違いがあります。
また、「エンタープライズ認証」を無効にすると、資格情報ピッカーがポップアップし、正しい資格情報を提供した後に「IsAuthenticated: true」が表示されることにも気付きました。
エンタープライズ認証機能に欠けているものや期待しすぎているものはありますか?