示例#1
0
        public ActionResult RemoveUsers(string userId, string role)
        {
            UserRoleManager manager = new UserRoleManager(db);
            var             result  = manager.RemoveUserFromRole(userId, role);

            return(View(result));
        }
示例#2
0
        private void DeleteRoleItem()
        {
            ServiceObject serviceObject = this.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();

            string          roleName  = base.GetStringProperty(Constants.SOProperties.Role.RoleName, true);
            UserRoleManager urmServer = new UserRoleManager();

            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(base.BaseAPIConnectionString);
                Role role = urmServer.GetRole(roleName);
                if (role == null)
                {
                    throw new ApplicationException(Constants.ErrorMessages.RoleNotExists);
                }

                string   roleItemName = base.GetStringProperty(Constants.SOProperties.Role.RoleItem, true);
                RoleItem remItem      = null;

                foreach (RoleItem ri in role.RoleItems)
                {
                    if (string.Compare(ri.Name, roleItemName, true) == 0)
                    {
                        remItem = ri;
                    }
                }
                if (remItem != null)
                {
                    role.RoleItems.Remove(remItem);
                }
                urmServer.UpdateRole(role);
            }
        }
        public IEnumerable <string> CreateStudent(AppUser user, IAuthenticationManager manager, AppIdentityDbContext db)
        {
            AppUserManager  userMgr = new AppUserManager(new UserStore <AppUser>(db));
            UserRoleManager roleMgr = new UserRoleManager(new RoleStore <UserRoles>(db));

            IdentityResult res = userMgr.Create(user, user.Password);

            userMgr.CheckPassword(user, user.Password);


            if (res.Succeeded && roleMgr.RoleExists("student"))
            {
                IdentityResult role = userMgr.AddToRole(user.Id, "student");
                db.Students.Add(new Student {
                    StudentName = user.UserName,
                });

                ClaimsIdentity identity = userMgr.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
                manager.SignOut();
                manager.SignIn(new AuthenticationProperties
                {
                    IsPersistent = false
                }, identity);

                return(null);
            }
            else
            {
                return(res.Errors);
            }
        }
        private async Task <List <Claim> > CreateJwtClaims(AbpLoginResult <Tenant, User> loginResult)
        {
            var    claims      = loginResult.Identity.Claims.ToList();
            var    nameIdClaim = claims.First(c => c.Type == JwtRegisteredClaimNames.Sub);
            string userModel   = JsonConvert.SerializeObject(Mapper.Map <UserLoginInfoDto>(loginResult.User));
            var    org         = await UserManager.GetOrganizationUnitsAsync(loginResult.User);

            string orgModel = JsonConvert.SerializeObject(Mapper.Map <List <OrgLoginInfo> >(org));
            var    company  = await CompanyManager.FindByIdAsync(loginResult.User.CompanyId);

            string companyModel = JsonConvert.SerializeObject(Mapper.Map <CompanyLoginInfo>(company));
            var    roles        = await UserManager.GetRolesAsync(loginResult.User);

            var max_role_type = await UserRoleManager.MaxRoleType(roles);

            // Specifically add the jti (random nonce), iat (issued timestamp), and sub (subject/user) claims.
            claims.AddRange(new[]
            {
                new Claim("UserModel", userModel),
                new Claim("OrgModel", orgModel),
                new Claim("CompanyModel", companyModel),
                new Claim("MaxRoleType", max_role_type.ToString()),
                new Claim(ClaimTypes.NameIdentifier, nameIdClaim.Value),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                //new Claim(JwtRegisteredClaimNames.Iat, DateTimeOffset.Now.ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer64)
            });

            return(claims);
        }
示例#5
0
 public AccountController()
 {
     _userManager      = new AppUserManager();
     _userRoleManager  = new UserRoleManager();
     _roleManager      = new AppRoleManager();
     _lastVisitManager = new LastVisitManager();
 }
示例#6
0
 public UsersDataAccess()
 {
     //
     // TODO: 在此处添加构造函数逻辑
     //
     manager = new UserRoleManager("CTPPDB", ConfigurationManager.GetCurrentContext());
 }
