0

Net SQL AzMan の設定はすべて「OR」ベースのようです。

例えば:

操作に 3 つの (許可された) アプリケーション グループを追加する場合、操作の権限を持つユーザーは、最初または 2 番目または 3 番目にいる必要があります。

ユーザーが (最初と 2 番目) または (最初と 3 番目) にいる必要があると言う方法を探しています。

それを行う方法はありますか?

理由:
部門から部門へと移動するにつれて権限が雪だるま式に変化するユーザーがいます。Active Directory 部門ごとに 1 つの役割を設定したいと考えています (上記の例では「最初の」)。上記のロジックを機能させることができれば、ユーザーが部門を変更すると、以前の部門のアクセス許可が失われます (上司が怠け者で、AzMan が更新されていない場合でも)。

AzMan でこれを機能させることができない場合は、自分のアプリで機能させることができます。しかし、AzMan レベルでははるかに簡単です。

4

1 に答える 1

2

これは、操作のBizRuleを使用して行うことができます。そのためのコードは少しやり過ぎですが、これは最小限の変更で機能するはずです。

using System;
using System.Security.Principal;
using System.IO;
using System.Data;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Text;
using NetSqlAzMan;
using NetSqlAzMan.Interfaces;

using System.Security.Principal;
using System.Reflection;

namespace APPLICATION.BizRules
{
    public sealed class BizRule : IAzManBizRule
    {
        public BizRule()
        { }

        public bool Execute(Hashtable contextParameters, IAzManSid identity, IAzManItem ownerItem, ref AuthorizationType authorizationType)
        {
            string sqlConnectionString = "data source=DATABASE_FQN;initial catalog=DATABASE;Integrated Security=false;User Id=USER_NAME;Password=PASSWORD";

            IAzManStorage storage = new SqlAzManStorage(sqlConnectionString);

            try
            {
                bool authorized = false;
                if (identity.StringValue.StartsWith("S"))
                {
                    //this is a little over kill but there is no way to reference standard .net libraries in NetSqlAzMan
                    Assembly asm = Assembly.Load(@"System.DirectoryServices.AccountManagement, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089");

                    System.Type userPrincipalType = asm.GetType("System.DirectoryServices.AccountManagement.UserPrincipal");
                    System.Type principalContextType = asm.GetType("System.DirectoryServices.AccountManagement.PrincipalContext");
                    System.Type contextTypeType = asm.GetType("System.DirectoryServices.AccountManagement.ContextType");
                    System.Type identityTypeType = asm.GetType("System.DirectoryServices.AccountManagement.IdentityType");

                    Object principalContext = Activator.CreateInstance(principalContextType, new object[] { Enum.ToObject(contextTypeType, 1), "DENALLIX" });

                    MethodInfo methodInfo = userPrincipalType.GetMethod("FindByIdentity", new Type[] { principalContextType, identityTypeType, typeof(string) });

                    Object userPrincipal = methodInfo.Invoke(null, new object[] { principalContext, Enum.ToObject(identityTypeType, 4), identity.StringValue });
                    string userPrincipalName = userPrincipal.GetType().GetProperty("UserPrincipalName").GetValue(userPrincipal, null).ToString();

                    WindowsIdentity user = new WindowsIdentity(userPrincipalName);

                    authorized = (checkRoleAuthorization(storage, "GROUP1", user) && checkRoleAuthorization(storage, "GROUP2", user)) || checkRoleAuthorization(storage, "GROUP3", user);
                }
                else
                {
                    AzManUser user = new AzManUser(identity);
                    authorized = (checkRoleAuthorization(storage, "GROUP1", user) && checkRoleAuthorization(storage, "GROUP2", user)) || checkRoleAuthorization(storage, "GROUP3", user);
                }


                return authorized;
            }
            catch (SqlAzManException ex)
            {
                return false;
            }
        }

        private bool checkRoleAuthorization(IAzManStorage storage, string roleName, object user)
        {
            AuthorizationType auth = AuthorizationType.Deny;            
            if (user is WindowsIdentity)
            {
                auth = storage.CheckAccess("MY STORE", "MY APPLICATION", roleName, (WindowsIdentity)user, DateTime.Now, true);                
            }
            else
            {
                auth = storage.CheckAccess("MY STORE", "MY APPLICATION", roleName, (IAzManDBUser)user, DateTime.Now, true);                
            }
            return auth == AuthorizationType.Allow || auth == AuthorizationType.AllowWithDelegation;
        }

    }
    public partial class AzManUser : IAzManDBUser
    {
        private Dictionary<string, object> _customColumns = new Dictionary<string, object>();

        private IAzManSid _sid;
        private string _username;

        public AzManUser(string username, string sid)
        {
            _username = username;
            _sid = new NetSqlAzMan.SqlAzManSID(sid);
        }

        public AzManUser(string sid)
        {
            _username = string.Empty;
            _sid = new NetSqlAzMan.SqlAzManSID(sid);
        }

        public AzManUser(IAzManSid sid)
        {
            _username = string.Empty;
            _sid = sid;
        }

        public Dictionary<string, object> CustomColumns
        {
            get { return _customColumns; }
        }

        public IAzManSid CustomSid
        {
            get
            {
                return _sid;
            }
        }

        public string UserName
        {
            get { return _username; }
        }
    }
}
于 2012-08-06T15:45:31.803 に答える