コード例 #1
0
        private static void ApplyChanges(List <SimpleUser> changes, ADToPermissionCenterSynchronizer context)
        {
            string[] changesIdArray             = changes.Select <SimpleUser, string>(m => m.SCObjectID).ToArray();
            PC.SchemaObjectCollection pcObjects = LoadSCObjects(changesIdArray);

            foreach (SimpleUser item in changes)
            {
                if (pcObjects.ContainsKey(item.SCObjectID))
                {
                    try
                    {
                        PC.SchemaObjectBase scObj = MeargeChanges(item.Tag, pcObjects[item.SCObjectID]);

                        PC.Adapters.SchemaObjectAdapter.Instance.Update(scObj);
                        context.Log.NumberOfModifiedItems++;
                    }
                    catch (Exception ex)
                    {
                        context.Log.NumberOfExceptions++;
                        context.Log.Status = ADSynchronizeResult.HasError;
                        LogHelper.WriteReverseSynchronizeDBLogDetail(context.Log.LogID, item.SCObjectID, AttributeHelper.Hex((byte[])item.Tag.Properties["objectguid"][0]), item.CodeName, ex.Message, ex.ToString());
                        Trace.TraceError("未成功更新," + ex.ToString());
                    }
                }
                else
                {
                    LogHelper.WriteReverseSynchronizeDBLogDetail(context.Log.LogID, item.SCObjectID, AttributeHelper.Hex((byte[])item.Tag.Properties["objectguid"][0]), item.CodeName, "未找到AD对象对应的权限中心对象。", null);
                }
            }
        }