示例#7
0
    public void BindRbl()
    {
        #region 绑定用户角色

        Users     user       = UserManager.GetUserById(Convert.ToInt32(ViewState["UserId"]));
        DataTable dtuserrole = UserRoleManager.GetAllUserRoles();
        GridViewHelp.BindRBL(dtuserrole, rbtnlistuserrole, "Name", "Id");

        foreach (ListItem lt in rbtnlistuserrole.Items)
        {
            if (lt.Text == user.UserRoles.Name)
            {
                lt.Selected = true;
            }
        }

        #endregion

        #region 绑定用户状态

        DataTable dtuserstate = UserStateManager.GetAllUserState();
        GridViewHelp.BindRBL(dtuserstate, rbtnlistuserstate, "Name", "Id");

        foreach (ListItem lt in rbtnlistuserstate.Items)
        {
            if (lt.Text == user.UserStates.Name)
            {
                lt.Selected = true;
            }
        }

        #endregion
    }
示例#8
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();

            ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "Le nom d'utilisateur ou le mot de passe est incorrect.");
                return;
            }

            ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                OAuthDefaults.AuthenticationType);

            ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                  CookieAuthenticationDefaults.AuthenticationType);

            AuthenticationProperties properties = CreateProperties(user.UserName);
            AuthenticationTicket     ticket     = new AuthenticationTicket(oAuthIdentity, properties);

            context.Validated(ticket);
            context.Request.Context.Authentication.SignIn(cookiesIdentity);
            UserRoleManager.Clear();
        }
示例#9
0
 protected void btnupdate_Click(object sender, EventArgs e)
 {
     #region 更新用户信息
     Users user = new Users();
     user.ID       = Convert.ToInt32(ViewState["UserId"]);
     user.LoginId  = this.txtLoginId.Text.Trim();
     user.Mail     = this.txtmail.Text.Trim();
     user.Name     = this.txtname.Text.Trim();
     user.Phone    = this.txtphone.Text.Trim();
     user.Address  = this.txtaddress.Text.Trim();
     user.LoginPwd = this.txtpwd.Text.Trim();
     foreach (ListItem lt in rbtnlistuserstate.Items)
     {
         if (lt.Selected == true)
         {
             user.UserStates = UserStateManager.GetUserStatesById(Convert.ToInt32(lt.Value));
         }
     }
     foreach (ListItem lt in rbtnlistuserrole.Items)
     {
         if (lt.Selected == true)
         {
             user.UserRoles = UserRoleManager.GetUserRolesById(Convert.ToInt32(lt.Value));
         }
     }
     if (UserManager.UpdateUser(user))
     {
         Response.Redirect("ListAllUsers.aspx");
     }
     else
     {
         Response.Write("<script>alert('更新失败')</script>");
     }
     #endregion
 }
示例#10
0
        public FrmUserRole()
        {
            InitializeComponent();

            //
            userRoleManager = new UserRoleManager();
        }
示例#11
0
文件: RoleOp.cs 项目: wang2650/Bap
        /// <summary>
        /// 角色批量添加人员
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="userIds"></param>
        /// <returns></returns>
        public bool AddUserForRole(int roleId, List <int> userIds)
        {
            bool            result          = true;
            UserRoleManager userRoleManager = new UserRoleManager();

            if (userIds != null && userIds.Count > 0)
            {
                List <WXQ.Enties.UserRole> lt = new List <Enties.UserRole>();
                DateTime dt = DateTime.Now;
                foreach (int m in userIds)
                {
                    if (!UserExitInRole(m, roleId))
                    {
                        WXQ.Enties.UserRole rm = new Enties.UserRole
                        {
                            UserId      = m,
                            RoleId      = roleId,
                            AddDateTime = dt,
                            AddUser     = this.OpUserId.ToString()
                        };
                        userRoleManager.Db.Insertable <WXQ.Enties.UserRole>(rm).AddQueue();
                    }
                }
                result = userRoleManager.Db.SaveQueues() > 0;
            }

            return(result);
        }
示例#12
0
 public void BindDDL()
 {
     #region 绑定用户角色
     DataTable dtuserrole = UserRoleManager.GetAllUserRoles();
     GridViewHelp.BindDDL(dtuserrole, dluserrole, "Name", "Id");
     #endregion
 }
