private void SetHirearchy(IAzScope azScope, IAzApplication azApplication, string taskName, IAzManApplication application)
        {
            IAzTask azTask = null;

            if (azScope == null)
            {
                azTask = azApplication.OpenTask(taskName, null);
            }
            else
            {
                azTask = azScope.OpenTask(taskName, null);
            }

            if (azTask != null)
            {
                IAzManItem item = application.GetItem(taskName);
                //SubTasks
                object[] azSubTasks = azTask.Tasks as object[];
                if (azSubTasks != null)
                {
                    foreach (string azSubTask in azSubTasks)
                    {
                        IAzManItem subItem = application.GetItem(azSubTask);
                        var        members = item.GetMembers();
                        if (members == null || members.Where(t => t.ItemId == subItem.ItemId).Count() == 0)
                        {
                            item.AddMember(subItem);
                        }
                        this.SetHirearchy(azScope, azApplication, azSubTask, application);
                    }
                }
                //SubOperations
                object[] azSubOperations = azTask.Operations as object[];
                if (azSubOperations != null)
                {
                    foreach (string azSubOperation in azSubOperations)
                    {
                        IAzManItem subItem = application.GetItem(azSubOperation);
                        var        members = item.GetMembers();
                        if (members == null || members.Where(t => t.ItemId == subItem.ItemId).Count() == 0)
                        {
                            item.AddMember(subItem);
                        }
                    }
                }
            }
        }
示例#2
0
        private void SaveAssignedRoles()
        {
            var currents = AssignRoles;
            var lastest  = AssignedRoles.Select(o => o.Name).ToList();

            //Get New Items
            foreach (var o in lastest.Where(o => !currents.Contains(o)))
            {
                IAzTask.AddTask(o);
            }

            //Get Deleted Ones
            foreach (var o in currents.Where(o => !lastest.Contains(o)))
            {
                IAzTask.DeleteTask(o);
            }
        }
示例#3
0
        private object[] GetTaskOperations(AzManAuthorizationProviderData data, IAzApplication azApp, string[] tasks)
        {
            string[]         scopes     = new string[] { data.Scope };
            StringCollection operations = new StringCollection();

            foreach (String task in tasks)
            {
                IAzScope scope = null;
                if ((scopes != null) && (scopes[0].Length > 0))
                {
                    scope = azApp.OpenScope(scopes[0], null);
                }

                IAzTask azTask = null;
                if (scope != null)
                {
                    azTask = scope.OpenTask(task, null);
                }
                else
                {
                    azTask = azApp.OpenTask(task, null);
                }

                Array ops = azTask.Operations as Array;
                Debug.Assert(ops != null);
                foreach (String op in ops)
                {
                    operations.Add(op);
                }
            }

            if (operations.Count == 0)
            {
                throw new ConfigurationException(SR.NoOperations);
            }

            object[] operationIds = new object[operations.Count];
            for (int index = 0; index < operations.Count; index++)
            {
                operationIds[index] = azApp.OpenOperation(operations[index], null).OperationID;
            }

            return(operationIds);
        }
示例#4
0
        protected override void OnSaving()
        {
            if (IsNew)
            {
                IAzItem = Scope.CreateRole(Name, Description);
            }
            else
            {
                IAzTask.Name             = Name;
                IAzTask.Description      = Description;
                IAzTask.IsRoleDefinition = IsRoleDefinition ? 1 : 0;
            }

            //Save the Assignments.
            SaveAssignedOperations();
            SaveAssignedRoles();

            IAzTask.Submit();
        }
        private object[] GetTaskOperations(IAzApplication azApp, string[] tasks)
        {
            string[]         scopes     = new string[] { this.scopeName };
            StringCollection operations = new StringCollection();

            foreach (String task in tasks)
            {
                IAzScope scope = null;
                if ((scopes != null) && (scopes[0].Length > 0))
                {
                    scope = azApp.OpenScope(scopes[0], null);
                }

                IAzTask azTask = null;
                if (scope != null)
                {
                    azTask = scope.OpenTask(task, null);
                }
                else
                {
                    azTask = azApp.OpenTask(task, null);
                }

                Array ops = azTask.Operations as Array;
                foreach (String op in ops)
                {
                    operations.Add(op);
                }
            }

            if (operations.Count == 0)
            {
                throw new ConfigurationErrorsException(Properties.Resources.NoOperations);
            }

            object[] operationIds = new object[operations.Count];
            for (int index = 0; index < operations.Count; index++)
            {
                operationIds[index] = azApp.OpenOperation(operations[index], null).OperationID;
            }

            return(operationIds);
        }