コード例 #2
0
ファイル: BatchEditor.aspx.cs プロジェクト: wooln/AK47Source
        private HashSet <string> GetSchemaTypes(PC.SchemaObjectCollection objects)
        {
            HashSet <string> result = new HashSet <string>();

            objects.ForEach <PC.SchemaObjectBase>(item => result.Add(item.SchemaType));

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// 得到所有预定义的和计算的用户
        /// </summary>
        /// <returns></returns>
        public SchemaObjectCollection GetAllCurrentAndCalculatedUsers()
        {
            SchemaObjectCollection result = GetCurrentUsers();

            result.Merge(GetCalculatedUsers());

            return(result);
        }
コード例 #4
0
        protected override void OnIDChanged()
        {
            base.OnIDChanged();

            this._AllChildrenRelations = null;
            this._AllChildren          = null;
            this._CurrentlChildren     = null;
        }
コード例 #5
0
        public SchemaObjectCollection ToSchemaObjects()
        {
            SchemaObjectCollection result = new SchemaObjectCollection();

            this.ForEach(u => result.Add(u));

            return(result);
        }
コード例 #6
0
ファイル: SCRole.cs プロジェクト: wooln/AK47Source
        /// <summary>
        /// 得到所有预定义的用户
        /// </summary>
        /// <returns></returns>
        public SchemaObjectCollection GetCurrentUsers()
        {
            SchemaObjectCollection result = this.CurrentMembers.ToUsers(true);

            if (this.Properties.GetValue("includeMatrixUsers", false))
            {
                EnumMatrixUsers(result);
            }

            return(result);
        }
コード例 #7
0
 /// <summary>
 /// 处理ID改变
 /// </summary>
 protected override void OnIDChanged()
 {
     base.OnIDChanged();
     this._AllMemberOfRelations = null;
     this._AllGroups            = null;
     this._CurrentGroups        = null;
     this._AllSecretaries       = null;
     this._CurrentSecretaries   = null;
     this._AllSecretariesOf     = null;
     this._CurrentSecretariesOf = null;
     this._AllMembersRelations  = null;
     this._CurrentMembers       = null;
 }
コード例 #8
0
ファイル: SCRole.cs プロジェクト: wooln/AK47Source
        protected override void OnIDChanged()
        {
            base.OnIDChanged();

            this._AllMembersRelations = null;
            this._AllPermissions      = null;
            this._CurrentPermissions  = null;
            this._CurrentMembers      = null;

            this._AllChildrenRelations = null;
            this._AllChildren          = null;
            this._CurrentlChildren     = null;
            this._CurrentApplication   = null;
        }
コード例 #9
0
ファイル: SCRole.cs プロジェクト: wooln/AK47Source
        /// <summary>
        /// 枚举矩阵中的人员
        /// </summary>
        /// <returns></returns>
        private void EnumMatrixUsers(SchemaObjectCollection result)
        {
            if (this.CurrentApplication != null)
            {
                SOARolePropertyRowCollection rows = SOARolePropertiesAdapter.Instance.LoadByRoleID(this.ID, null);

                SCRoleEnumMatrixUsersContext context = new SCRoleEnumMatrixUsersContext();

                context.CachedApplication.Add(this.CurrentApplication.CodeName, this.CurrentApplication);

                string fullCodeName = this.GetFullCodeName();

                context.CalculatedRolesCodeNames.Add(fullCodeName, fullCodeName);

                InternalEnumMatrixUsers(this, context);

                FillMatrixUsers(context, result);
            }
        }
コード例 #10
0
        public SchemaObjectCollection GetCurrentUsers()
        {
            SchemaObjectCollection result = null;

            SCRelationObject relation = this.CurrentParentRelations.FirstOrDefault();

            if (relation != null)
            {
                SCObjectAndRelationCollection objsAndRelations = SCSnapshotAdapter.Instance.QueryObjectAndRelationByParentFullPath(
                    SchemaInfo.FilterByCategory("Users").ToSchemaNames(), new string[] { relation.FullPath }, true, true, false, DateTime.MinValue);

                result = objsAndRelations.ToSchemaObjects();
            }
            else
            {
                result = new SchemaObjectCollection();
            }

            return(result);
        }
コード例 #11
0
        public void FillDetails()
        {
            SchemaObjectCollection allObjs = ToSchemaObjects();

            this.ForEach(sor =>
            {
                sor.Detail = allObjs[sor.ID];

                if (sor.Detail == null)
                {
                    if (string.Compare(SCOrganization.RootOrganizationID, sor.ID, true) == 0)
                    {
                        sor.Detail = SCOrganization.GetRoot();
                    }
                    else
                    {
                        throw new ObjectNotFoundException("Can not find matching detail of object (ID:" + sor.ID + "), there may have data errors");
                    }
                }
            });
        }
コード例 #12
0
ファイル: ObjectDestroyTest.cs プロジェクト: wooln/AK47Source
        public void ClearOrganizationWithChildrenTest()
        {
            var testOrg = NewObject <PC.SCOrganization>();

            Facade.AddOrganization(testOrg, PC.SCOrganization.GetRoot());

            var testSubOrg = NewObject <PC.SCOrganization>();

            Facade.AddOrganization(testSubOrg, testOrg);

            var testChildOrg = NewObject <PC.SCOrganization>();

            Facade.AddOrganization(testChildOrg, testSubOrg);

            var testChildUser = NewObject <PC.SCUser>();

            Facade.AddUser(testChildUser, testSubOrg);

            var testChildGroup = NewObject <PC.SCGroup>();

            Facade.AddGroup(testChildGroup, testSubOrg);

            PC.SchemaObjectCollection collection = new PC.SchemaObjectCollection();
            collection.Add(testSubOrg);

            Facade.DeleteObjectsRecursively(collection, testOrg);

            var actualSubOrg     = LoadObject <PC.SCOrganization>(testSubOrg.ID);
            var actualChildOrg   = LoadObject <PC.SCOrganization>(testChildOrg.ID);
            var actualChildUser  = LoadObject <PC.SCUser>(testChildUser.ID);
            var actualChildGroup = LoadObject <PC.SCGroup>(testChildGroup.ID);

            Assert.AreNotEqual(SchemaObjectStatus.Normal, actualSubOrg.Status);

            Assert.AreEqual(0, actualSubOrg.CurrentChildren.Count);

            Assert.AreEqual(0, actualChildGroup.CurrentParentRelations.Count);
            Assert.AreEqual(0, actualChildOrg.CurrentParentRelations.Count);
            Assert.AreEqual(0, actualChildUser.CurrentParentRelations.Count);
        }
コード例 #13
0
        private void DoHierarchicalAction(SCObjectSet objectSet, IImportContext context, IDictionary <string, PC.SchemaObjectBase> knownObjects, Dictionary <string, IList <PC.SCOrganization> > orgToOrgRelations, Dictionary <string, IList <PC.SCUser> > orgToUserRelations, Dictionary <string, IList <PC.SCGroup> > orgToGroupRelations, PC.SCOrganization currentParent, HierarchicalAction actionAdapter)
        {
            // 爬树
            PC.SchemaObjectCollection objects = objectSet.Objects;

            if (orgToOrgRelations.ContainsKey(currentParent.ID))
            {
                var childList = orgToOrgRelations[currentParent.ID];

                for (int i = 0; i < childList.Count; i++)
                {
                    this.currentSteps++;

                    var org = childList[i];

                    System.Diagnostics.Debug.WriteLine("正在处理组织" + org.Name);

                    actionAdapter.ExecuteEachOrganization(objectSet, context, knownObjects, org, orgToOrgRelations, orgToUserRelations, orgToGroupRelations);

                    this.DoHierarchicalAction(objectSet, context, knownObjects, orgToOrgRelations, orgToUserRelations, orgToGroupRelations, org, actionAdapter);
                }
            }
        }
コード例 #14
0
ファイル: SCObjectSet.cs プロジェクト: wooln/AK47Source
        public void Load(System.IO.TextReader input)
        {
            int count;

            var xmlDoc = new System.Xml.XmlDocument();

            xmlDoc.Load(input);
            SchemaObjectXmlImporter importer = new SchemaObjectXmlImporter();

            var nodeContext = xmlDoc.SelectSingleNode("/sc/context");

            if (nodeContext != null)
            {
                var attrTime = nodeContext.Attributes["timeContext"];
                if (attrTime != null && attrTime.Specified)
                {
                    this.timeContext = System.Xml.XmlConvert.ToDateTime(attrTime.Value, System.Xml.XmlDateTimeSerializationMode.Local);
                }

                var scope = nodeContext.Attributes["scope"];
                if (scope != null && scope.Specified)
                {
                    this.Scope = scope.Value;
                }
            }

            var nodeObjects = xmlDoc.SelectNodes("/sc/objects/Object");

            this.objects = null;
            count        = nodeObjects.Count;

            if (count > 0)
            {
                this.objects = new SchemaObjectCollection();

                for (int i = 0; i < count; i++)
                {
                    var xml        = nodeObjects[i].OuterXml;
                    var schemaType = nodeObjects[i].Attributes["SchemaType"].Value;
                    this.objects.Add(importer.XmlToObject(xml, schemaType));
                }
            }

            nodeObjects    = xmlDoc.SelectNodes("/sc/relations/Object");
            this.relations = null;
            count          = nodeObjects.Count;

            if (count > 0)
            {
                this.relations = new SCRelationObjectCollection();

                for (int i = 0; i < count; i++)
                {
                    var xml        = nodeObjects[i].OuterXml;
                    var schemaType = nodeObjects[i].Attributes["SchemaType"].Value;
                    this.relations.Add((SCRelationObject)importer.XmlToObject(xml, schemaType));
                }
            }

            nodeObjects     = xmlDoc.SelectNodes("/sc/membership/Object");
            this.membership = null;
            count           = nodeObjects.Count;

            if (count > 0)
            {
                this.membership = new SCMemberRelationCollection();

                for (int i = 0; i < count; i++)
                {
                    var xml        = nodeObjects[i].OuterXml;
                    var schemaType = nodeObjects[i].Attributes["SchemaType"].Value;
                    this.membership.Add((SCSimpleRelationBase)importer.XmlToObject(xml, schemaType));
                }
            }

            nodeObjects     = xmlDoc.SelectNodes("/sc/conditions/condition");
            this.conditions = null;
            count           = nodeObjects.Count;

            if (count > 0)
            {
                this.conditions = new MCS.Library.SOA.DataObjects.Security.Conditions.SCConditionCollection();

                for (int i = 0; i < count; i++)
                {
                    var xml = nodeObjects[i];

                    var condition = LoadCondition(xml);

                    this.conditions.Add(condition);
                }
            }

            nodeObjects = xmlDoc.SelectNodes("/sc/acls/acl");
            this.acls   = null;
            count       = nodeObjects.Count;

            if (count > 0)
            {
                this.acls = new SCAclContainerCollection();

                for (int i = 0; i < count; i++)
                {
                    var xml = nodeObjects[i];

                    var acl = LoadAcl(xml);

                    this.acls.Add(acl);
                }
            }
        }
コード例 #15
0
 /// <summary>
 /// 处理ID的变更
 /// </summary>
 protected override void OnIDChanged()
 {
     this._AllParentRelations = null;
     this._AllParents         = null;
     this._CurrentlParents    = null;
 }
コード例 #16
0
        /// <summary>
        /// 准备组织
        /// </summary>
        /// <param name="objectSet"></param>
        /// <param name="context"></param>
        /// <param name="knownObjects">向其中写入已经确认存在于数据库中的项</param>
        /// <param name="orgToOrgRelations">组织关系</param>
        /// <param name="allSteps"></param>
        /// <param name="currentSteps"></param>
        /// <param name="currentParent"></param>
        /// <param name="checkOnly"><see langword="true"/>表示只检查组织关系,不实际导入。</param>
        /// <returns></returns>
        private bool PrepareOrganizations(SCObjectSet objectSet, IImportContext context, IDictionary <string, PC.SchemaObjectBase> knownObjects, Dictionary <string, IList <PC.SCOrganization> > orgToOrgRelations, PC.SCOrganization currentParent, bool checkOnly)
        {
            bool valid = true;

            PC.SchemaObjectCollection objects = objectSet.Objects;

            if (orgToOrgRelations.ContainsKey(currentParent.ID))
            {
                var childList = orgToOrgRelations[currentParent.ID];

                for (int i = 0; i < childList.Count; i++)
                {
                    this.currentSteps++;

                    var org = childList[i];

                    try
                    {
                        // 导入该组织
                        if (checkOnly == false)
                        {
                            var msg = string.Format("正在导入组织{0}", org.ToDescription());
                            context.AppendLog(msg);
                            context.SetStatus(this.currentSteps, this.allSteps, msg);
                            PC.Executors.SCObjectOperations.Instance.AddOrganization(org, currentParent);

                            if (knownObjects.ContainsKey(org.ID) == false)
                            {
                                knownObjects.Add(org.ID, org);
                            }
                        }
                        else
                        {
                            context.SetStatus(this.currentSteps, this.allSteps, string.Format("正在校验组织 {0} ", org.ToDescription()));

                            if (Util.IsNullOrDeleted(PC.Adapters.SchemaObjectAdapter.Instance.Load(org.ID)))
                            {
                                context.AppendLog(string.Format("组织 {0} 不存在,导入时将排除此组织及子对象", org.ToDescription()));
                                valid = false;
                                childList.RemoveAt(i);
                                i--;
                                continue;
                            }
                            else if (Util.IsNullOrDeleted(PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(currentParent.ID, org.ID)))
                            {
                                context.AppendLog(string.Format("组织 {0} 已存在,但已被移至其他位置,导入时将排除此组织及子对象。", org.ToDescription()));
                                valid = false;
                                childList.RemoveAt(i);
                                i--;
                                continue;
                            }
                            else
                            {
                                if (knownObjects.ContainsKey(org.ID) == false)
                                {
                                    knownObjects.Add(org.ID, org);
                                }
                            }
                        }

                        valid &= this.PrepareOrganizations(objectSet, context, knownObjects, orgToOrgRelations, org, checkOnly);
                    }
                    catch (Exception ex)
                    {
                        context.AppendLog(string.Format("导入组织 {0} 时出现错误,已跳过了该组织及子对象:{1}", org.ToDescription(), ex.ToString()));
                        valid = false;
                        childList.RemoveAt(i);
                        i--;
                    }
                }
            }

            return(valid);
        }
コード例 #17
0
ファイル: SCRole.cs プロジェクト: wooln/AK47Source
        private static void FillMatrixUsers(SCRoleEnumMatrixUsersContext context, SchemaObjectCollection result)
        {
            SchemaObjectCollection users = SchemaObjectAdapter.Instance.LoadByCodeName(builder => { }, DateTime.MinValue, context.UsersCodeNames.Keys.ToArray());

            result.Merge(users);
        }