示例#13
0
 protected void btnadd_Click(object sender, EventArgs e)
 {
     #region 注册用户
     Users user = new Users();
     user.LoginId  = txtLoginId.Text;
     user.LoginPwd = txtpwd.Text;
     user.Mail     = txtmail.Text;
     user.Name     = txtname.Text;
     user.Phone    = txtphone.Text;
     user.Address  = txtaddress.Text;
     foreach (ListItem lt in ddluserstate.Items)
     {
         if (lt.Selected == true)
         {
             user.UserStates = UserStateManager.GetUserStatesById(Convert.ToInt32(lt.Value));
         }
     }
     foreach (ListItem lt in ddluserrole.Items)
     {
         if (lt.Selected == true)
         {
             user.UserRoles = UserRoleManager.GetUserRolesById(Convert.ToInt32(lt.Value));
         }
     }
     if (UserManager.UserReg(user))
     {
         Response.Redirect("ListAllUsers.aspx");
     }
     else
     {
         labmessage.Text = "该用户名已被注册,请选择其他用户名";
     }
     #endregion
 }
        public void ValidateFile_Deserialisation(string fileName, bool canDeserialise)
        {
            var basePath = AppDomain.CurrentDomain.BaseDirectory;

            basePath = Path.Combine(basePath, "Resources");
            var path = Path.Combine(basePath, fileName);

            var    manager = new UserRoleManager();
            string message = null;
            var    result  = manager.LoadUserRoleFromFile(path, ref message);

            Assert.AreEqual(canDeserialise, result, "Should return correct deserialisation result");

            if (canDeserialise)
            {
                Assert.IsTrue(string.IsNullOrEmpty(message), "Should return no message if it succeded");
                Assert.IsTrue(manager.UserRoles != null, "Successfully load data");
                Assert.IsTrue(manager.Roles.Count > 0, "Successfully load roles");
                Assert.IsTrue(manager.Users.Count > 0, "Successfully load users");
            }
            else
            {
                Assert.IsTrue(message.StartsWith("Invalid character after parsing property name."), "Should return error message if it failed");
            }
        }
示例#15
0
        private void ListRoleItems()
        {
            base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
            DataTable       results   = base.ServiceBroker.ServicePackage.ResultTable;
            UserRoleManager urmServer = new UserRoleManager();

            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(base.BaseAPIConnectionString);
                Role role = urmServer.GetRole(base.GetStringProperty(Constants.SOProperties.Role.RoleName, true));
                if (role == null)
                {
                    throw new ApplicationException(Constants.ErrorMessages.RoleNotExists);
                }
                RoleItemCollection <Role, RoleItem> items = role.Include;
                foreach (RoleItem ri in items)
                {
                    DataRow row = results.NewRow();
                    results.Rows.Add(FillRoleItemRow(row, ri, false));
                }
                items = role.Exclude;
                foreach (RoleItem ri in items)
                {
                    DataRow row = results.NewRow();
                    results.Rows.Add(FillRoleItemRow(row, ri, true));
                }
            }
        }
示例#16
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;
                }
            }
        }
示例#17
0
        public JsonResult GetUserRole()
        {
            UserRoleManager userRoleManager = new UserRoleManager();
            var             result          = userRoleManager.GetUserRoles();

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
示例#18
0
        public async Task <IActionResult> ManageUserRoles(string userId, string userName)
        {
            ViewBag.userId   = userId;
            ViewBag.userName = userName;

            var user = await _accountService.GetUserById(userId);

            var model = new List <UserRoleManager>();

            foreach (var role in await _adminService.GetRoles().ToListAsync())
            {
                var userRoleManager = new UserRoleManager
                {
                    RoleId   = role.Id,
                    RoleName = role.Name
                };

                if (await _userManager.IsInRoleAsync(user, role.Name))
                {
                    userRoleManager.IsSelected = true;
                }
                else
                {
                    userRoleManager.IsSelected = false;
                }

                model.Add(userRoleManager);
            }

            return(View(model));
        }
示例#19
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;
                }
            }
        }
示例#20
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;
                }
            }
        }
 private async void DeleteUserRole_Click(object sender, RoutedEventArgs e)
 {
     if (UserRoleIdWillBeDeleted.Text != "")
     {
         string id = UserRoleIdWillBeDeleted.Text;
         await UserRoleManager.DeleteUserRole(id, UserRoles);
     }
 }
示例#22
0
        public EFUnitOfWork(string connectionString)
        {
            db = new TourAgencyContext(connectionString);

            userManager   = new UserManager(new UserStore <User>(db));
            roleManager   = new UserRoleManager(new RoleStore <UserRole>(db));
            clientManager = new ClientManager(db);
        }
示例#23
0
 public UserRoleManager GetUserRoleManager()
 {
     if (NeedCreateNewManager(_userRoleManager))
     {
         _userRoleManager = new UserRoleManager(_dbContext);
     }
     return(_userRoleManager);
 }
