标签: windows-principal

如何检索用户所属的所有角色(组)?

有没有办法获取Windows身份验证用户所在的角色列表,而无需通过WindowsPrincipal.IsInRole方法明确检查?

.net rbac windows-principal windows-identity

24
推荐指数
3
解决办法
2万
查看次数

如何以DOMAIN\user格式的用户名创建WindowsIdentity/WindowsPrincipal

WindowsIdentity(string)构造函数需要的用户名是在username@domain.com格式.但在我的情况下,我以旧DOMAIN\user格式从数据库中获取用户名(然后必须检查其Windows角色成员身份).

WindowsPrincipal从旧式用户名创建的最佳方法是什么?

c# windows-principal windows-identity

17
推荐指数
2
解决办法
3万
查看次数

从WindowsIdentity和Thread.CurrentPrincipal检索WindowsPrincipal有什么区别?

我试图弄清楚为什么基于属性的安全性不能像我在WCF中所期望的那样工作,我怀疑它可能与以下内容有关:

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

var identity = new WindowsIdentity("ksarfo");
var principal = new WindowsPrincipal(identity);
Console.WriteLine("\nChecking whether current user [" + identity.Name + "] is member of [" + groupName + "]");
Console.WriteLine(principal.IsInRole(groupName)); // returns true

principal = (WindowsPrincipal)Thread.CurrentPrincipal;
identity = (WindowsIdentity) principal.Identity;
Console.WriteLine("\nChecking whether current user [" + identity.Name + "] is member of [" + groupName + "]");
Console.WriteLine(principal.IsInRole(groupName)); // returns false
Run Code Online (Sandbox Code Playgroud)

我不明白为什么函数调用的结果不同:

principal.IsInRole(groupName)
Run Code Online (Sandbox Code Playgroud)

为了完整起见,代码实际失败的点在这里:

PrincipalPermission(SecurityAction.Demand, Role = "PortfolioManager")]
Run Code Online (Sandbox Code Playgroud)

帮助赞赏.

c# security active-directory windows-principal wcf-security

15
推荐指数
1
解决办法
1万
查看次数

MVC3 Windows身份验证覆盖User.Identity

我正在使用带有MSSQL后端的MVC3 构建Intranet应用程序.我有身份验证和角色(通过自定义角色提供程序)正常工作.我现在要做的是重写User.Identity以允许像User.Identity.FirstName这样的项目.但我找不到任何代码可以告诉我在WindowsIdentity中如何做到这一点

我试过写一个自定义提供程序:

public class CPrincipal : WindowsPrincipal
{
    UserDAL userDAL = new UserDAL();
    public CPrincipal(WindowsIdentity identity)
        : base(identity)
    {
        userInfo = userDAL.GetUserProfile(identity.Name.Split('\\')[1]);
        this.identity = identity;
    }
    public UserInfo userInfo { get; private set; }
    public WindowsIdentity identity { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)

并覆盖WindowsAuthentication以填充自定义主体.

