예제 #1
0
        private async Task EnrichSubjectAttributes(XacmlContextRequest request, string resourceParty)
        {
            // If there is no resource party then it is impossible to enrich roles
            if (string.IsNullOrEmpty(resourceParty))
            {
                return;
            }

            XacmlContextAttributes subjectContextAttributes = request.GetSubjectAttributes();

            int subjectUserId   = 0;
            int resourcePartyId = Convert.ToInt32(resourceParty);

            foreach (XacmlAttribute xacmlAttribute in subjectContextAttributes.Attributes)
            {
                if (xacmlAttribute.AttributeId.OriginalString.Equals(XacmlRequestAttribute.UserAttribute))
                {
                    subjectUserId = Convert.ToInt32(xacmlAttribute.AttributeValues.First().Value);
                }
            }

            if (subjectUserId == 0)
            {
                return;
            }

            List <Role> roleList = await _rolesWrapper.GetDecisionPointRolesForUser(subjectUserId, resourcePartyId) ?? new List <Role>();

            subjectContextAttributes.Attributes.Add(GetRoleAttribute(roleList));
        }
예제 #2
0
        private async Task <List <Role> > GetRoles(int subjectUserId, int resourcePartyId)
        {
            string cacheKey = GetCacheKey(subjectUserId, resourcePartyId);

            if (!_memoryCache.TryGetValue(cacheKey, out List <Role> roles))
            {
                // Key not in cache, so get data.
                roles = await _rolesWrapper.GetDecisionPointRolesForUser(subjectUserId, resourcePartyId) ?? new List <Role>();

                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetPriority(CacheItemPriority.High)
                                        .SetAbsoluteExpiration(new TimeSpan(0, _generalSettings.RoleCacheTimeout, 0));

                _memoryCache.Set(cacheKey, roles, cacheEntryOptions);
            }

            return(roles);
        }
예제 #3
0
        public async Task <ActionResult> Get(int coveredByUserId, int offeredByPartyId)
        {
            if (coveredByUserId == 0 || offeredByPartyId == 0)
            {
                return(BadRequest());
            }

            List <Role> roleList = await _rolesWrapper.GetDecisionPointRolesForUser(coveredByUserId, offeredByPartyId);

            if (roleList == null || roleList.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(roleList));
        }