Exemplo n.º 1
0
        private IReadOnlyDictionary <string, RoleCached> GetUserRoles(IRolesCache rolesCache)
        {
            if (!Identity.IsAuthenticated)
            {
                return(new Dictionary <string, RoleCached>
                {
                    [RoleNames.Unregistered] = rolesCache.GetRole(RoleNames.Unregistered)
                }.ToImmutableDictionary());
            }

            var roles     = GetRolesNames();
            var allGroups = rolesCache.AllRoles;


            var dictionaryBuilder = ImmutableDictionary.CreateBuilder <string, RoleCached>();

            var registeredGroup = rolesCache.GetRole(RoleNames.Registered);

            dictionaryBuilder.Add(registeredGroup.Name, registeredGroup);
            foreach (var role in roles)
            {
                if (!allGroups.ContainsKey(role))
                {
                    continue;
                }

                var userGroup = allGroups[role];
                dictionaryBuilder.Add(userGroup.Name, userGroup);
            }

            return(dictionaryBuilder.ToImmutable());
        }
Exemplo n.º 2
0
 protected BaseController(IServiceProvider serviceProvider)
 {
     contentCache = serviceProvider.GetRequiredService <IContentCache>();
     rolesCache   = serviceProvider.GetRequiredService <IRolesCache>();
     userManager  = serviceProvider.GetRequiredService <SunUserManager>();
     keyGenerator = serviceProvider.GetRequiredService <CacheKeyGenerator>();
 }
Exemplo n.º 3
0
        public SectionClientCached(Section section, Dictionary <string, Type> clientComponentTypes,
                                   IRolesCache rolesCache)
        {
            Id   = section.Id;
            Name = section.Name;
            Type = section.Type;
            if (section.Roles != null)
            {
                Roles = section.Roles.Split(',')
                        .Select(x => rolesCache.GetRole(x))
                        .ToDictionary(x => x.Id, x => x)
                        .ToImmutableDictionary();
            }
            else
            {
                Roles = new Dictionary <int, RoleCached>().ToImmutableDictionary();
            }

            if (clientComponentTypes.TryGetValue(Type, out Type type))
            {
                object clientData = JsonSerializer.Deserialize(section.Options, type);
                string clientJson = JsonSerializer.Serialize(clientData);
                Options = SunJson.MakeJElement(clientJson);
            }
        }
Exemplo n.º 4
0
 public MenuCache(
     IDataBaseFactory dataBaseFactory,
     IRolesCache rolesCache)
 {
     this.dataBaseFactory = dataBaseFactory;
     this.rolesCache      = rolesCache;
 }
Exemplo n.º 5
0
 public UserRolesAdminController(
     IUserRolesAdminPresenter userRolesAdminPresenter,
     JwtBlackListService jwtBlackListService,
     IRolesCache rolesCache,
     IServiceProvider serviceProvider) : base(serviceProvider)
 {
     this.userRolesAdminPresenter = userRolesAdminPresenter;
     this.jwtBlackListService     = jwtBlackListService;
 }
Exemplo n.º 6
0
 public SectionsCache(
     IDataBaseFactory dataBaseFactory,
     IRolesCache rolesCache,
     SectionTypes sectionTypes)
 {
     this.rolesCache      = rolesCache;
     this.dataBaseFactory = dataBaseFactory;
     this.sectionTypes    = sectionTypes;
     Initialize();
 }
Exemplo n.º 7
0
        public CategoriesPresenter(IRolesCache rolesCache,
                                   ICategoriesCache categoriesCache,
                                   IAuthorizationService authorizationService,
                                   OperationKeysContainer operationKeysContainer)
        {
            OperationKeys = operationKeysContainer;

            this.authorizationService = authorizationService;
            this.categoriesCache      = categoriesCache;
            this.rolesCache           = rolesCache;
        }
Exemplo n.º 8
0
 public JwtService(
     DataBaseConnection db,
     SunUserManager userManager,
     IRolesCache rolesCache,
     IOptions <JwtOptions> jwtOptions,
     ILoggerFactory loggerFactory) : base(db)
 {
     this.userManager = userManager;
     this.jwtOptions  = jwtOptions.Value;
     logger           = loggerFactory.CreateLogger <AccountController>();
     this.rolesCache  = rolesCache;
 }
        public SunClaimsPrincipal(ClaimsPrincipal user, IRolesCache rolesCache, long sessionId = 0, string longToken2Db = null) : base(user)
        {
            this.SessionId    = sessionId;
            this.LongToken2Db = longToken2Db;

            if (Identity.IsAuthenticated)
            {
                UserId = int.Parse(this.FindFirstValue(ClaimTypes.NameIdentifier));
            }

            Roles = GetUserRoles(rolesCache);
        }