    void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs e)
    {
        if (e.Identity != null && e.Identity.IsAuthenticated)
        {
            CPrincipal cPrincipal = new CPrincipal(e.Identity);
            HttpContext.Current.User = cPrincipal;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我在身份验证功能中有一个断点,并且正在填充主体; 但是,当我在控制器中放置一个断点时,User只是它的正常RolePrincipal,而不是我的自定义主体.我究竟做错了什么?

编辑:

我在global.asax中注释掉了上面的代码.我使用C#覆盖了AuthorizeAttribute:

public class CAuthorize : AuthorizeAttribute
{ …
Run Code Online (Sandbox Code Playgroud)

intranet windows-authentication windows-principal windows-identity asp.net-mvc-3

11
推荐指数
1
解决办法
1万
查看次数

如何确保IsInRole检查未使用缓存凭据

我有一个连接到WCF服务的WPF客户端,我想锁定一些功能,以便只有某些用户可以执行某些操作.WCF服务在执行服务方法时模拟客户端用户.操作系统是Windows XP.

我正在阅读这个问题,作为调查我的应用程序中将用户角色应用于功能的最佳方法的一部分(我想将用户分配给AD安全组,然后检查IsInRole),并且担心缓存权限将允许用户他们的权限已经减少,以访问他们不再拥有权限的功能.相反,我也担心升级了权限的用户需要注销他们的Windows帐户,甚至可能必须重新启动WCF服务(最糟糕的情况)才能访问新功能.

确保客户端和服务器都能立即看到AD安全组更改的最简单方法是什么?

c# wcf active-directory windows-principal wcf-security

6
推荐指数
1
解决办法
1020
查看次数

IsInRole获得新的安全令牌

我正在使用WindowsPrincipal的IsInRole方法来检查WPF和Winforms应用程序中的组成员身份.我正在生成一个身份令牌,可以用于任何AD用户(不一定是实际登录到计算机的用户 - 取决于我正在做什么我不一定要进行身份验证,我只使用基本的信息级令牌(我认为它的正确名称是"身份令牌").

第一次在特定计算机上运行此代码时,操作系统会为指定的用户生成标识令牌.然后,IsInRole函数使用该标记来验证组成员身份.它很快,所以我非常喜欢它.但是,后续调用创建WindowsIdentity/WindowsPrincipal会引用现有令牌而不是创建新令牌.我知道如何更新令牌的唯一方法是退出计算机或重新启动(清除令牌缓存).有谁知道重置缓存身份令牌的更好方法?

示例代码C#:

Using System.Security.Principal;
WindowsIdentity impersonationLevelIdentity = new WindowsIdentity("Some_UserID_That_Isn't_Me", null);
WindowsPrincipal identityWindowsPrincipal = new WindowsPrincipal(impersonationLevelIdentity);
If (identityWindowsPrincipal.IsInRole("AN_AD_GROUP")) { ...
Run Code Online (Sandbox Code Playgroud)

VB:

Imports System.Security.Principal
Dim impersonationLevelIdentity = New WindowsIdentity("Some_UserID_That_Isn't_Me", Nothing)
Dim identityWindowsPrincipal = New WindowsPrincipal(impersonationLevelIdentity)
if identityWindowsPrincipal.IsInRole("AN_AD_GROUP") then...
Run Code Online (Sandbox Code Playgroud)

c# vb.net windows-principal isinrole windows-identity

6
推荐指数
1
解决办法
330
查看次数

WindowsPrincipal.IsInRole和通用与全局活动目录组

有人知道如何WindowsPrincipal.IsInRole("domain\role")使用活动目录通用组吗?

假设当前用户是名为Domain的域中名为Role的组的成员,并且Role组是Active Directory中的Global组.然后,以下代码将产生result = true:

WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
bool result = wp.IsInRole(@"domain\Role");
Run Code Online (Sandbox Code Playgroud)

但是,如果将Role组更改为通用组,则代码将生成result = false.

c# active-directory windows-principal isinrole

5
推荐指数
1
解决办法
9765
查看次数

为什么WindowsPrincipal.IsInRole总是为"管理员"组返回false?

我的本地用户帐户位于Administrators组中,我想简单地弄清楚Windows窗体项目将如何确定我是否在管理员组中.所以,我启动了一个Windows窗体项目,并尝试了以下内容:

[STAThread]
static void Main()
{
    string adminGroup1 = @"BUILTIN\Administrators";
    string adminGroup2 = Environment.MachineName + @"\Administrators";
    string adminGroup3 = Environment.MachineName.ToLower() + @"\Administrators";
    string adminGroup4 = "Administrators";
    string adminGroup5 = "administrators";

    AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
    WindowsPrincipal currentUser1 = (WindowsPrincipal)Thread.CurrentPrincipal;
    bool IsAdmin1_1 = currentUser1.IsInRole(adminGroup1); // false
    bool IsAdmin1_2 = currentUser1.IsInRole(adminGroup2); // false
    bool IsAdmin1_3 = currentUser1.IsInRole(adminGroup3); // false
    bool IsAdmin1_4 = currentUser1.IsInRole(adminGroup4); // false
    bool IsAdmin1_5 = currentUser1.IsInRole(adminGroup5); // false

    WindowsPrincipal currentUser2 = new WindowsPrincipal(WindowsIdentity.GetCurrent());
    bool IsAdmin2_1 = currentUser2.IsInRole(adminGroup1); // false
    bool IsAdmin2_2 = currentUser2.IsInRole(adminGroup2); …
Run Code Online (Sandbox Code Playgroud)

c# windows-principal winforms

4
推荐指数
1
解决办法
6283
查看次数

为什么Vista报告我的Windows帐户不在管理员角色中?

在Windows Vista下,当我检查当前用户帐户是否处于管理员角色时,我收到了否定信息,如下图所示.

谁能告诉我为什么我不在管理员角色?当我检查我是否处于"调试器用户"角色时,我得到"真实"

谢谢.

不在管理员角色中

.net powershell windows-principal user-accounts windows-vista

1
推荐指数
1
解决办法
158
查看次数