示例#6
0
        private void SetHirearchy(IAzScope azScope, IAzApplication azApplication, string taskName, IAzManApplication application)
        {
            IAzTask azTask = null;

            if (azScope == null)
            {
                azTask = azApplication.OpenTask(taskName, null);
            }
            else
            {
                azTask = azScope.OpenTask(taskName, null);
            }

            IAzManItem item = application.GetItem(taskName);

            if (azTask != null)
            {
                //SubTasks
                object[] azSubTasks = azTask.Tasks as object[];
                if (azSubTasks != null)
                {
                    foreach (string azSubTask in azSubTasks)
                    {
                        IAzManItem subItem = application.GetItem(azSubTask);
                        item.AddMember(subItem);
                        //this.SetHirearchy(azScope, azApplication, azSubTask, application);
                    }
                }
                //SubOperations
                object[] azSubOperations = azTask.Operations as object[];
                if (azSubOperations != null)
                {
                    foreach (string azSubOperation in azSubOperations)
                    {
                        IAzManItem subItem = application.GetItem(azSubOperation);
                        item.AddMember(subItem);
                    }
                }
            }
        }
示例#7
0
        private void CreaStrutturaSuAzMan(string azManStorePath, int n)
        {
            this.Clessidra(true);
            this.StartTimer();
            WindowsIdentity       id       = WindowsIdentity.GetCurrent();
            NTAccount             userName = new NTAccount(id.Name);
            IAzAuthorizationStore store    = new AzAuthorizationStoreClass();

            store.Initialize(0, azManStorePath, null);
            object o = null;

            this.pb.Maximum = n - 1;
            for (int a = 0; a < n; a++)
            {
                IAzApplication app = store.CreateApplication("Application" + a.ToString(), null);
                app.Submit(0, null);
                this.pb.Value = a;
                Application.DoEvents();
                //IAzClientContext ctx = app.InitializeClientContextFromToken((UInt64)id.Token, null);
                for (int i = 0; i < n; i++)
                {
                    IAzOperation op = app.CreateOperation("Operation" + i.ToString(), o);
                    op.OperationID = i + 1;
                    op.Submit(0, null);
                    IAzTask task = app.CreateTask("Task" + i.ToString(), null);
                    task.AddOperation(op.Name, null);
                    task.Submit(0, null);
                    IAzTask roleTask = app.CreateTask("Role" + i.ToString(), null);
                    roleTask.IsRoleDefinition = 1;
                    roleTask.AddTask("Task" + i.ToString(), null);
                    roleTask.Submit(0, null);
                    IAzRole role = app.CreateRole("Role" + i.ToString(), null);
                    role.AddTask("Role" + i.ToString(), null);
                    role.AddMember(id.User.Value, null); //add current user
                    role.Submit(0, null);
                }
            }
            this.StopTimer(this.txtAzManElapsed);
            this.Clessidra(false);
        }
