我需要一些關于如何最好地在 ASP.net 核心應用程式中實作安全機制的建議。應用程式用戶使用 AD 身份驗證進行身份驗證。這種型別的實施是否有最佳實踐?
我有一份專案記錄清單。用戶應該只能檢索他們有權訪問的專案串列。我有三種具有不同訪問級別的用戶型別,如下所述。
- 審批人 - 分配給各個專案。
- 州審批人——可以查看全州范圍的專案。
- 全域審批者 - 可以訪問所有專案。
有沒有人對實作什么模型和邏輯有什么建議?
uj5u.com熱心網友回復:
好吧,我使用“有限”資訊來保護已登錄用戶的頁面。因此,如果他們具有特定角色的成員資格,那么只有那些用戶可以跳轉/查看此類頁面。
但是,在您的情況下,并且經常?
好吧,與其說是用戶可以使用或被限制的網頁。
但是,如果可以基于 IIS 安全性而不是您的代碼來限制網頁,則應使用該選項。
但是,例如,通常在代碼中,我們有來自給定公司的個人用戶,并且只有一些可以并且被允許查看所有專案。(所以有些人只能看到自己的專案,但從那家公司,有些人有權查看 使用所有專案。
所以,我們經常有這樣的代碼:
Dim cmdSQL As New SqlCommand("dbo.GetProjects", GetCon)
cmdSQL.CommandType = CommandType.StoredProcedure
cmdSQL.Parameters.Add("@LogonID", SqlDbType.Int).Value = Membership.GetUser.ProviderUserKey
cmdSQL.Parameters.Add("Email", SqlDbType.NVarChar).Value = Membership.GetUser.Email
cmdSQL.Parameters.Add("@PortalMaster", SqlDbType.Bit).Value = IIf(Roles.IsUserInRole("PortalMaster"), 1, 0)
因此,如果用戶是 PortalMaster,那么他們可以獲取并查看屬于該公司的所有專案。(每個登錄網站的公司可以有 1 或 20 名員工屬于給定公司)。
因此,在上面,查詢將通過 EmployeeID(他們的登錄)提取專案,因此他們只能看到自己的專案。
如果您是 PortalMaster 組的成員,那么我們會根據 ComapnyID 拉取專案。
那么,雖然您可能沒有像上面那樣使用較舊的安全提供商?您將專案拉到簡單的查詢必須限制基于上述回傳的行。
一旦這些專案被回傳(在一個漂亮的網格中 - 包括搜索選項),他們就可以選擇(點擊)一個專案。下一頁不再關心了,因為在您選擇專案之前,您無法進入專案詳細資訊頁面。
因此,很明顯,對于創建它的給定專案,您必須擁有它。因此,您顯示他們當前專案的能力將受到他們的登錄 ID 或您現在使用的任何限制。
但是,對于州級用戶?然后,您的標準是他們的登錄 ID 和他們基于該登錄所屬的狀態。
然后是“管理員”角色或組——他們可以搜索和拉取所有專案。
因此,雖然我們確實通過“角色”安全性(基于 IIS)來限制網頁,但這只是意味著所有用戶都可以或不能根據他們的角色訪問某些網頁(并且這種安全性不需要我的代碼- 分配給這些網頁的 IIS 安全性可以為您完成所有這些骯臟的作業。
However, if you are a legal logon, then you can only ever work on projects that belong to your company. But then it is a question if that user also has the role of "PortalMaster", and if they do, then we pull all projects for display to select from for that given user.
And of course we never use say URL "query parameters", and such internal database company ID, or ContactID (user id) are never exposed, nor possible allow display of information or data that don't belong to the given user.
So, you need to build some sql or some store procedures, and having a few "parameters" for those stored procedures that returns rows of data based on their role membership is quite much how you would approach this. So in above, if the user is a portal master, then the stored procedure simple queries the data based on company they belong to as opposed to their contact id.
Now, this of course asseumes the database schema is setup, and for example, we hvae a company table, a employee table (that has their logon information), and then of course each project created has both a created by, and the company the project belongs to. So, that simple information is enough to provide the 2 levels of security.
We actually don't have a "super user" that can look at and see all projects in the system, but it actually not all that bad of a idea, since for testing, or checking a project that has some problem is a "pain" right now, since we in theory have to create a logon for that company, or get a password.
So, all logons we create belong to a given company. And thus when a user creates a new project, it can only be created under that one company, and of course a project also requires the user that created the project.
So, you simple have to restrict records returned in the page in which they can select a project to work on. IIS security, or in fact SQL server security as a general rule can't do this type of security for you - you the developer have to.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/435127.html
上一篇:C/C 通過套接字下載/上傳檔案
