public AuditLoggingFilterAttribute(
            IAuditLogger auditLogger,
            IFhirRequestContextAccessor fhirRequestContextAccessor,
            IClaimsIndexer claimsIndexer)
        {
            EnsureArg.IsNotNull(auditLogger, nameof(auditLogger));
            EnsureArg.IsNotNull(fhirRequestContextAccessor, nameof(fhirRequestContextAccessor));
            EnsureArg.IsNotNull(claimsIndexer, nameof(claimsIndexer));

            _auditLogger = auditLogger;
            _fhirRequestContextAccessor = fhirRequestContextAccessor;
            _claimsIndexer = claimsIndexer;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceWrapperWithSearchIndicesFactory"/> class.
        /// </summary>
        /// <param name="rawResourceFactory">The raw resource factory.</param>
        /// <param name="fhirRequestContextAccessor">The FHIR request context accessor.</param>
        /// <param name="searchIndexer">The search indexer used to generate search indices.</param>
        /// <param name="claimsIndexer">The claims indexer used to generate claims indices.</param>
        /// <param name="compartmentIndexer">The compartment indexer.</param>
        public ResourceWrapperWithSearchIndicesFactory(IRawResourceFactory rawResourceFactory, IFhirRequestContextAccessor fhirRequestContextAccessor, ISearchIndexer searchIndexer, IClaimsIndexer claimsIndexer, ICompartmentIndexer compartmentIndexer)
        {
            EnsureArg.IsNotNull(rawResourceFactory, nameof(rawResourceFactory));
            EnsureArg.IsNotNull(searchIndexer, nameof(searchIndexer));
            EnsureArg.IsNotNull(fhirRequestContextAccessor, nameof(fhirRequestContextAccessor));
            EnsureArg.IsNotNull(claimsIndexer, nameof(claimsIndexer));
            EnsureArg.IsNotNull(compartmentIndexer, nameof(compartmentIndexer));

            _rawResourceFactory         = rawResourceFactory;
            _searchIndexer              = searchIndexer;
            _fhirRequestContextAccessor = fhirRequestContextAccessor;
            _claimsIndexer              = claimsIndexer;
            _compartmentIndexer         = compartmentIndexer;
        }
        public AuditLoggingFilterTests()
        {
            _fhirResult = new FhirResult(new Patient()
            {
                Name = { new HumanName()
                         {
                             Text = "TestPatient"
                         } }
            });

            _executedContext = new ResultExecutedContext(
                new ActionContext(new DefaultHttpContext(), new RouteData(), new ControllerActionDescriptor()
            {
                DisplayName = "Executed Context Test Descriptor"
            }),
                new List <IFilterMetadata>(),
                _fhirResult,
                FilterTestsHelper.CreateMockFhirController());

            _executedContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.Created;
            _fhirResult.StatusCode = HttpStatusCode.Created;
            _fhirRequestContext.RequestType.Returns(new Coding("System", "TestRequestType"));
            _fhirRequestContext.RequestSubType = new Coding("System", "TestRequestSubType");
            _fhirRequestContext.Uri.Returns(new Uri("https://fhirtest/fhir?count=100"));
            _fhirRequestContextAccessor.FhirRequestContext.Returns(_fhirRequestContext);
            _fhirRequestContextAccessor.FhirRequestContext.Principal.Returns(_claimsPrincipal);

            _securityConfiguration.LastModifiedClaims.Returns(new HashSet <string> {
                "claim1"
            });
            _securityOptions.Value.Returns(_securityConfiguration);
            _claimsPrincipal.Claims.Returns(new List <System.Security.Claims.Claim> {
                Claim1
            });

            _claims = new KeyValuePair <string, string>[]
            {
                KeyValuePair.Create("claim", "value"),
            };

            _claimsIndexer = Substitute.For <IClaimsIndexer>();

            _claimsIndexer.Extract().Returns(_claims);

            _filter = new AuditLoggingFilterAttribute(
                _auditLogger,
                _fhirRequestContextAccessor,
                _claimsIndexer);
        }