示例#8
0
        private static void MergeStores(string fromStoreLocation, string toStoreLocation)
        {
            LogEntry entry = new LogEntry();

            entry.Severity = TraceEventType.Verbose;
            entry.Priority = -1;

            if (Logger.ShouldLog(entry))
            {
                entry.Message = string.Format("Merging authorization stores.\nFrom Store = \"{0}\"\nTo Store = \"{1}\"...", fromStoreLocation, toStoreLocation);
                Logger.Write(entry);
            }

            try
            {
                AzAuthorizationStore fromStore = new AzAuthorizationStore();
                fromStore.Initialize(0, fromStoreLocation, null);

                AzAuthorizationStore toStore = new AzAuthorizationStore();
                toStore.Initialize(AZ_AZSTORE_FLAG_BATCH_UPDATE, toStoreLocation, null);

                foreach (IAzApplication3 fromApplication in fromStore.Applications)
                {
                    IAzApplication3 toApplication = (IAzApplication3)((IAzAuthorizationStore3)toStore).OpenApplication2(fromApplication.Name, null);

                    var operationsDictionary = new Dictionary <string, IAzOperation>();

                    int nextOperationId = 0;

                    foreach (IAzOperation toOperation in toApplication.Operations)
                    {
                        operationsDictionary.Add(toOperation.Name, toOperation);
                        nextOperationId = Math.Max(nextOperationId, toOperation.OperationID);
                    }

                    foreach (IAzOperation fromOperation in fromApplication.Operations)
                    {
                        IAzOperation toOperation = null;

                        if (operationsDictionary.ContainsKey(fromOperation.Name))
                        {
                            toOperation = operationsDictionary[fromOperation.Name];
                        }
                        else
                        {
                            if (Logger.ShouldLog(entry))
                            {
                                entry.Message = string.Format("Adding new Operation \"{0}\"...", fromOperation.Name);
                                Logger.Write(entry);
                            }

                            toOperation = toApplication.CreateOperation(fromOperation.Name);
                            nextOperationId++;
                            toOperation.OperationID = nextOperationId;
                        }

                        toOperation.Description = fromOperation.Description;
                        toOperation.Submit();
                    }

                    var tasksDictionary = new Dictionary <string, IAzTask>();

                    foreach (IAzTask toTask in toApplication.Tasks)
                    {
                        tasksDictionary.Add(toTask.Name, toTask);
                    }

                    foreach (IAzTask fromTask in fromApplication.Tasks)
                    {
                        IAzTask toTask = null;

                        if (tasksDictionary.ContainsKey(fromTask.Name))
                        {
                            toTask = tasksDictionary[fromTask.Name];
                        }
                        else
                        {
                            if (Logger.ShouldLog(entry))
                            {
                                entry.Message = string.Format("Adding new Task \"{0}\"...", fromTask.Name);
                                Logger.Write(entry);
                            }

                            toTask = toApplication.CreateTask(fromTask.Name);
                        }

                        toTask.IsRoleDefinition = fromTask.IsRoleDefinition;
                        toTask.Description      = fromTask.Description;

                        foreach (string taskOperation in fromTask.Operations)
                        {
                            if (!((object[])toTask.Operations).Contains(taskOperation))
                            {
                                if (Logger.ShouldLog(entry))
                                {
                                    entry.Message = string.Format("Adding Operation \"{0}\" to Task \"{1}\"...", taskOperation, toTask.Name);
                                    Logger.Write(entry);
                                }

                                toTask.AddOperation(taskOperation);
                            }
                        }

                        toTask.Submit();
                    }

                    var rolesDictionary = new Dictionary <string, IAzRoleDefinition>();

                    foreach (IAzRoleDefinition toRole in toApplication.RoleDefinitions)
                    {
                        rolesDictionary.Add(toRole.Name, toRole);
                    }

                    foreach (IAzRoleDefinition fromRole in fromApplication.RoleDefinitions)
                    {
                        IAzRoleDefinition toRole = null;

                        if (rolesDictionary.ContainsKey(fromRole.Name))
                        {
                            toRole = rolesDictionary[fromRole.Name];
                        }
                        else
                        {
                            if (Logger.ShouldLog(entry))
                            {
                                entry.Message = string.Format("Adding new Role Definition \"{0}\"...", fromRole.Name);
                                Logger.Write(entry);
                            }

                            toRole = toApplication.CreateRoleDefinition(fromRole.Name);
                        }

                        toRole.Description = toRole.Description;

                        foreach (string roleOperation in fromRole.Operations)
                        {
                            if (!((object[])toRole.Operations).Contains(roleOperation))
                            {
                                if (Logger.ShouldLog(entry))
                                {
                                    entry.Message = string.Format("Adding Operation \"{0}\" to Role Definition \"{1}\"...", roleOperation, toRole.Name);
                                    Logger.Write(entry);
                                }

                                toRole.AddOperation(roleOperation);
                            }
                        }

                        foreach (string roleTask in fromRole.Tasks)
                        {
                            if (!((object[])toRole.Tasks).Contains(roleTask))
                            {
                                if (Logger.ShouldLog(entry))
                                {
                                    entry.Message = string.Format("Adding Task \"{0}\" to Role Definition \"{1}\"...", roleTask, toRole.Name);
                                    Logger.Write(entry);
                                }

                                toRole.AddTask(roleTask);
                            }
                        }

                        toRole.Submit();
                    }
                }

                if (Logger.ShouldLog(entry))
                {
                    entry.Message = string.Format("Submitting changes...");
                    Logger.Write(entry);
                }

                toStore.Submit();
            }
            catch (Exception ex)
            {
                AuthorizationException authException = new AuthorizationException(string.Format("Failed to merge authorization stores.\nFrom Store = \"{0}\"\nTo Store = \"{1}\"\n", fromStoreLocation, toStoreLocation), ex);

                entry.Severity = TraceEventType.Error;

                if (Logger.ShouldLog(entry))
                {
                    entry.Message = authException.ToString();
                    Logger.Write(entry);
                }

                throw authException;
            }
        }