protected override async Task <AuthenticateResult> HandleAuthenticateAsync()
        {
            string authorization = Request.Headers[HeaderNames.Authorization];

            if (string.IsNullOrEmpty(authorization))
            {
                return(AuthenticateResult.Fail("Authentication not provided."));
            }

            ClaimsPrincipal principal = null;

            if (!_simpleMemoryCache.IsExist(authorization))
            {
                var alfrescoProfile = await _alfrescoHttpClient.GetPerson("-me-");

                if (alfrescoProfile?.Entry?.Id != null)
                {
                    principal = _mapper.Map <ClaimsPrincipal>((alfrescoProfile, authorization));
                }

                if (principal?.Claims == null)
                {
                    return(AuthenticateResult.Fail("Authentication not provided."));
                }

                lock (Sync)
                {
                    if (!_simpleMemoryCache.IsExist(authorization))
                    {
                        _simpleMemoryCache.Create(authorization, principal, new MemoryCacheEntryOptions
                        {
                            SlidingExpiration = TimeSpan.FromMinutes(_alfrescoConfiguration.TokenExpire ?? 30),
                            Priority          = CacheItemPriority.High
                        });
                    }
                }
            }
            else
            {
                principal = _simpleMemoryCache.Get <ClaimsPrincipal>(authorization);
            }

            return(AuthenticateResult.Success(new AuthenticationTicket(principal, new AuthenticationProperties
            {
                AllowRefresh = false,
                IsPersistent = true
            }, "Alfresco Scheme")));
        }
示例#2
0
        public async Task <List <PathsModel> > GetAllPaths()
        {
            if (_simpleMemoryCache.IsExist(_cacheKey))
            {
                return(_simpleMemoryCache.Get <List <PathsModel> >(_cacheKey));
            }

            var paths = await FindAllPaths();

            _simpleMemoryCache.Create(_cacheKey, paths, new MemoryCacheEntryOptions {
                Priority = CacheItemPriority.NeverRemove
            });
            return(paths);
        }
        public async Task <bool> HandleNotAuthenticated()
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(new Uri(_alfrescoConfiguration.Url), "alfresco/api/-default-/public/authentication/versions/1/tickets"));

            webRequest.Method      = "POST";
            webRequest.ContentType = MediaTypeNames.Application.Json;

            try
            {
                await CreateRequestBody(webRequest);

                HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();

                if (response?.StatusCode != HttpStatusCode.Created)
                {
                    return(false);
                }

                var responseModel = CreateResponse(response);

                if (responseModel?.Entry?.Id == null)
                {
                    return(false);
                }


                if (_simpleMemoryCache.IsExist(nameof(AdminAuthentification)))
                {
                    _simpleMemoryCache.Delete(nameof(AdminAuthentification));
                }

                _simpleMemoryCache.Create(
                    nameof(AdminAuthentification),
                    $"Basic {responseModel.Entry.Id.ToAlfrescoAuthentication()}",
                    new MemoryCacheEntryOptions
                {
                    SlidingExpiration = TimeSpan.FromMinutes(_alfrescoConfiguration.TokenExpire ?? 30)
                });

                return(true);
            }
            catch (Exception e)
            {
                Log.Error(e, "HandleNotAuthenticated");
                return(false);
            }
        }
        public async Task <List <SignerStatus> > Status([FromQuery] SignerGetStatus signerStatus)
        {
            var componentValidator = new ComponentValidator(_alfrescoHttpClient);
            await signerStatus.ComponentId.ForEachAsync(async x =>
            {
                var component = x.Split('_');
                if (component.Length != 2)
                {
                    throw new BadRequestException($"Component {x} is not in form 'guid_componentId'");
                }

                //await componentValidator.ValidateAsync(new DocumentProperties(component[1]));
            });

            return((from component in signerStatus.ComponentId
                    where _simpleMemoryCache.IsExist($"{SignerStatus}{component}")
                    select new SignerStatus {
                Id = component.Split('_')[0], Component = component.Split('_')[1], Status = _simpleMemoryCache.Get <string>($"{SignerStatus}{component}")
            }).ToList());
        }
示例#5
0
        public async Task <List <CodeListModel> > GetAllListsOfValues()
        {
            if (_simpleMemoryCache.IsExist(_cacheKey))
            {
                return(_simpleMemoryCache.Get <List <CodeListModel> >(_cacheKey));
            }

            var codeLists = new List <CodeListModel>();

            var alfrescoResponse = await _alfrescoHttpClient.CodeListGetAll();

            foreach (var list in alfrescoResponse.CodeLists.Where(x => x.Name != "rmc_smList"))
            {
                codeLists.Add(await GetListValues(list.Name));
            }

            _simpleMemoryCache.Create(_cacheKey, codeLists);

            return(codeLists);
        }