Exemplo n.º 1
0
        private void buttonConvert_Click(object sender, EventArgs e)
        {
            using (AD2DBInitialParams initParams = AD2DBInitialParams.GetParams())
            {
                textBoxLog.Text = string.Empty;

                ServiceLog log = new ServiceLog("ADToAccredit");

                log.AddTextBoxTraceListener(textBoxLog);

                initParams.Log = log;

                this._ProcessedObjectsCount = 0;

                OutputStatus();

                initParams.BeforeProcessADObject += new BeforeProcessADObjectDelegate(initParams_BeforeProcessADObject);

                AD2DBConvertion converter = new AD2DBConvertion(initParams);

                converter.DoConvert();

                OutputStatus();

                OguMechanismFactory.GetMechanism().RemoveAllCache();
                PermissionMechanismFactory.GetMechanism().RemoveAllCache();
            }
        }
Exemplo n.º 2
0
        private void GetApplicationRole()
        {
            List <AppRoles> allRoles = new List <AppRoles>();

            OguObjectCollection <IUser> users = OguMechanismFactory.GetMechanism().GetObjects <IUser>(SearchOUIDType.Guid, Data.ID);

            ExceptionHelper.FalseThrow(users.Count > 0, "不能找到ID为\"{0}\"的用户", Data.ID);

            ApplicationCollection result = PermissionMechanismFactory.GetMechanism().GetAllApplications();

            foreach (IApplication app in result)
            {
                RoleCollection roles = users[0].Roles[app.CodeName];
                if (roles.Count > 0)
                {
                    AppRoles ar = new AppRoles();

                    ar.AppName = app.Name;
                    ar.Roles   = GetRoleNames(roles);

                    allRoles.Add(ar);
                }
            }

            gridAppRoles.DataSource = allRoles;
            gridAppRoles.DataBind();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据描述得到一组角色集合
        /// </summary>
        /// <param name="rolesDesp"></param>
        /// <returns></returns>
        public static IRole[] GetRoles(string rolesDesp)
        {
            List <IRole> result = new List <IRole>();

            if (string.IsNullOrEmpty(rolesDesp) == false)
            {
                AppRolesDespsCollection allAppRolesDesps = GetAppRolesDesps(rolesDesp);

                ApplicationCollection apps = PermissionMechanismFactory.GetMechanism().GetApplications(allAppRolesDesps.GetAppNames());

                foreach (AppRolesDesps appRolesDesps in allAppRolesDesps)
                {
                    if (apps.ContainsKey(appRolesDesps.AppName))
                    {
                        IApplication app = apps[appRolesDesps.AppName];

                        foreach (string roleName in appRolesDesps.RolesDesp)
                        {
                            if (app.Roles.ContainsKey(roleName))
                            {
                                result.Add(app.Roles[roleName]);
                            }
                        }
                    }
                }
            }

            return(result.ToArray());
        }
Exemplo n.º 4
0
        public void OguApplicationCollectionSerializationTest()
        {
            JSONSerializerExecute.RegisterConverter(typeof(OguApplicationConverter));

            ApplicationCollection    originalApps = PermissionMechanismFactory.GetMechanism().GetAllApplications();
            OguApplicationCollection apps         = new OguApplicationCollection(originalApps);

            CheckOguApplicationCollectionItems(apps);

            //测试Set操作
            for (int i = 0; i < apps.Count; i++)
            {
                apps[i] = originalApps[i];
            }

            CheckOguApplicationCollectionItems(apps);

            string serializedData = JSONSerializerExecute.Serialize(apps);

            Console.WriteLine(serializedData);

            OguApplicationCollection deserializedData = JSONSerializerExecute.Deserialize <OguApplicationCollection>(serializedData);

            for (int i = 0; i < apps.Count; i++)
            {
                ValidatePermissionObject(apps[i], deserializedData[i]);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argument"></param>
        public override void Execute(string argument)
        {
            ApplicationCollection applications = PermissionMechanismFactory.GetMechanism().GetApplications(argument);

            ExceptionHelper.FalseThrow(applications.Count > 0, "不能查询到CodeName为\"{0}\"应用", argument);

            applications[0].Permissions.ForEach(p => OutputHelper.OutputPermissionInfo(p));
        }
Exemplo n.º 6
0
        private static IApplication GetApplicationByCodeName(string codeName)
        {
            ApplicationCollection apps = PermissionMechanismFactory.GetMechanism().GetApplications(codeName);

            ExceptionHelper.FalseThrow(apps.Count > 0,
                                       Translator.Translate(Define.DefaultCulture, "不能在授权系统中找到CodeName为'{0}'的应用", codeName));

            return(apps[0]);
        }
Exemplo n.º 7
0
        private static IApplication GetApplicationByID(string id)
        {
            ApplicationCollection apps = PermissionMechanismFactory.GetMechanism().GetAllApplications();

            IApplication app = apps.Find(a => string.Compare(a.ID, id, true) == 0);

            ExceptionHelper.FalseThrow(app != null,
                                       Translator.Translate(Define.DefaultCulture, "不能在授权系统中找到ID为'{0}'的应用", id));

            return(app);
        }
Exemplo n.º 8
0
        public OguRoleCollection GetAppRoles(string codeName)
        {
            ApplicationCollection apps = PermissionMechanismFactory.GetMechanism().GetApplications(codeName);

            OguRoleCollection roles = new OguRoleCollection();

            if (apps.Count > 0)
            {
                roles.CopyFrom(apps[0].Roles);
            }

            return(roles);
        }
Exemplo n.º 9
0
        public void OguApplicationSerializationTest()
        {
            OguApplication app = (OguApplication)OguApplication.CreateWrapperObject(PermissionMechanismFactory.GetMechanism().GetAllApplications().First());

            JSONSerializerExecute.RegisterConverter(typeof(OguApplicationConverter));

            string serializedData = JSONSerializerExecute.Serialize(app);

            Console.WriteLine(serializedData);

            OguApplication deserializedData = JSONSerializerExecute.Deserialize <OguApplication>(serializedData);

            ValidatePermissionObject(app, deserializedData);
        }
Exemplo n.º 10
0
        public override void OnThreadTaskStart()
        {
            using (AD2DBInitialParams initParams = AD2DBInitialParams.GetParams())
            {
                initParams.Log = this.Params.Log;

                AD2DBConvertion converter = new AD2DBConvertion(initParams);

                converter.DoConvert();

                OguMechanismFactory.GetMechanism().RemoveAllCache();
                PermissionMechanismFactory.GetMechanism().RemoveAllCache();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argument"></param>
        public override void Execute(string argument)
        {
            string[] arguments = argument.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

            ExceptionHelper.FalseThrow(arguments.Length > 1, "参数太少,必须提供两个参数,用逗号或空格分开");

            ApplicationCollection applications = PermissionMechanismFactory.GetMechanism().GetApplications(arguments[0]);

            ExceptionHelper.FalseThrow(applications.Count > 0, "不能查询到CodeName为\"{0}\"应用", arguments[0]);

            ExceptionHelper.FalseThrow(applications[0].Permissions.ContainsKey(arguments[1]),
                                       "在应用\"{0}\"中不能查询到CodeName为\"{1}\"的权限", arguments[0], arguments[1]);

            applications[0].Permissions[arguments[1]].RelativeRoles.ForEach(r => OutputHelper.OutputPermissionInfo(r));
        }
Exemplo n.º 12
0
        protected override void OnDialogContentControlLoaded(Control container)
        {
            base.OnDialogContentControlLoaded(container);

            if (string.IsNullOrEmpty(this.DialogTitle))
            {
                this.DialogTitle = RoleGraphControlParams.DefaultDialogTitle;
            }

            this._ApplicationSelector = (HtmlSelect)container.FindControl("applications");
            this._RoleSelector        = (HtmlSelect)container.FindControl("roles");
            this._LoadingTag          = (HtmlGenericControl)container.FindControl("loadingTag");
            this._RelativeLink        = (HtmlAnchor)container.FindControl("relativeLink");

            HtmlGenericControl img = (HtmlGenericControl)container.FindControl("loadingImg");

            if (img != null)
            {
                img.Style["background-image"] = string.Format("url({0})", ControlResources.HourglassLogoUrl);
            }

            OguApplicationCollection apps = new OguApplicationCollection(PermissionMechanismFactory.GetMechanism().GetAllApplications());

            this._ApplicationsData = apps;

            if (apps.Count > 0)
            {
                string appCodeName = GetAppCodeNameFromFullCodeName(this.SelectedFullCodeName);

                IApplication selectedApp = null;

                if (string.IsNullOrEmpty(appCodeName) == false)
                {
                    selectedApp = apps.Find(app => app.CodeName == appCodeName);
                }

                if (selectedApp == null)
                {
                    selectedApp = apps[0];
                }

                this._RolesData = new OguRoleCollection(selectedApp.Roles);
            }
        }
Exemplo n.º 13
0
        /*
         * protected override string GetDialogFeature()
         * {
         *  WindowFeature feature = new WindowFeature();
         *
         *  feature.Width = 420;
         *  feature.Height = 320;
         *  feature.Center = true;
         *  feature.Resizable = false;
         *  feature.ShowScrollBars = false;
         *  feature.ShowStatusBar = false;
         *
         *  return feature.ToDialogFeatureClientString();
         * }
         * */

        private static OguApplicationCollection InitApplicationsData(string fullCodeName)
        {
            OguApplicationCollection result = null;

            string appCodeName = GetAppCodeNameFromFullCodeName(fullCodeName);

            if (string.IsNullOrEmpty(appCodeName))
            {
                result = new OguApplicationCollection(PermissionMechanismFactory.GetMechanism().GetAllApplications());
            }
            else
            {
                result = new OguApplicationCollection(PermissionMechanismFactory.GetMechanism().GetApplications(appCodeName));

                if (result.Count == 0)
                {
                    result = new OguApplicationCollection(PermissionMechanismFactory.GetMechanism().GetAllApplications());
                }
            }

            return(result);
        }
Exemplo n.º 14
0
 private static ApplicationCollection GetAppCollection()
 {
     return(PermissionMechanismFactory.GetMechanism().GetAllApplications());
 }
Exemplo n.º 15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argument"></param>
        public override void Execute(string argument)
        {
            PermissionMechanismFactory.GetMechanism().RemoveAllCache();

            Console.WriteLine("Permission cache cleared");
        }
Exemplo n.º 16
0
 protected void ButtonRemovePermissionCache_Click(object sender, EventArgs e)
 {
     PermissionMechanismFactory.GetMechanism().RemoveAllCache();
     Successful();
 }
Exemplo n.º 17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="argument"></param>
 public override void Execute(string argument)
 {
     PermissionMechanismFactory.GetMechanism().GetAllApplications().ToList().ForEach(
         obj => OutputHelper.OutputPermissionInfo(obj));
 }