[英]Windows Authentication, Custom permissions, WCF, Active Directory
[英]Application with dual authentication: custom and Active Directory
我有一個C#應用程序,它將對一半的用戶使用企業Active Directory進行身份驗證,對另一半的用戶使用自定義身份驗證方法。
我已經設法使用DirectoryEntry,DirectorySearcher等對AD中的用戶進行身份驗證,並且還可以使用我的自定義身份驗證。
但是,我想知道某個用戶是否已經使用公司域登錄到他的計算機中,那么該用戶將不會顯示任何登錄表單,而必須傳遞給該應用程序。
我知道我可以使用WindowsIdentity.GetCurrent()。IsAuthenticated ,但是對於本地登錄的用戶和域登錄的用戶都返回“ true”。
我想知道如何區分第一個和最新的一個。
(注意:這是一個桌面應用程序)
我還維護了一個Winforms桌面應用程序,該應用程序在Office用戶中使用活動目錄,並且也支持非辦公室用戶。
這可能比您要的要多,但由於我的情況與您相同,因此無論如何我都會提供它,因為它以一種很好的方式組合在一起,我實際上並沒有編寫太多代碼,運作良好。
我敢肯定,其他人可能會使用一個軟件包來完成此任務,而不是自己滾動一個軟件包-老實說,下次我有此要求時,我可能會走這條路線...
這里是:
從概念上講,我從ASP.NET得到了提示,並將安全性分為兩個邏輯部分:
身份驗證 -該用戶是誰?
授權 -用戶可以這樣做嗎?
我的實現使用一個簡單的數據庫:
這是我應用程序主要形式的摘要:
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;
}
這是支持的實用程序代碼 。
最后,我通過一個ASP.NET支架站點對其進行管理:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.