Exemplo n.º 10
0
        public CategoriesPresenter(
            IRolesCache rolesCache,
            ICategoriesCache categoriesCache,
            IOptionsMonitor <GlobalOptions> globalOptions,
            IAuthorizationService authorizationService,
            OperationKeysContainer operationKeysContainer)
        {
            OperationKeys = operationKeysContainer;

            this.authorizationService = authorizationService;
            this.categoriesCache      = categoriesCache;
            this.rolesCache           = rolesCache;
            this.globalOptions        = globalOptions;
        }
Exemplo n.º 11
0
 public SunJweHandler(
     IOptionsMonitor <SunJweOptions> options,
     ILoggerFactory logger,
     UrlEncoder encoder,
     ISystemClock clock,
     IRolesCache rolesCache,
     JweService jweService,
     JweBlackListService jweBlackListService,
     SunUserManager userManager) : base(options, logger, encoder, clock)
 {
     this.rolesCache          = rolesCache;
     this.jweService          = jweService;
     this.userManager         = userManager;
     this.jweBlackListService = jweBlackListService;
 }
Exemplo n.º 12
0
 public JweService(
     DataBaseConnection db,
     SunUserManager userManager,
     IRolesCache rolesCache,
     ICryptService cryptService,
     IOptionsMonitor <SecurityOptions> securityOptions,
     IOptionsMonitor <UrlPathsOptions> urlsOptions,
     ILoggerFactory loggerFactory) : base(db)
 {
     this.userManager     = userManager;
     this.cryptService    = cryptService;
     this.urlsOptions     = urlsOptions;
     this.securityOptions = securityOptions;
     logger          = loggerFactory.CreateLogger <AccountController>();
     this.rolesCache = rolesCache;
 }
Exemplo n.º 13
0
 public JweService(
     DataBaseConnection db,
     SunUserManager userManager,
     IRolesCache rolesCache,
     ICryptService cryptService,
     IOptionsMonitor <JweOptions> jweOptions,
     IOptionsMonitor <GlobalOptions> globalOptions,
     ILoggerFactory loggerFactory) : base(db)
 {
     this.userManager   = userManager;
     this.cryptService  = cryptService;
     this.globalOptions = globalOptions;
     this.jweOptions    = jweOptions;
     logger             = loggerFactory.CreateLogger <AccountController>();
     this.rolesCache    = rolesCache;
 }
Exemplo n.º 14
0
        public SectionServerCached(Section section, Type serverSectionType, IRolesCache rolesCache)
        {
            Id          = section.Id;
            Name        = section.Name;
            IsCacheData = section.IsCacheData;
            if (section.Roles != null)
            {
                Roles = section.Roles.Split(',')
                        .Select(x => rolesCache.GetRole(x))
                        .ToDictionary(x => x.Id, x => x)
                        .ToImmutableDictionary();
            }
            else
            {
                Roles = new Dictionary <int, RoleCached>().ToImmutableDictionary();
            }

            Data = JsonSerializer.Deserialize(section.Options, serverSectionType);
        }
 public ComponentsAdminManager(
     IRolesCache rolesCache,
     DataBaseConnection db) : base(db)
 {
     this.rolesCache = rolesCache;
 }
Exemplo n.º 16
0
 public ProfilePresenter(DataBaseConnection db, IRolesCache rolesCache) : base(db)
 {
     this.RolesCache = rolesCache;
 }
Exemplo n.º 17
0
 public ComponentsCache(IDataBaseFactory dataBaseFactory, IRolesCache rolesCache)
 {
     this.rolesCache      = rolesCache;
     this.dataBaseFactory = dataBaseFactory;
 }
Exemplo n.º 18
0
 public MenuAdminManager(IRolesCache rolesCache, DataBaseConnection db) : base(db)
 {
     this.rolesCache = rolesCache;
 }
Exemplo n.º 19
0
        public SectionServerCached(Section section, Dictionary <string, Type> serverTypes, IRolesCache rolesCache)
        {
            Id          = section.Id;
            Name        = section.Name;
            IsCacheData = section.IsCacheData;
            if (section.Roles != null)
            {
                Roles = section.Roles.Split(',')
                        .Select(x => rolesCache.GetRole(x))
                        .ToDictionary(x => x.Id, x => x)
                        .ToImmutableDictionary();
            }
            else
            {
                Roles = new Dictionary <int, RoleCached>().ToImmutableDictionary();
            }

            if (!serverTypes.TryGetValue(section.Type, out Type type))
            {
                throw new SunException("No component type found: " + section.Type);
            }

            Data = JsonSerializer.Deserialize(section.Options, type);
        }