public async Task Invoke(HttpContext context)
        {
            _logger.LogInformation("Handling authorization in resource: " + context.Request.Path);
            var principal = _authenticate.AuthenticateRequest(context);

            if (principal == null)
            {
                _logger.LogInformation("The client doesn't have enough privileges.");
                return;
            }

            //context.Session.SetString("principalId", principal.PrincipalURL);
            _logger.LogInformation($"Authorization granted for principal: {principal.PrincipalStringIdentifier}");
            await _next.Invoke(context);

            _logger.LogInformation("Finished handling request.");
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Call the method to perform a PROFIND over a
        ///     principal.
        ///     Initially the client could do a PROFIND over
        ///     the server to discover all the user calendars
        ///     or could PORFIND directly over a calendar URL.
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns>The request</returns>
        public async Task Profind(HttpContext httpContext)
        {
            var requestPath  = httpContext.Request.Path;
            var streamReader = new StreamReader(httpContext.Request.Body);
            //read the body of the request
            var bodyString = streamReader.ReadToEnd();

            //try to authenticate the request either with the cookies or the user credentials
            var principal = _authenticate.AuthenticateRequest(httpContext);

            //if the principal is null then there is some problem with the authentication
            //so return
            //if (principal == null)
            //    return;

            var body = XmlTreeStructure.Parse(bodyString);

            //take the requested properties
            var reqProperties = ExtractPropertiesNameMainNS(body);

            await BuildResponse(httpContext.Response, requestPath, reqProperties, principal);
        }