public void CreateRole(String roleName, String description) { if (String.IsNullOrEmpty(roleName)) { throw new ProviderException("Role name cannot be empty or null."); } if (roleName.Contains(",")) { throw new ArgumentException("Role names cannot contain commas."); } if (RoleExists(roleName)) { throw new ProviderException("Role name already exists."); } if (roleName.Length > 256) { throw new ProviderException("Role name cannot exceed 256 characters."); } using (Session session = XpoHelper.GetNewSession()) { XpoRole role = new XpoRole(session) { RoleName = roleName, ApplicationName = this.ApplicationName, Description = description }; role.Save(); } }
public override Boolean RoleExists(String roleName) { if (String.IsNullOrEmpty(roleName)) { throw new ProviderException("Role name cannot be empty or null."); } using (Session session = XpoHelper.GetNewSession()) { XpoRole role = session.FindObject <XpoRole>(new GroupOperator( GroupOperatorType.And, new BinaryOperator("ApplicationName", ApplicationName, BinaryOperatorType.Equal), new BinaryOperator("RoleName", roleName, BinaryOperatorType.Equal))); return(role != null); } }
public override Boolean DeleteRole(String roleName, Boolean throwOnPopulatedRole) { if (!RoleExists(roleName)) { throw new ProviderException("Role does not exist."); } if (throwOnPopulatedRole && GetUsersInRole(roleName).Length > 0) { throw new ProviderException("Cannot delete a populated role."); } using (Session session = XpoHelper.GetNewSession()) { XpoRole role = session.FindObject <XpoRole>(new GroupOperator( GroupOperatorType.And, new BinaryOperator("ApplicationName", ApplicationName, BinaryOperatorType.Equal), new BinaryOperator("RoleName", roleName, BinaryOperatorType.Equal))); role.Delete(); role.Save(); } return(!RoleExists(roleName)); }