示例#24
0
        public RoleForm(DbAuthenticationProviderData dbAuthenticationProviderData, ConfigurationContext context)
        {
            this.dbAuthenticationproviderData = dbAuthenticationProviderData;
            InitializeComponent();

            this.userRoleMgr = new UserRoleManager(dbAuthenticationProviderData.Database, context);

            UpdateSaveButtonEnabled();
        }
        private async void Page_Loading(FrameworkElement sender, object args)
        {
            UserRoleLoadingProessRing.IsActive   = true;
            UserRoleLoadingProessRing.Visibility = Visibility.Visible;
            await UserRoleManager.GetUserRoles(UserRoles);

            UserRoleLoadingProessRing.IsActive   = false;
            UserRoleLoadingProessRing.Visibility = Visibility.Collapsed;
        }
 private async void AddUserRole_Click(object sender, RoutedEventArgs e)
 {
     if (UserRoleNameWillBeAdded.Text != "")
     {
         string name = UserRoleNameWillBeAdded.Text;
         var    obj  = new { Name = name };
         await UserRoleManager.AddUserRole(new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json"), UserRoles);
     }
 }
示例#27
0
        public FrmRoleDetail()
        {
            InitializeComponent();

            //
            roleDetailManager = new RoleDetailManager();
            userRoleManager = new UserRoleManager();
            menuManager = new MenuManager();
        }
        public void ValidateFile_Path()
        {
            var    manager = new UserRoleManager();
            string message = null;
            var    result  = manager.LoadUserRoleFromFile("Invalid/Path", ref message);

            Assert.IsFalse(result, "Should fail path validation");
            Assert.AreEqual(message, "Invalid file path.");
        }
示例#29
0
 public HomeController()
 {
     _blogManager     = new BlogManager();
     _categoryManager = new CategoryManager();
     _userRoleManager = new UserRoleManager();
     _userManager     = new AppUserManager();
     _logManager      = new LogManager();
     _commentManager  = new CommentManager();
     _likeManager     = new LikeManager();
 }
 public int InsertUserRole(int userID, int roleID)
 {
     try
     {
         return(UserRoleManager.InsertUserRole(userID, roleID));
     }
     catch
     {
         return(0);
     }
 }
 public int DeleteUserRole(int userRoleID)
 {
     try
     {
         return(UserRoleManager.DeleteUserRole(userRoleID));
     }
     catch
     {
         return(0);
     }
 }
 public List <UserRole> GetRolesForUser(int userID)
 {
     try
     {
         return(UserRoleManager.GetRolesForUser(userID));
     }
     catch
     {
         return(new List <UserRole>());
     }
 }
示例#33
0
文件: FrmUser.cs 项目: hamalawy/ssmp
        public FrmUser()
        {
            InitializeComponent();

            //Create Manager which will use in form
            userManager = new UserManager();
            userTitleManager = new UserTitleManager();
            userRoleManager = new UserRoleManager();
            userStatusManager = new UserStatusManager();

            //
            MODE = Constants.MODE.ADD;
        }
示例#34
0
        public void DeleteUserWithAProfile()
        {
            UserRoleManager urm = new UserRoleManager("EntLibSecurity", Context);
            urm.CreateUser("testuser3", ASCIIEncoding.ASCII.GetBytes("Password"));

            GenericIdentity ident1 = new GenericIdentity("testuser3");

            this.profile.SetProfile(ident1, "test");

            try
            {
                urm.DeleteUser("testuser3");
            }
            catch (Exception ex)
            {
                Assert.Fail("no exception should occur when deleting a user: " + ex.Message);
            }
        }
示例#35
0
        public static void CreateTestData(ConfigurationContext context)
        {
            UserRoleManager urm = new UserRoleManager("EntLibSecurity", context);

            DeleteTestData(context);

            byte[] pwd = SHA1Managed.Create().ComputeHash(ASCIIEncoding.ASCII.GetBytes("Password"));
            byte [] emptyPasswd = SHA1Managed.Create().ComputeHash(ASCIIEncoding.ASCII.GetBytes(""));

            urm.CreateUser("testuser", pwd);
            urm.CreateUser("bogususer", pwd);
            urm.CreateUser("emptyUser", emptyPasswd);

            urm.CreateRole("Admins");
            urm.CreateRole("Managers");
            urm.CreateRole("Users");

            urm.CreateUserRole("testuser", "Users");
            urm.CreateUserRole("testuser", "Managers");
        }
        private void FindUserInRole()
        {
            ServiceObject serviceObject = this.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();

            DataTable results = this.ServicePackage.ResultTable;
            DataRow row;
            bool isRoleMember = false;

            UserRoleManager urmServer = new UserRoleManager();
            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(WFMServerConnectionString);
                Role role = urmServer.GetRole(serviceObject.Properties[Constants.Properties.RoleName].Value as string);
                if (role == null)
                {
                    throw new ApplicationException(Constants.ErrorText.RoleNotExist);
                }

                foreach (RoleItem roleItem in role.Include)
                {
                    string roleItemName = roleItem.Name;

                    if (roleItem is UserItem)
                    {
                        // check if the specified username matches the current roleItem name
                        if (serviceObject.Properties[Constants.Properties.RoleItem].Value.ToString() == roleItem.Name)
                        {
                            // user exist in role
                            row = results.NewRow();
                            results.Rows.Add(FillResultRow(row, true));
                            isRoleMember = true;
                            break;
                        }
                    }
                    else
                    {
                        // It is a group item, use the smartobject method UMUser.Get_Group_Users to resolve all group users  
                        
                        // Open a K2 Server connection
                        smartobjectClient.SmartObjectClientServer smoServer = new smartobjectClient.SmartObjectClientServer();
                        smoServer.CreateConnection();
                        smoServer.Connection.Open(WFMServerConnectionString);

                        // Get a handle to the ' UMUser' SmartObject
                        smartobjectClient.SmartObject umUser = smoServer.GetSmartObject("UMUser");

                        // Specify which method will be called
                        smartobjectClient.SmartListMethod getGroupUsers = umUser.ListMethods["Get_Group_Users"];
                        umUser.MethodToExecute = getGroupUsers.Name;

                        // Split FQN in SecurityLabel and groupname
                        string[] fqn = roleItem.Name.Split(':');
                        
                        // Set the input properties
                        getGroupUsers.InputProperties["Labelname"].Value = fqn[0];
                        getGroupUsers.InputProperties["Group_name"].Value = fqn[1];

                        // Call the method
                        smartobjectClient.SmartObjectList smartObjectGroupUsers = smoServer.ExecuteList(umUser);

                        List<string> groupUsers = new List<string>();

                        foreach (smartobjectClient.SmartObject smo in smartObjectGroupUsers.SmartObjectsList)
                        {
                            groupUsers.Add(smo.Properties["FQN"].Value);
                        }

                        foreach (string user in groupUsers)
                        {
                            // check if the specified username matches the current roleItem name
                            if (serviceObject.Properties[Constants.Properties.RoleItem].Value.ToString() == user)
                            {
                                // user exist in role
                                row = results.NewRow();
                                results.Rows.Add(FillResultRow(row, true));
                                isRoleMember = true;
                                break;
                            }
                        }
                    }
                }

                // the specified user is not found in the specified role
                if (!isRoleMember)
                {
                    row = results.NewRow();
                    results.Rows.Add(FillResultRow(row, false));
                }
            }
        }
