/// <summary>マルチテナント時の所有権を確認するユーティリティ・メソッド</summary> /// <param name="objParentId">string</param> /// <returns>所有権の有・無</returns> private async Task <bool> CheckOwnershipInMultitenantMode(string objParentId) { if (ASPNETIdentityConfig.MultiTenant) { // マルチテナントの場合、 ApplicationUser adminUser = await UserManager.FindByIdAsync(User.Identity.GetUserId()); IList <string> roles = await UserManager.GetRolesAsync(adminUser.Id); //if (adminUser.UserName == ASPNETIdentityConfig.AdministratorUID) if (CheckRole.IsSystemAdmin(roles)) { // 「既定の管理者ユーザ」の場合。 } else { // 「既定の管理者ユーザ」で無い場合、 // 配下のobjectかどうか、チェックをする。 return(objParentId == adminUser.Id); } } else { // マルチテナントでない場合。 } return(true); }
public async Task <ActionResult> Index(EnumAdminMessageId?message) { this.Authorize(); // 色々な結果メッセージの設定 ViewBag.StatusMessage = message == EnumAdminMessageId.DoNotHaveOwnershipOfTheObject ? Resources.AdminController.DoNotHaveOwnershipOfTheObject : message == EnumAdminMessageId.AddSuccess ? Resources.AdminController.AddSuccess : message == EnumAdminMessageId.Error ? Resources.AdminController.Error : message == EnumAdminMessageId.EditSuccess ? Resources.AdminController.EditSuccess : message == EnumAdminMessageId.DeleteSuccess ? Resources.AdminController.DeleteSuccess : ""; // ユーザ一覧表示 // マルチテナント化 : ASP.NET Identity上に分割キーを渡すI/Fが無いので已む無くSession。 ApplicationUser user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); Session["ParentId"] = user.ParentId; // 分割キー Session["IsSystemAdmin"] = CheckRole.IsSystemAdmin(await UserManager.GetRolesAsync(user.Id)); // 「管理者ユーザ」か否か。 //(user.UserName == ASPNETIdentityConfig.AdministratorUID); // 「既定の管理者ユーザ」か否か。 // Usersへのアクセスを非同期化出来ず UsersAdminSearchViewModel model = new UsersAdminSearchViewModel(); model.UserNameforSearch = ""; model.Users = UserManager.Users.AsEnumerable(); return(View(model)); }
public async Task <ActionResult> Details(string id) { this.Authorize(); // ロールを取得 ApplicationRole role = await RoleManager.FindByIdAsync(id); // マルチテナントの場合、所有権を確認する。 if (await this.CheckOwnershipInMultitenantMode(role.ParentId)) { // 配下のobjectである。 } else { // 配下のobjectでない。 // エラー → リダイレクト(一覧へ) return(RedirectToAction("Index", new { Message = EnumAdminMessageId.DoNotHaveOwnershipOfTheObject })); } // ロールに属するユーザを取得 List <string> userNames = new List <string>(); // マルチテナント化 : ASP.NET Identity上に分割キーを渡すI/Fが無いので已む無くSession。 ApplicationUser temp = await UserManager.FindByIdAsync(User.Identity.GetUserId()); Session["ParentId"] = temp.ParentId; // 分割キー Session["IsSystemAdmin"] = CheckRole.IsSystemAdmin(await UserManager.GetRolesAsync(temp.Id)); // 「管理者ユーザ」か否か。 //(temp.UserName == ASPNETIdentityConfig.AdministratorUID); // 「既定の管理者ユーザ」か否か。 foreach (ApplicationUser user in UserManager.Users.AsEnumerable()) { // ユーザがロールに属するかどうか。 if (await UserManager.IsInRoleAsync(user.Id, role.Name)) { // ロールに含まれるユーザ userNames.Add(user.UserName); } else { // ロールに含まれないユーザ } } // ロール詳細表示 ViewBag.UserNames = userNames; ViewBag.UserCount = userNames.Count(); return(View(role)); }
public async Task <ActionResult> List(UsersAdminSearchViewModel model) { this.Authorize(); // ユーザ一覧表示 // マルチテナント化 : ASP.NET Identity上に分割キーを渡すI/Fが無いので已む無くSession。 ApplicationUser user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); Session["ParentId"] = user.ParentId; // 分割キー Session["IsSystemAdmin"] = CheckRole.IsSystemAdmin(await UserManager.GetRolesAsync(user.Id)); // 「管理者ユーザ」か否か。 //(user.UserName == ASPNETIdentityConfig.AdministratorUID); // 「既定の管理者ユーザ」か否か。 Session["SearchConditionOfUsers"] = model.UserNameforSearch; // ユーザ一覧の検索条件 // Usersへのアクセスを非同期化出来ず //model.UserNameforSearch = ""; model.Users = UserManager.Users.AsEnumerable(); return(View("Index", model)); }