扩展Identity 2.1以将用户分配给公司和角色给用户

时间:2016-07-15 07:15:43

标签: asp.net-mvc-5 asp.net-identity-2 asp.net-mvc-5.2

好的,我现在真的迷失了,

我有一个运行良好的应用程序,我有公司订阅可用的数据组。当用户登录时,他们可以从他们的角色允许的数据中访问信息,如果他们有多个角色,他们可以访问对于多个报告领域,如果他们只订阅一个角色,他们只能访问该区域。现在所有数据都是相同的并且每天更新,因此如果100个用户订阅角色1,3和5,他们就可以访问该数据。在过去十年中,公司的用户将使用一次登录来访问数据(一次登录提供给George公司,但Lisa,john,Jerry和bob都使用George的凭据来下载报告)。请注意,每个公司的数据不会发生变化,并且每个公司的网站都不会更改,所有数据和主题都是他们有权访问的网站的一部分。

现在问题。

我的许多用户(访问我的数据的公司)已经要求我们希望能够将用户添加到他们的帐户中,以便他们可以监控谁正在下载哪些报告,因为我收取500,1000的订阅费用和2000年的报告。我的应用程序记录下载的报告,用户可以从用户门户查看这些报告以及下载它的ID。问题是公司希望能够管理自己的用户,有点像帐户管理员。我已经研究过多租户了,这并不适合我的需求,但是从我正在看的内容我觉得我需要为用户和company_id用户角色添加一个company_id 所以每个公司都可以拥有一个管理员角色和用户角色。但不确定,因为我学习和阅读更多关于这一点,我看到了不同的想法。但是没有真正看到一个对我有用的东西。

这是一个例子。

每个用户(公司)都有很多用户,该公司的每个用户都有管理员或用户的角色。用户(公司)可以访问角色允许的许多区域,并且该公司的用户可以访问公司角色提供的报告。 (或查看他们所属的所有群组的汇总数据)。

考虑将此添加到IdentityModels:

    public class ApplicationUserRole : IdentityUserRole<string>
{
    public string CompanyId { get; set; }
}


public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>//, IAppUser
{
    public ApplicationUser()
    {
        this.Id = Guid.NewGuid().ToString();
    }
    public virtual string CompanyId { get; set; }
    public virtual List<CompanyEntity> Company { get; set; }
    public DateTime CreatedOn { get; set; }

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager, string authenticationType)
    {
        var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
        return userIdentity;
    }
}

添加到IdentityConfig:

public string GetCurrentCompanyId(string userName)
    {
        var user = this.FindByName(userName);
        if (user == null)
            return string.Empty;

        var currentCompany = string.Empty;
        if (user.Claims.Count > 0)
        {
            currentCompany = user.Claims.Where(c => c.ClaimType == ConcordyaPayee.Core.Common.ConcordyaClaimTypes.CurrentCompanyId).FirstOrDefault().ClaimValue;
        }
        else
        {
            currentCompany = user.CurrentCompanyId;
        }
        return currentCompany;
    }

    public override Task<IdentityResult> AddToRoleAsync(string userId, string role, string companyId)
    {
        return base.AddToRoleAsync(userId, role);
    }

现在我不确定这个,我是否需要创建一个新的用户存储。以及如何进行身份验证,我是否需要编写新的授权属性。我应该使用索赔吗?或者可能是ACL系统。或者我是否需要找到不同的身份提供者。

任何帮助都将受到极大的赞赏。因为我很困惑。

0 个答案:

没有答案
相关问题