示例#37
0
        private void ListRoles()
        {
            base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            UserRoleManager urmServer = new UserRoleManager();
            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(base.BaseAPIConnectionString);
                Role[] roles = urmServer.GetRoles();
                foreach (Role r in roles)
                {
                    DataRow row = results.NewRow();
                    row[Constants.SOProperties.Role.RoleName] = r.Name;
                    row[Constants.SOProperties.Role.RoleDescription] = r.Description;
                    row[Constants.SOProperties.Role.RoleDynamic] = r.IsDynamic;
                    results.Rows.Add(row);
                }
            }
        }
示例#38
0
 private void ListRoleItems()
 {
     base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
     DataTable results = base.ServiceBroker.ServicePackage.ResultTable;
     UserRoleManager urmServer = new UserRoleManager();
     using (urmServer.CreateConnection())
     {
         urmServer.Connection.Open(base.BaseAPIConnectionString);
         Role role = urmServer.GetRole(base.GetStringProperty(Constants.SOProperties.Role.RoleName, true));
         if (role == null)
         {
             throw new ApplicationException(Constants.ErrorMessages.RoleNotExists);
         }
         RoleItemCollection<Role, RoleItem> items = role.Include;
         foreach (RoleItem ri in items)
         {
             DataRow row = results.NewRow();
             results.Rows.Add(FillRoleItemRow(row, ri, false));
         }
         items = role.Exclude;
         foreach (RoleItem ri in items)
         {
             DataRow row = results.NewRow();
             results.Rows.Add(FillRoleItemRow(row, ri, true));
         }
     }
 }
