我一整天都在为这个问题苦苦挣扎。
我正在使用 JavaScript 和 HTML5 开发 Windows 8 应用程序。我需要根据分配用户帐户的事件目录组来限制应用程序上的某些功能。
问题是:如何检查用户帐户是否属于 Active Directory 组?
我尝试过使用 Windows.System.UserProfile.UserInformation 和 Windows.Security.Credentials.UI.CredentialPicker,但它们都没有返回测试用户帐户是否属于某个组或用户所在组的方法帐户已分配。
预先感谢您的帮助。
最佳答案
我找到了一种解决方案来执行此操作,这就是我实现的解决方案,并且它有效。您可以创建一个 Web 服务,根据 Active Directory 验证凭据,您可以在其中传递域、用户名和密码,然后使用 WinJS.xhr 从应用程序中调用它。要请求凭据,您可以使用 CredentialPicker 控件,该控件返回用户输入的域、用户名和密码。
这是代码:
网络服务代码:
ValidateUserResult vur = new ValidateUserResult();
try
{
using (PrincipalContext context =
new PrincipalContext(ContextType.Domain, domain))
{
vur.UserCredentialsAreValid = context
.ValidateCredentials(username, password);
if (vur.UserCredentialsAreValid)
{
vur.ProcessMessageText = "Ok";
vur.ProcessMessageCode = 0;
}
else
{
vur.ProcessMessageText =
"Credenciales invalidas";
vur.ProcessMessageCode = -1;
}
}
}
catch (Exception ex)
{
vur.UserCredentialsAreValid = false;
vur.ProcessMessageText = ex.Message;
vur.ProcessMessageCode = ex.HResult;
}
return vur;
Windows 8 应用程序:
WinJS.xhr({
type: "get"
, url: {Web Service Url}
+ "/json/{Web Service Method Name}?domain="
+ domain + "&username=" + username
+ "&password=" + password
}).then(
function (result) {
if (result.status === 200) {
// Place code here.
}
},
function (error) {
// If an error occurs, manage here
});
关于javascript - 在 Windows 8 应用程序中获取用户帐户 Active Directory 组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15098338/