コード例 #1
0
        /// <summary>
        ///  delete role
        /// </summary>
        /// <param name="roleName">role name</param>
        public static void DeleteRole(string roleName)
        {
            UserRoleManager roleManager = new UserRoleManager();

            try
            {
                roleManager.CreateConnection();
                roleManager.Connection.Open(GetServerConnectionSetup());
                Role role = roleManager.GetRole(roleName);
                if (role != null)
                {
                    roleManager.DeleteRole(role.Guid, roleName);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (roleManager != null)
                {
                    roleManager.Connection.Close();
                    roleManager.Connection.Dispose();
                    roleManager.DeleteConnection();
                    roleManager.Connection = null;
                    roleManager            = null;
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///  Get users of role by role name
        /// </summary>
        /// <param name="roleName">role name</param>
        /// <returns>return users</returns>
        public static string[] GetRoleUsers(string roleName)
        {
            UserRoleManager roleManager = new UserRoleManager();

            try
            {
                roleManager.CreateConnection();
                roleManager.Connection.Open(GetServerConnectionSetup());
                Role     role  = roleManager.GetRole(roleName);
                string[] names = new string[role.Include.Count];
                for (int i = 0; i < role.Include.Count; i++)
                {
                    names[i] = role.Include[i].Name;
                }

                return(names);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (roleManager != null)
                {
                    roleManager.Connection.Close();
                    roleManager.Connection.Dispose();
                    roleManager.DeleteConnection();
                    roleManager.Connection = null;
                    roleManager            = null;
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///  Get roles
        /// </summary>
        /// <returns>return roles</returns>
        public static string[] GetRoles()
        {
            UserRoleManager roleManager = new UserRoleManager();

            try
            {
                roleManager.CreateConnection();
                roleManager.Connection.Open(GetServerConnectionSetup());
                string[] roleNameList = roleManager.GetRoleNameList();
                return(roleNameList);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (roleManager != null)
                {
                    roleManager.Connection.Close();
                    roleManager.Connection.Dispose();
                    roleManager.DeleteConnection();
                    roleManager.Connection = null;
                    roleManager            = null;
                }
            }
        }
コード例 #4
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;
                }
            }
        }
コード例 #5
0
        /// <summary>
        ///  delete users of role
        /// </summary>
        /// <param name="roleName">role name</param>
        /// <param name="users">user ad's</param>
        public static void DeleteUserFromRole(string roleName, string users)
        {
            UserRoleManager roleManager = new UserRoleManager();

            try
            {
                roleManager.CreateConnection();
                roleManager.Connection.Open(GetServerConnectionSetup());
                Role role = roleManager.GetRole(roleName);
                if (role != null)
                {
                    string[] user = users.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string u in user)
                    {
                        role.Include.Remove(role.Include[SecurityLabelName + ":" + u]);
                    }

                    roleManager.UpdateRole(role);
                    roleManager.Connection.Dispose();
                    roleManager.DeleteConnection();
                    roleManager.Connection = null;
                    roleManager            = null;
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (roleManager != null)
                {
                    roleManager.Connection.Close();
                    roleManager.Connection.Dispose();
                    roleManager.DeleteConnection();
                    roleManager.Connection = null;
                    roleManager            = null;
                }
            }
        }
コード例 #6
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;
                }
            }
        }