示例#39
0
        private void DeleteRoleItem()
        {
            ServiceObject serviceObject = this.ServiceBroker.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();

            string roleName = base.GetStringProperty(Constants.SOProperties.Role.RoleName, true);
            UserRoleManager urmServer = new UserRoleManager();
            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(base.BaseAPIConnectionString);
                Role role = urmServer.GetRole(roleName);
                if (role == null)
                {
                    throw new ApplicationException(Constants.ErrorMessages.RoleNotExists);
                }

                string roleItemName = base.GetStringProperty(Constants.SOProperties.Role.RoleItem, true);
                RoleItem remItem = null;
                foreach (RoleItem ri in role.Include)
                {
                    if (string.Compare(ri.Name, roleItemName, true) == 0)
                        remItem = ri;
                }
                if (remItem != null)
                {
                    role.Include.Remove(remItem);
                }
                else
                {
                    foreach (RoleItem ri in role.Exclude)
                    {
                        if (string.Compare(ri.Name, roleItemName, true) == 0)
                        {
                            remItem = ri;
                        }
                    }
                    if (remItem != null)
                    {
                        role.Exclude.Remove(remItem);
                    }
                }
                urmServer.UpdateRole(role);
            }
        }
        private void DeleteRoleItem()
        {
            ServiceObject serviceObject = this.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();

            UserRoleManager urmServer = new UserRoleManager();
            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(WFMServerConnectionString);
                Role role = urmServer.GetRole(serviceObject.Properties[Constants.Properties.RoleName].Value as string);
                if (role == null)
                {
                    throw new ApplicationException(Constants.ErrorText.RoleNotExist);
                }

                string roleItemName = serviceObject.Properties[Constants.Properties.RoleItem].Value as string;
                RoleItem remItem = null;
                foreach (RoleItem ri in role.Include)
                {
                    if (string.Compare(ri.Name, roleItemName, true) == 0)
                        remItem = ri;
                }

                if (remItem != null)
                    role.Include.Remove(remItem);
                else
                {
                    foreach (RoleItem ri in role.Exclude)
                    {
                        if (string.Compare(ri.Name, roleItemName, true) == 0)
                            remItem = ri;
                    }

                    if (remItem != null)
                        role.Exclude.Remove(remItem);
                }
                urmServer.UpdateRole(role);
            }
        }
        private void AddRoleItem()
        {
            ServiceObject serviceObject = this.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();

            UserRoleManager urmServer = new UserRoleManager();
            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(WFMServerConnectionString);
                Role role = urmServer.GetRole(serviceObject.Properties[Constants.Properties.RoleName].Value as string);
                if (role == null)
                {
                    throw new ApplicationException(Constants.ErrorText.RoleNotExist);
                }
                string roleItemName = serviceObject.Properties[Constants.Properties.RoleItem].Value as string;
                string roleItemType = serviceObject.Properties[Constants.Properties.RoleItemType].Value as string;
                bool exclude = Convert.ToBoolean(serviceObject.Properties[Constants.Properties.RoleExclude].Value as string);

                switch (roleItemType)
                {
                    case Constants.RoleItemType.Group:
                        GroupItem gi = new GroupItem(roleItemName);
                        if (exclude)
                            role.Exclude.Add(gi);
                        else 
                            role.Include.Add(gi);
                        break;
                    case Constants.RoleItemType.User:
                        UserItem ui = new UserItem(roleItemName);
                        if (exclude)
                            role.Exclude.Add(ui);
                        else 
                            role.Include.Add(ui);
                        break;
 
                    default:
                        throw new ApplicationException(string.Format(Constants.ErrorText.RoleTypeNotSupported, roleItemType));
                        //break;
                }

                urmServer.UpdateRole(role);
            }
        }
        private void ListRoleItems()
        {
            ServiceObject serviceObject = this.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();

            DataTable results = this.ServicePackage.ResultTable;

            UserRoleManager urmServer = new UserRoleManager();
            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(WFMServerConnectionString);
                Role role = urmServer.GetRole(serviceObject.Properties[Constants.Properties.RoleName].Value as string);
                if (role == null)
                {
                    throw new ApplicationException(Constants.ErrorText.RoleNotExist);
                }
                RoleItemCollection<Role, RoleItem> items = role.Include;
                foreach (RoleItem ri in items)
                {
                    DataRow row = results.NewRow();
                    results.Rows.Add(FillRoleItemRow(row, ri, false));
                }

                items = role.Exclude;
                foreach (RoleItem ri in items)
                {
                    DataRow row = results.NewRow();
                    results.Rows.Add(FillRoleItemRow(row, ri, true));
                }
            }
        }
        private void ListRoles()
        {
            ServiceObject serviceObject = this.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();
            DataTable results = this.ServicePackage.ResultTable;

            UserRoleManager urmServer = new UserRoleManager();
            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(WFMServerConnectionString);
                Role[] roles = urmServer.GetRoles();
                foreach (Role r in roles)
                {
                    DataRow row = results.NewRow();
                    row[Constants.Properties.RoleName] = r.Name;
                    row[Constants.Properties.RoleDescription] = r.Description;
                    row[Constants.Properties.RoleGuid] = r.Guid;
                    row[Constants.Properties.RoleDynamic] = r.IsDynamic;
                    row[Constants.Properties.RoleExtraData] = r.ExtraData;
                    results.Rows.Add(row);
                }
            }
        }
        private void AddRole()
        {
            ServiceObject serviceObject = this.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();

            Role role = new Role();
            UserRoleManager urmServer = new UserRoleManager();

            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(WFMServerConnectionString);

                string roleName = serviceObject.Properties[Constants.Properties.RoleName].Value as string;
                string roleDescription = serviceObject.Properties[Constants.Properties.RoleDescription].Value as string;
                bool roleIsDynamic = Convert.ToBoolean(serviceObject.Properties[Constants.Properties.RoleDynamic].Value as string);

                role.Name = roleName;
                role.Description = roleDescription;
                role.IsDynamic = roleIsDynamic;

                // At least one roleItem has to be created with the new group
                string roleItemName = serviceObject.Properties[Constants.Properties.RoleItem].Value as string;
                string roleItemType = serviceObject.Properties[Constants.Properties.RoleItemType].Value as string;

                switch (roleItemType)
                {
                    case Constants.RoleItemType.Group:
                        GroupItem gi = new GroupItem(roleItemName);
                        role.Include.Add(gi);
                        break;
                    case Constants.RoleItemType.User:
                        UserItem ui = new UserItem(roleItemName);
                        role.Include.Add(ui);
                        break;
                    default:
                        throw new ApplicationException(string.Format(Constants.ErrorText.RoleTypeNotSupported, roleItemType));
                    //break;
                }

                urmServer.CreateRole(role);
                urmServer.Connection.Close();
            }
        }
