Beispiel #1
0
        /// <summary>
        ///  create a role
        /// </summary>
        /// <param name="roleName">role name</param>
        /// <param name="roleDescription">roleDescription's description</param>
        /// <param name="users">user ad's</param>
        public static void CreateRole(string roleName, string roleDescription, string users)
        {
            if (string.IsNullOrEmpty(users))
            {
                return;
            }

            SourceCode.Security.UserRoleManager.Management.UserRoleManager roleManager = new UserRoleManager();

            try
            {
                roleManager.CreateConnection();
                roleManager.Connection.Open(GetServerConnectionSetup());
                if (roleManager.GetRole(roleName) == null)
                {
                    SourceCode.Security.UserRoleManager.Management.Role role = new SourceCode.Security.UserRoleManager.Management.Role();

                    // Set Role Name, Description and Properties
                    role.Name        = roleName;
                    role.Description = roleDescription;
                    role.IsDynamic   = true;

                    ////Add users to Include in Role
                    ////role.Include.Add(new UserItem("K2:DENALLIX\\Anthony"));
                    string[] user = users.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string u in user)
                    {
                        string us = SecurityLabelName + ":" + u;
                        if (role.Include[us] == null)
                        {
                            role.Include.Add(new UserItem(us));
                        }
                    }

                    roleManager.CreateRole(role);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (roleManager != null)
                {
                    roleManager.Connection.Close();
                    roleManager.Connection.Dispose();
                    roleManager.DeleteConnection();
                    roleManager.Connection = null;
                    roleManager            = null;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///  Add users to a role
        /// </summary>
        /// <param name="roleName">role name</param>
        /// <param name="users">user ad's</param>
        public static void AddUsersToRole(string roleName, string users)
        {
            SourceCode.Security.UserRoleManager.Management.UserRoleManager roleManager = new UserRoleManager();

            try
            {
                roleManager.CreateConnection();
                roleManager.Connection.Open(GetServerConnectionSetup());

                SourceCode.Security.UserRoleManager.Management.Role role = roleManager.GetRole(roleName);

                ////Add users to Include in Role
                ////role.Include.Add(new UserItem("K2:DENALLIX\\Anthony"));
                if (role != null)
                {
                    string[] user = users.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string u in user)
                    {
                        string us = SecurityLabelName + ":" + u;
                        if (role.Include[us] == null)
                        {
                            role.Include.Add(new UserItem(us));
                        }
                    }

                    roleManager.UpdateRole(role);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (roleManager != null)
                {
                    roleManager.Connection.Close();
                    roleManager.Connection.Dispose();
                    roleManager.DeleteConnection();
                    roleManager.Connection = null;
                    roleManager            = null;
                }
            }
        }
Beispiel #3
0
        private IList <UserRoleDto> GetIncludeOrExclude(Management.Role role, bool isInclude)
        {
            Management.RoleItemCollection <Management.Role, Management.RoleItem> roleitems = null;
            IList <UserRoleDto> users = new List <UserRoleDto>();

            if (isInclude)
            {
                roleitems = role.Include;
            }
            else
            {
                roleitems = role.Exclude;
            }

            foreach (Management.RoleItem roleitem in roleitems)
            {
                UserRoleDto user   = new UserRoleDto();
                var         single = GetEmployee(roleitem.Name);

                if (single != null)
                {
                    user.fullName   = single.fullName;
                    user.Devision   = single.devision;
                    user.EmployeeNo = single.employeeNo;
                    user.GroupName  = single.groupName;
                    user.Position   = single.position;
                    user.SubDept    = single.subDept;
                }

                user.LoginName = SecurityLabel.GetNameWithoutLabel(roleitem.Name).ToUpper();
                user.Include   = isInclude;

                users.Add(user);
            }

            return(users);
        }
        /// <summary>
        /// This function copies the local Roles to URM roles. This is a little different from the CopyToLocalRole method since URM.Role.Include/Exclude is readonly.
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        private URM.Role CopyToURMRole(Role role)
        {
            URM.Role r = new URM.Role();
            r.Description = role.Description;
            r.ExtraData = role.ExtraData;
            r.Guid = role.Guid;
            r.IsDynamic = role.IsDynamic;
            r.Name = role.Name;

            SetRoleItems(r.Include, role.Includes);
            SetRoleItems(r.Exclude, role.Excludes);

            return r;
        }