public async Task <ActionResult> Query(RoleQueryViewModel model) { if (ModelState.IsValid) { using (RoleServiceClient client = new RoleServiceClient()) { await Task.Run(() => { StringBuilder where = new StringBuilder(); if (model != null) { if (!string.IsNullOrEmpty(model.RoleName)) { where.AppendFormat("Key LIKE '{0}%'", model.RoleName); } } PagingConfig cfg = new PagingConfig() { Where = where.ToString() }; MethodReturnResult <IList <Role> > result = client.Get(ref cfg); if (result.Code == 0) { ViewBag.PagingConfig = cfg; ViewBag.RoleList = result.Data; } }); } } return(PartialView("_RoleListPartial")); }
void GetUserRoles(CookieContainer cookieContainer) { string endPtAddr = strEndPtAddr("MyRoleSvcWrap"); RoleServiceClient roleSvc = new RoleServiceClient(new BasicHttpBinding(), new EndpointAddress(endPtAddr)); using (new OperationContextScope(roleSvc.InnerChannel)) { // CookieContainer must be set in order to call GetRolesForCurrentUser(). // 1638 SetCookies(OperationContext.Current, cookieContainer); string[] roles = roleSvc.GetRolesForCurrentUser(); if (roles.Length == 0) { Console.WriteLine("User does not belong to any role."); } else { string userRoles = ""; for (int i = 0; i < roles.Length; i++) { userRoles += roles[i] + " "; } Console.WriteLine("User's roles: " + userRoles); } } }
public ActionResult RoleService(string baseUrl, string token) { var serviceUrl = string.IsNullOrWhiteSpace(baseUrl) ? GetAbsoluteUrl("~/Public/Role.svc") : baseUrl + "/Public/Role.svc"; var binding = new BasicHttpBinding(); if (serviceUrl.StartsWith("https://")) { binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential; } if (string.IsNullOrWhiteSpace(token)) { token = Repository.OfType <AccessToken>().Queryable.Where(x => x.Application.Name == "Catbert" && x.Active). Select(x => x.Token).FirstOrDefault(); } Check.Require(token != null, "No access tokens for catbert found"); var client = new RoleServiceClient(binding, new EndpointAddress(serviceUrl)); client.ClientCredentials.UserName.UserName = "******"; client.ClientCredentials.UserName.Password = token; string[] users; using (client) { users = client.GetUsersInRole("Catbert", "Admin"); } return(Content("User count: " + users.Length)); }
// // GET: /RBAC/Role/Detail /// <summary> /// Details the specified role name. /// </summary> /// <param name="roleName">Name of the role.</param> /// <returns>Task<ActionResult>.</returns> public async Task <ActionResult> Detail(string roleName) { using (RoleServiceClient client = new RoleServiceClient()) { MethodReturnResult <Role> result = await client.GetAsync(roleName ?? string.Empty); if (result.Code == 0) { RoleViewModel viewModel = new RoleViewModel() { RoleName = result.Data.Key, CreateTime = result.Data.CreateTime, Creator = result.Data.Creator, Description = result.Data.Description, Editor = result.Data.Editor, EditTime = result.Data.EditTime }; return(PartialView("_RoleInfoPartial", viewModel)); } else { ModelState.AddModelError("", result.Message); } } return(PartialView("_RoleInfoPartial")); }
public CustomUserStore( UserServiceClient userclient, RoleServiceClient roleclient, ClaimsServiceClient claimsclient, IMapper mapper) //, ILogger logger) { this.userclient = userclient; this.roleclient = roleclient; this.claimsclient = claimsclient; this.mapper = mapper; // this.logger = logger; // this.logger.LogDebug(@"CTOR {nameof(CustomUserStore)}"); }
public async Task <ActionResult> Delete(string roleName) { using (RoleServiceClient client = new RoleServiceClient()) { MethodReturnResult result = await client.DeleteAsync(roleName ?? string.Empty); if (result.Code == 0) { result.Message = string.Format(StringResource.Role_Delete_Success, roleName); } return(Json(result)); } }
public IList <Role> GetRoles() { using (RoleServiceClient client = new RoleServiceClient()) { PagingConfig cfg = new PagingConfig() { IsPaging = false }; MethodReturnResult <IList <Role> > result = client.Get(ref cfg); if (result.Code == 0) { return(result.Data); } } return(new List <Role>()); }
public static IList <RoleDto> GetAllRoles(string userType) { RolesServiceReference.RoleServiceClient client = null; IList <RoleDto> Roles = new List <RoleDto>(); Query query = new Query(); client = new RoleServiceClient(); if (userType == "CAUser") { Criterion CriteriaIsApplicableForAckUsers = new Criterion("IsApplicableForAckUsers", false, CriteriaOperator.Equal); query.Add(CriteriaIsApplicableForAckUsers); } Roles = client.FindByQuery(query).Entities.ToList(); client.Close(); //Session["UsersRolesList"] = Roles; return(Roles); }
// // GET: /RBAC/Role/ /// <summary> /// Indexes this instance. /// </summary> /// <returns>Task<ActionResult>.</returns> public async Task <ActionResult> Index() { using (RoleServiceClient client = new RoleServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig(); MethodReturnResult <IList <Role> > result = client.Get(ref cfg); if (result.Code == 0) { ViewBag.PagingConfig = cfg; ViewBag.RoleList = result.Data; } }); } return(View()); }
public async Task <ActionResult> SaveRole(RoleViewModel model) { using (RoleServiceClient client = new RoleServiceClient()) { Role u = new Role() { Description = model.Description, Editor = User.Identity.Name, EditTime = DateTime.Now, CreateTime = DateTime.Now, Creator = User.Identity.Name, Key = model.RoleName }; MethodReturnResult rst = await client.AddAsync(u); if (rst.Code == 0) { rst.Message = string.Format(StringResource.Role_SaveRole_Success, u.Key); } return(Json(rst)); } }
public async Task <ActionResult> PagingQuery(string where, string orderBy, int?currentPageNo, int?currentPageSize) { if (ModelState.IsValid) { int pageNo = currentPageNo ?? 0; int pageSize = currentPageSize ?? 20; if (Request["PageNo"] != null) { pageNo = Convert.ToInt32(Request["PageNo"]); } if (Request["PageSize"] != null) { pageSize = Convert.ToInt32(Request["PageSize"]); } using (RoleServiceClient client = new RoleServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { PageNo = pageNo, PageSize = pageSize, Where = where ?? string.Empty, OrderBy = orderBy ?? string.Empty }; MethodReturnResult <IList <Role> > result = client.Get(ref cfg); if (result.Code == 0) { ViewBag.PagingConfig = cfg; ViewBag.RoleList = result.Data; } }); } } return(PartialView("_RoleListPartial")); }
private RoleServiceClient GetClient() { var binding = new BasicHttpBinding { SendTimeout = TimeSpan.FromMinutes(1), Security = { Mode = BasicHttpSecurityMode.TransportWithMessageCredential, Message = {ClientCredentialType = BasicHttpMessageCredentialType.UserName} } }; var endpointAddress = new EndpointAddress(ServiceUrl); var client = new RoleServiceClient(binding, endpointAddress); client.ClientCredentials.UserName.UserName = ApplicationName; client.ClientCredentials.UserName.Password = AuthToken; return client; }
public RoleRepository() { roleServiceClient = new RoleServiceClient(); roleServiceClient.Open(); }
public async Task <ActionResult> SaveModify(RoleViewModel model , SetRoleUserViewModel roleUser , SetRoleResourceViewModel roleResource) { MethodReturnResult rst = new MethodReturnResult(); try { using (RoleServiceClient client = new RoleServiceClient()) { MethodReturnResult <Role> result = await client.GetAsync(model.RoleName); if (result.Code > 0) { return(Json(result)); } //修改角色基本信息。 result.Data.Description = model.Description; result.Data.Editor = User.Identity.Name; result.Data.EditTime = DateTime.Now; rst = await client.ModifyAsync(result.Data); if (rst.Code > 0) { return(Json(rst)); } //设置角色用户 IList <UserInRole> lstUserInRole = new List <UserInRole>(); if (roleUser.Users != null) { foreach (string loginName in roleUser.Users) { lstUserInRole.Add(new UserInRole() { Key = new UserInRoleKey() { LoginName = loginName, RoleName = model.RoleName }, Editor = User.Identity.Name, EditTime = DateTime.Now }); } } rst = await client.SetRoleUserAsync(model.RoleName, lstUserInRole); if (rst.Code > 0) { return(Json(rst)); } //设置角色资源 IList <RoleOwnResource> lstRoleOwnResource = new List <RoleOwnResource>(); if (roleResource.Resources != null) { foreach (string val in roleResource.Resources) { string[] vals = val.Split('$'); ResourceType type = (ResourceType)Enum.Parse(typeof(ResourceType), vals[0]); string code = string.Concat(vals.Skip(1)); lstRoleOwnResource.Add(new RoleOwnResource() { Key = new RoleOwnResourceKey() { RoleName = model.RoleName, ResourceCode = code, ResourceType = type }, Editor = User.Identity.Name, EditTime = DateTime.Now }); } } rst = await client.SetRoleResourceAsync(model.RoleName, lstRoleOwnResource); if (rst.Code > 0) { return(Json(rst)); } if (rst.Code == 0) { rst.Message = string.Format(StringResource.Role_SaveModify_Success, model.RoleName); } return(Json(rst)); } } catch (Exception ex) { rst.Code = 1000; rst.Message = ex.Message; } return(Json(rst)); }
public CustomRoleStore(RoleServiceClient client, IMapper mapper) { _authSrvClient = client; _mapper = mapper; }