示例#45
0
        public static void DeleteTestData(ConfigurationContext context)
        {
            Data.Database db = DatabaseFactory.CreateDatabase("EntLibSecurity");
            DBCommandWrapper cmd = db.GetSqlStringCommandWrapper("delete Profiles");
            db.ExecuteNonQuery(cmd);

            UserRoleManager urm = new UserRoleManager("EntLibSecurity", context);

            try
            {
                urm.DeleteUserRole("testuser", "Users");
            }
            catch
            {
            }
            try
            {
                urm.DeleteUserRole("testuser", "Managers");
            }
            catch
            {
            }

            try
            {
                urm.DeleteRole("Admins");
            }
            catch
            {
            }
            try
            {
                urm.DeleteRole("Managers");
            }
            catch
            {
            }
            try
            {
                urm.DeleteRole("Users");
            }
            catch
            {
            }

            try
            {
                urm.DeleteUser("testuser");
            try {urm.DeleteUser("emptyUser");} catch{}
            }
            catch
            {
            }
            try
            {
                urm.DeleteUser("bogususer");
            }
            catch
            {
            }
            try
            {
                urm.DeleteUser("emptyUser");
            }
            catch
            {
            }
        }
 public void Setup()
 {
     manager = new UserRoleManager(DbServiceKey, Context);
 }
示例#47
0
 private void DeleteRole()
 {
     base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
     DataTable results = base.ServiceBroker.ServicePackage.ResultTable;
     UserRoleManager urmServer = new UserRoleManager();
     using (urmServer.CreateConnection())
     {
         urmServer.Connection.Open(base.BaseAPIConnectionString);
         string roleName = base.GetStringProperty(Constants.SOProperties.Role.RoleName, true);
         Role role = urmServer.GetRole(roleName);
         if (role == null)
         {
             throw new ApplicationException(Constants.ErrorMessages.RoleNotExists);
         }
         else
         {
             urmServer.DeleteRole(role.Guid, role.Name);
             urmServer.Connection.Close();
         }
     }
 }
