首页 文章

双重身份验证的应用程序:自定义和Active Directory

提问于
浏览
2

我有一个C#应用程序,它将使用企业Active Directory对一半用户进行身份验证,并为另一半使用自定义身份验证方法 .

我已经设法使用DirectoryEntry,DirectorySearcher等对AD中的用户进行身份验证,并且还可以使用我的自定义身份验证 .

但是,我想知道用户是否已使用公司域登录到他的计算机,然后该用户将不会显示任何登录表单并且必须传递给应用程序 .

我知道我可以使用 WindowsIdentity.GetCurrent().IsAuthenticated ,但是对于本地登录的用户和Domain登录的用户,它返回"true" .

我想知道如何区分第一个和最新的一个 .

(注意:这是一个桌面应用程序)

1 回答

  • 1

    我还维护一个winforms桌面应用程序,它为办公室用户使用活动目录,并支持非办公用户 .

    这可能比你的要求更多,但是因为我有与你相同的场景,无论如何我会提供它,因为它以一种很好的方式聚集在一起,我真的没有写太多的代码而且一直在运作良好 .

    我相信其他人可能会用一个包来做这件事,而不是滚动他们自己 - 而且说实话,我可能会在下次有这个要求时走这条路......

    这里是:

    从概念上讲,我从ASP.NET中获取了一个提示并将安全性分解为两个逻辑部分:

    Authentication - 这位用户是谁?

    Authorization - 用户可以这样做吗?

    我的实现使用一个简单的数据库

    enter image description here

    这是我应用程序主要形式的一个片段:

    public EOMForm()
        {
            InitializeComponent();
    
            // Show the connection string when hovering over the database label (Test Mode Only)
            if(Properties.Settings.Default.TestMode)
                this.toolTip1.SetToolTip(this.databaseLabel, EomAppCommon.EomAppSettings.ConnStr);
    
            // Security
            DisableMenus();
        }
    
        private void DisableMenus()
        {
            // Disable individual menu items
            foreach (var menuItem in this.TaggedToolStripMenuItems())
                menuItem.Enabled = Security.User.Current.CanDoMenuItem((string)menuItem.Tag);
    
            // Apply disabled color to top level menus that have all their items disabled
            foreach (var menu in menuStrip1.DisabledMenus())
                menu.ForeColor = SystemColors.GrayText;
        }
    

    here's the supporting utility code .

    最后,我使用ASP.NET scaffold站点管理它:

    enter image description here

相关问题