private async Task AuthorizeAndPush(CloudEvent cloudEvent, Subscription subscription)
 {
     if (await _authorizationHelper.AuthorizeConsumerForAltinnAppEvent(cloudEvent, subscription.Consumer))
     {
         CloudEventEnvelope cloudEventEnvelope = MapToEnvelope(cloudEvent, subscription);
         await _eventsService.PushToConsumer(cloudEventEnvelope);
     }
 }
        private async Task <bool> AuthorizeConsumerForAltinnAppEvent(CloudEvent cloudEvent, string consumer)
        {
            string cacheKey = GetAltinnAppAuthorizationCacheKey(GetSourceFilter(cloudEvent.Source), consumer);

            bool isAuthorized;

            if (!_memoryCache.TryGetValue(cacheKey, out isAuthorized))
            {
                isAuthorized = await _authorizationHelper.AuthorizeConsumerForAltinnAppEvent(cloudEvent, consumer);

                _memoryCache.Set(cacheKey, isAuthorized, _orgAuthorizationEntryOptions);
            }

            return(isAuthorized);
        }
Beispiel #3
0
        public async Task AuthorizeOrgAccessToEventForUserNotAuthorized()
        {
            PepWithPDPAuthorizationMockSI pdp         = new PepWithPDPAuthorizationMockSI();
            AuthorizationHelper           authzHelper = new AuthorizationHelper(pdp);

            CloudEvent cloudEvent = new CloudEvent()
            {
                Source  = new Uri("https://skd.apps.altinn.no/ttd/endring-av-navn-v2/instances/1337/6fb3f738-6800-4f29-9f3e-1c66862656cd"),
                Subject = "/party/1337"
            };

            // Act
            bool result = await authzHelper.AuthorizeConsumerForAltinnAppEvent(cloudEvent, "/org/nav");

            // Assert.
            Assert.False(result);
        }