示例#48
0
        private void AddRole()
        {
            base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;
            Role role = new Role();
            UserRoleManager urmServer = new UserRoleManager();
            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(base.BaseAPIConnectionString);

                role.Name = base.GetStringProperty(Constants.SOProperties.Role.RoleName, true);
                role.Description = base.GetStringProperty(Constants.SOProperties.Role.RoleDescription);;
                role.IsDynamic = base.GetBoolProperty(Constants.SOProperties.Role.RoleDynamic);

                // At least one roleItem has to be created with the new group
                string roleItemName = base.GetStringProperty(Constants.SOProperties.Role.RoleItem, true);
                string roleItemType = base.GetStringProperty(Constants.SOProperties.Role.RoleItemType, true);
                switch (roleItemType.ToUpper())
                {
                    case "GROUP":
                        GroupItem gi = new GroupItem(roleItemName);
                        role.Include.Add(gi);
                        break;
                    case "USER":
                        UserItem ui = new UserItem(roleItemName);
                        role.Include.Add(ui);
                        break;
                    default:
                        throw new ApplicationException(string.Format(Constants.ErrorMessages.RoleTypeNotSupported, roleItemType));
                    //break;
                }
                urmServer.CreateRole(role);
                urmServer.Connection.Close();
            }
        }
        private void DeleteRole()
        {
            ServiceObject serviceObject = this.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();

            UserRoleManager urmServer = new UserRoleManager();

            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(WFMServerConnectionString);

                string roleName = serviceObject.Properties[Constants.Properties.RoleName].Value as string;
                Guid roleGUID = new Guid(serviceObject.Properties[Constants.Properties.RoleGuid].Value as string);

                Role role = urmServer.GetRole(roleName);
                if (role == null)
                {
                    throw new ApplicationException(Constants.ErrorText.RoleNotExist);
                }
                else
                {
                    urmServer.DeleteRole(roleGUID, roleName);
                    urmServer.Connection.Close();
                }
            }
        }
示例#50
0
        private void AddRoleItem()
        {
            ServiceObject serviceObject = this.ServiceBroker.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();

            UserRoleManager urmServer = new UserRoleManager();
            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(base.BaseAPIConnectionString);
                Role role = urmServer.GetRole(base.GetStringProperty(Constants.SOProperties.Role.RoleName,true));
                if (role == null)
                {
                    throw new ApplicationException(Constants.ErrorMessages.RoleNotExists);
                }
                string roleItemName = base.GetStringProperty(Constants.SOProperties.Role.RoleItem, true);
                string roleItemType = base.GetStringProperty(Constants.SOProperties.Role.RoleItemType, true);
                bool exclude = base.GetBoolProperty(Constants.SOProperties.Role.RoleExclude);
                switch (roleItemType.ToUpper())
                {
                    case "GROUP":
                        GroupItem gi = new GroupItem(roleItemName);
                        if (exclude)
                            role.Exclude.Add(gi);
                        else
                            role.Include.Add(gi);
                        break;
                    case "USER":
                        UserItem ui = new UserItem(roleItemName);
                        if (exclude)
                            role.Exclude.Add(ui);
                        else
                            role.Include.Add(ui);
                        break;
                    default:
                        throw new ApplicationException(string.Format(Constants.ErrorMessages.RoleTypeNotSupported, roleItemType));
                    //break;
                }
                urmServer.UpdateRole(role);
            }
        }
示例#51
0
        /// <devdoc>
        /// Compares the password passed in against the password stored in the database.
        /// </devdoc>
        private bool PasswordsMatch(byte[] password, string userName)
        {
            DbAuthenticationProviderData dbAuthenticationProviderData = (DbAuthenticationProviderData)securityConfigurationView.GetAuthenticationProviderData(ConfigurationName);
            bool result = false;
            UserRoleManager manager = new UserRoleManager(dbAuthenticationProviderData.Database, securityConfigurationView.ConfigurationContext);
            byte[] hashedPassword = manager.GetPassword(userName);

            if (hashedPassword != null)
            {
                HashProviderFactory hashFactory = new HashProviderFactory(securityConfigurationView.ConfigurationContext);
                IHashProvider hashProvider = hashFactory.CreateHashProvider(dbAuthenticationProviderData.HashProvider);
                result = hashProvider.CompareHash(password, hashedPassword);
            }
            return result;
        }