From 0b68fb2bd06f775ac86037c3a89858833d87c11e Mon Sep 17 00:00:00 2001 From: Guillaume Duval Date: Mon, 16 Dec 2024 14:59:45 +0100 Subject: [PATCH] [RHCLOUD-36917] Debug/Update recipients authorization criterion management --- .../email/EmailCloudEventDataExtractor.java | 2 +- .../email/constants/ExchangeProperty.java | 2 +- .../recipients/RecipientsQuery.java | 2 +- .../RecipientsResolverRequestPreparer.java | 4 +- .../ExternalAuthorizationCriterion.java | 83 ------------- ...ientsAuthorizationCriterionExtractor.java} | 17 +-- .../drawer/DrawerNotificationToConnector.java | 6 +- .../processors/drawer/DrawerProcessor.java | 6 +- .../processors/email/EmailAggregator.java | 10 +- .../processors/email/EmailProcessor.java | 6 +- .../connector/dto/EmailNotification.java | 6 +- .../ExternalRecipientsResolver.java | 6 +- .../pojo/RecipientsQuery.java | 4 +- .../transformers/BaseTransformer.java | 4 + ...nalAuthorizationCriteriaExtractorTest.java | 116 ------------------ .../drawer/DrawerProcessorTest.java | 4 +- recipients-resolver/pom.xml | 7 ++ .../model/ExternalAuthorizationCriterion.java | 83 ------------- .../resolver/RecipientsResolver.java | 16 +-- .../resolver/kessel/KesselService.java | 16 +-- .../rest/RecipientsResolverResource.java | 2 +- .../recipients/rest/pojo/RecipientsQuery.java | 4 +- .../resolver/RecipientsResolverTest.java | 14 ++- 23 files changed, 78 insertions(+), 342 deletions(-) delete mode 100644 engine/src/main/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriterion.java rename engine/src/main/java/com/redhat/cloud/notifications/processors/{ExternalAuthorizationCriterionExtractor.java => RecipientsAuthorizationCriterionExtractor.java} (58%) delete mode 100644 engine/src/test/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriteriaExtractorTest.java delete mode 100644 recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/model/ExternalAuthorizationCriterion.java diff --git a/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/EmailCloudEventDataExtractor.java b/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/EmailCloudEventDataExtractor.java index 630928fd8e..d7c5bbef69 100644 --- a/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/EmailCloudEventDataExtractor.java +++ b/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/EmailCloudEventDataExtractor.java @@ -59,7 +59,7 @@ public void extract(final Exchange exchange, final JsonObject cloudEventData) { exchange.setProperty(ExchangeProperty.SUBSCRIBED_BY_DEFAULT, cloudEventData.getBoolean("subscribed_by_default")); exchange.setProperty(ExchangeProperty.SUBSCRIBERS, subscribers); exchange.setProperty(ExchangeProperty.UNSUBSCRIBERS, unsubscribers); - exchange.setProperty(ExchangeProperty.AUTHORIZATION_CRITERIA, recipientsAuthorizationCriterion); + exchange.setProperty(ExchangeProperty.RECIPIENTS_AUTHORIZATION_CRITERION, recipientsAuthorizationCriterion); exchange.setProperty(ExchangeProperty.EMAIL_RECIPIENTS, emails); exchange.setProperty(ExchangeProperty.EMAIL_SENDER, cloudEventData.getString("email_sender")); diff --git a/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/constants/ExchangeProperty.java b/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/constants/ExchangeProperty.java index e705bb29ab..edc6cafad4 100644 --- a/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/constants/ExchangeProperty.java +++ b/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/constants/ExchangeProperty.java @@ -49,5 +49,5 @@ public class ExchangeProperty { public static final String USE_EMAIL_BOP_V1_SSL = "use_email_bop_V1_ssl"; - public static final String AUTHORIZATION_CRITERIA = "authorization_criteria"; + public static final String RECIPIENTS_AUTHORIZATION_CRITERION = "recipients_authorization_criterion"; } diff --git a/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/processors/recipients/RecipientsQuery.java b/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/processors/recipients/RecipientsQuery.java index 60c6ccf02d..7e2e3d114a 100644 --- a/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/processors/recipients/RecipientsQuery.java +++ b/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/processors/recipients/RecipientsQuery.java @@ -24,5 +24,5 @@ public class RecipientsQuery { public boolean subscribedByDefault; - public JsonObject authorizationCriteria; + public JsonObject recipientsAuthorizationCriterion; } diff --git a/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/processors/recipients/RecipientsResolverRequestPreparer.java b/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/processors/recipients/RecipientsResolverRequestPreparer.java index 966c678343..146c7ce25d 100644 --- a/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/processors/recipients/RecipientsResolverRequestPreparer.java +++ b/connector-email/src/main/java/com/redhat/cloud/notifications/connector/email/processors/recipients/RecipientsResolverRequestPreparer.java @@ -26,7 +26,7 @@ public void process(final Exchange exchange) throws JsonProcessingException { List recipientSettings = exchange.getProperty(ExchangeProperty.RECIPIENT_SETTINGS, List.class); Set subscribers = exchange.getProperty(ExchangeProperty.SUBSCRIBERS, Set.class); Set unsubscribers = exchange.getProperty(ExchangeProperty.UNSUBSCRIBERS, Set.class); - JsonObject authorizationCriteria = exchange.getProperty(ExchangeProperty.AUTHORIZATION_CRITERIA, JsonObject.class); + JsonObject recipientsAuthorizationCriterion = exchange.getProperty(ExchangeProperty.RECIPIENTS_AUTHORIZATION_CRITERION, JsonObject.class); boolean subscribedByDefault = exchange.getProperty(ExchangeProperty.SUBSCRIBED_BY_DEFAULT, boolean.class); final String orgId = exchange.getProperty(ORG_ID, String.class); @@ -37,7 +37,7 @@ public void process(final Exchange exchange) throws JsonProcessingException { recipientsQuery.orgId = orgId; recipientsQuery.recipientSettings = Set.copyOf(recipientSettings); recipientsQuery.subscribedByDefault = subscribedByDefault; - recipientsQuery.authorizationCriteria = authorizationCriteria; + recipientsQuery.recipientsAuthorizationCriterion = recipientsAuthorizationCriterion; // Serialize the payload. exchange.getMessage().setBody(objectMapper.writeValueAsString(recipientsQuery)); diff --git a/engine/src/main/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriterion.java b/engine/src/main/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriterion.java deleted file mode 100644 index 28c60e9b6f..0000000000 --- a/engine/src/main/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriterion.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.redhat.cloud.notifications.processors; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import jakarta.validation.constraints.NotNull; -import java.util.Objects; - -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) -@JsonIgnoreProperties(ignoreUnknown = true) -public class ExternalAuthorizationCriterion { - - @NotNull - private Type type; - - @NotNull - private String id; - - @NotNull - private String relation; - - public ExternalAuthorizationCriterion(Type type, String id, String relation) { - this.type = type; - this.id = id; - this.relation = relation; - } - - public @NotNull Type getType() { - return type; - } - - public @NotNull String getId() { - return id; - } - - public @NotNull String getRelation() { - return relation; - } - - public static class Type { - public String name; - public String namespace; - - public Type(String name, String namespace) { - this.name = name; - this.namespace = namespace; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Type type = (Type) o; - return Objects.equals(name, type.name) && Objects.equals(namespace, type.namespace); - } - - @Override - public int hashCode() { - return Objects.hash(name, namespace); - } - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ExternalAuthorizationCriterion that = (ExternalAuthorizationCriterion) o; - return Objects.equals(type, that.type) && Objects.equals(id, that.id) && Objects.equals(relation, that.relation); - } - - @Override - public int hashCode() { - return Objects.hash(type.hashCode(), id, relation); - } -} diff --git a/engine/src/main/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriterionExtractor.java b/engine/src/main/java/com/redhat/cloud/notifications/processors/RecipientsAuthorizationCriterionExtractor.java similarity index 58% rename from engine/src/main/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriterionExtractor.java rename to engine/src/main/java/com/redhat/cloud/notifications/processors/RecipientsAuthorizationCriterionExtractor.java index dd1e0838f5..cc7d702808 100644 --- a/engine/src/main/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriterionExtractor.java +++ b/engine/src/main/java/com/redhat/cloud/notifications/processors/RecipientsAuthorizationCriterionExtractor.java @@ -1,6 +1,7 @@ package com.redhat.cloud.notifications.processors; import com.fasterxml.jackson.databind.ObjectMapper; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; import com.redhat.cloud.notifications.models.EmailAggregation; import com.redhat.cloud.notifications.models.Event; import com.redhat.cloud.notifications.transformers.BaseTransformer; @@ -9,10 +10,10 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -@ApplicationScoped -public class ExternalAuthorizationCriterionExtractor { +import static com.redhat.cloud.notifications.transformers.BaseTransformer.RECIPIENTS_AUTHORIZATION_CRITERION; - public static final String EXTERNAL_AUTHORIZATION_CRITERIA = "recipients_authorization_criterion"; +@ApplicationScoped +public class RecipientsAuthorizationCriterionExtractor { @Inject BaseTransformer baseTransformer; @@ -20,18 +21,18 @@ public class ExternalAuthorizationCriterionExtractor { @Inject ObjectMapper objectMapper; - public ExternalAuthorizationCriterion extract(Event event) { + public RecipientsAuthorizationCriterion extract(Event event) { return extract(baseTransformer.toJsonObject(event)); } - public ExternalAuthorizationCriterion extract(EmailAggregation emailAggregation) { + public RecipientsAuthorizationCriterion extract(EmailAggregation emailAggregation) { return extract(emailAggregation.getPayload()); } - private ExternalAuthorizationCriterion extract(JsonObject data) { - if (null != data.getJsonObject(BaseTransformer.CONTEXT) && null != data.getJsonObject(BaseTransformer.CONTEXT).getJsonObject(EXTERNAL_AUTHORIZATION_CRITERIA)) { + private RecipientsAuthorizationCriterion extract(JsonObject data) { + if (null != data.getJsonObject(RECIPIENTS_AUTHORIZATION_CRITERION)) { try { - return objectMapper.convertValue(data.getJsonObject(BaseTransformer.CONTEXT).getJsonObject(EXTERNAL_AUTHORIZATION_CRITERIA), ExternalAuthorizationCriterion.class); + return objectMapper.convertValue(data.getJsonObject(RECIPIENTS_AUTHORIZATION_CRITERION), RecipientsAuthorizationCriterion.class); } catch (IllegalArgumentException e) { Log.error("Error parsing authorization criteria", e); } diff --git a/engine/src/main/java/com/redhat/cloud/notifications/processors/drawer/DrawerNotificationToConnector.java b/engine/src/main/java/com/redhat/cloud/notifications/processors/drawer/DrawerNotificationToConnector.java index 939b809f49..c9baeddabc 100644 --- a/engine/src/main/java/com/redhat/cloud/notifications/processors/drawer/DrawerNotificationToConnector.java +++ b/engine/src/main/java/com/redhat/cloud/notifications/processors/drawer/DrawerNotificationToConnector.java @@ -1,8 +1,8 @@ package com.redhat.cloud.notifications.processors.drawer; import com.fasterxml.jackson.annotation.JsonProperty; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; import com.redhat.cloud.notifications.models.DrawerEntryPayload; -import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriterion; import com.redhat.cloud.notifications.processors.email.connector.dto.RecipientSettings; import java.util.Collection; @@ -20,6 +20,6 @@ public record DrawerNotificationToConnector( @JsonProperty("unsubscribers") Collection unsubscribers, - @JsonProperty("authorization_criteria") - ExternalAuthorizationCriterion externalAuthorizationCriteria + @JsonProperty("recipients_authorization_criterion") + RecipientsAuthorizationCriterion recipientsAuthorizationCriterion ) { } diff --git a/engine/src/main/java/com/redhat/cloud/notifications/processors/drawer/DrawerProcessor.java b/engine/src/main/java/com/redhat/cloud/notifications/processors/drawer/DrawerProcessor.java index 681042edd1..3fb766932f 100644 --- a/engine/src/main/java/com/redhat/cloud/notifications/processors/drawer/DrawerProcessor.java +++ b/engine/src/main/java/com/redhat/cloud/notifications/processors/drawer/DrawerProcessor.java @@ -14,7 +14,7 @@ import com.redhat.cloud.notifications.models.Event; import com.redhat.cloud.notifications.models.IntegrationTemplate; import com.redhat.cloud.notifications.processors.ConnectorSender; -import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriterionExtractor; +import com.redhat.cloud.notifications.processors.RecipientsAuthorizationCriterionExtractor; import com.redhat.cloud.notifications.processors.SystemEndpointTypeProcessor; import com.redhat.cloud.notifications.processors.email.connector.dto.RecipientSettings; import com.redhat.cloud.notifications.templates.TemplateService; @@ -70,7 +70,7 @@ public class DrawerProcessor extends SystemEndpointTypeProcessor { BundleRepository bundleRepository; @Inject - ExternalAuthorizationCriterionExtractor externalAuthorizationCriteriaExtractor; + RecipientsAuthorizationCriterionExtractor recipientsAuthorizationCriterionExtractor; @Override public void process(Event event, List endpoints) { @@ -101,7 +101,7 @@ public void process(Event event, List endpoints) { drawerEntryPayload, recipientSettings, unsubscribers, - externalAuthorizationCriteriaExtractor.extract(event) + recipientsAuthorizationCriterionExtractor.extract(event) ); connectorSender.send(event, endpoints.getFirst(), JsonObject.mapFrom(drawerNotificationToConnector)); diff --git a/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailAggregator.java b/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailAggregator.java index 33dd34efea..4cd2dda647 100644 --- a/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailAggregator.java +++ b/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailAggregator.java @@ -12,6 +12,7 @@ import com.redhat.cloud.notifications.events.EventWrapperCloudEvent; import com.redhat.cloud.notifications.ingress.Action; import com.redhat.cloud.notifications.ingress.Recipient; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; import com.redhat.cloud.notifications.models.EmailAggregation; import com.redhat.cloud.notifications.models.EmailAggregationKey; import com.redhat.cloud.notifications.models.Endpoint; @@ -20,8 +21,7 @@ import com.redhat.cloud.notifications.models.EventType; import com.redhat.cloud.notifications.models.NotificationsConsoleCloudEvent; import com.redhat.cloud.notifications.models.SubscriptionType; -import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriterion; -import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriterionExtractor; +import com.redhat.cloud.notifications.processors.RecipientsAuthorizationCriterionExtractor; import com.redhat.cloud.notifications.processors.email.aggregators.AbstractEmailPayloadAggregator; import com.redhat.cloud.notifications.processors.email.aggregators.EmailPayloadAggregatorFactory; import com.redhat.cloud.notifications.recipients.User; @@ -82,7 +82,7 @@ public class EmailAggregator { private static final String RECIPIENTS_KEY = "recipients"; @Inject - ExternalAuthorizationCriterionExtractor externalAuthorizationCriteriaExtractor; + RecipientsAuthorizationCriterionExtractor recipientsAuthorizationCriterionExtractor; @ConfigProperty(name = "notifications.aggregation.max-page-size", defaultValue = "100") int maxPageSize; @@ -147,7 +147,7 @@ private void aggregationBasedOnEmailAggregation(EmailAggregationKey aggregationK Set subscribers = subscribersByEventType.getOrDefault(eventType.getName(), Collections.emptySet()); Set unsubscribers = unsubscribersByEventType.getOrDefault(eventType.getName(), Collections.emptySet()); - ExternalAuthorizationCriterion externalAuthorizationCriteria = externalAuthorizationCriteriaExtractor.extract(aggregation); + RecipientsAuthorizationCriterion externalAuthorizationCriteria = recipientsAuthorizationCriterionExtractor.extract(aggregation); Set recipients = externalRecipientsResolver.recipientUsers( aggregationKey.getOrgId(), @@ -209,7 +209,7 @@ private void aggregationBasedOnEvent(EventAggregationCriteria eventAggregationCr Set subscribers = subscribersByEventType.getOrDefault(eventType.getName(), Collections.emptySet()); Set unsubscribers = unsubscribersByEventType.getOrDefault(eventType.getName(), Collections.emptySet()); aggregation.setEventWrapper(getEventWrapper(aggregation.getPayload())); - ExternalAuthorizationCriterion externalAuthorizationCriterion = externalAuthorizationCriteriaExtractor.extract(aggregation); + RecipientsAuthorizationCriterion externalAuthorizationCriterion = recipientsAuthorizationCriterionExtractor.extract(aggregation); Log.info("Start calling external resolver service "); Set recipients = externalRecipientsResolver.recipientUsers( diff --git a/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailProcessor.java b/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailProcessor.java index 901faff94f..540e982c82 100644 --- a/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailProcessor.java +++ b/engine/src/main/java/com/redhat/cloud/notifications/processors/email/EmailProcessor.java @@ -7,7 +7,7 @@ import com.redhat.cloud.notifications.models.Event; import com.redhat.cloud.notifications.models.InstantEmailTemplate; import com.redhat.cloud.notifications.processors.ConnectorSender; -import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriterionExtractor; +import com.redhat.cloud.notifications.processors.RecipientsAuthorizationCriterionExtractor; import com.redhat.cloud.notifications.processors.SystemEndpointTypeProcessor; import com.redhat.cloud.notifications.processors.email.connector.dto.EmailNotification; import com.redhat.cloud.notifications.processors.email.connector.dto.RecipientSettings; @@ -53,7 +53,7 @@ public class EmailProcessor extends SystemEndpointTypeProcessor { SubscriptionRepository subscriptionRepository; @Inject - ExternalAuthorizationCriterionExtractor externalAuthorizationCriteriaExtractor; + RecipientsAuthorizationCriterionExtractor recipientsAuthorizationCriterionExtractor; @Override public void process(final Event event, final List endpoints) { @@ -123,7 +123,7 @@ public void process(final Event event, final List endpoints, final boo subscribers, unsubscribers, event.getEventType().isSubscribedByDefault(), - externalAuthorizationCriteriaExtractor.extract(event) + recipientsAuthorizationCriterionExtractor.extract(event) ); Log.debugf("[org_id: %s] Sending email notification to connector", emailNotification); diff --git a/engine/src/main/java/com/redhat/cloud/notifications/processors/email/connector/dto/EmailNotification.java b/engine/src/main/java/com/redhat/cloud/notifications/processors/email/connector/dto/EmailNotification.java index dad975a3fb..f5ba02d630 100644 --- a/engine/src/main/java/com/redhat/cloud/notifications/processors/email/connector/dto/EmailNotification.java +++ b/engine/src/main/java/com/redhat/cloud/notifications/processors/email/connector/dto/EmailNotification.java @@ -1,7 +1,7 @@ package com.redhat.cloud.notifications.processors.email.connector.dto; import com.fasterxml.jackson.annotation.JsonProperty; -import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriterion; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; import java.util.Collection; /** @@ -21,7 +21,7 @@ * event type. * @param subscribedByDefault true if the event type is subscribed by * default. - * @param externalAuthorizationCriteria forward received authorization criteria. + * @param recipientsAuthorizationCriterion forward received authorization criterion. * */ public record EmailNotification( @@ -33,5 +33,5 @@ public record EmailNotification( @JsonProperty("subscribers") Collection subscribers, @JsonProperty("unsubscribers") Collection unsubscribers, @JsonProperty("subscribed_by_default") boolean subscribedByDefault, - @JsonProperty("external_authorization_criterion") ExternalAuthorizationCriterion externalAuthorizationCriteria + @JsonProperty("recipients_authorization_criterion") RecipientsAuthorizationCriterion recipientsAuthorizationCriterion ) { } diff --git a/engine/src/main/java/com/redhat/cloud/notifications/recipients/recipientsresolver/ExternalRecipientsResolver.java b/engine/src/main/java/com/redhat/cloud/notifications/recipients/recipientsresolver/ExternalRecipientsResolver.java index 487bad1c39..87273ee4c8 100644 --- a/engine/src/main/java/com/redhat/cloud/notifications/recipients/recipientsresolver/ExternalRecipientsResolver.java +++ b/engine/src/main/java/com/redhat/cloud/notifications/recipients/recipientsresolver/ExternalRecipientsResolver.java @@ -1,6 +1,6 @@ package com.redhat.cloud.notifications.recipients.recipientsresolver; -import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriterion; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; import com.redhat.cloud.notifications.recipients.RecipientSettings; import com.redhat.cloud.notifications.recipients.User; import com.redhat.cloud.notifications.recipients.recipientsresolver.pojo.RecipientsQuery; @@ -59,7 +59,7 @@ private T retryOnError(final CheckedSupplier usersServiceCall) { } @CacheResult(cacheName = "recipients-resolver-results") - public Set recipientUsers(String orgId, Set recipientSettings, Set subscribers, Set unsubscribers, boolean subscribedByDefault, ExternalAuthorizationCriterion externalAuthorizationCriteria) { + public Set recipientUsers(String orgId, Set recipientSettings, Set subscribers, Set unsubscribers, boolean subscribedByDefault, RecipientsAuthorizationCriterion recipientsAuthorizationCriterion) { RecipientsQuery recipientsQuery = new RecipientsQuery(); recipientsQuery.subscribers = Set.copyOf(subscribers); recipientsQuery.unsubscribers = Set.copyOf(unsubscribers); @@ -71,7 +71,7 @@ public Set recipientUsers(String orgId, Set recipientSe recipientsQuery.recipientSettings = recipientSettingsSet; recipientsQuery.subscribedByDefault = subscribedByDefault; - recipientsQuery.externalAuthorizationCriteria = externalAuthorizationCriteria; + recipientsQuery.recipientsAuthorizationCriterion = recipientsAuthorizationCriterion; Set recipientsList = retryOnError(() -> recipientsResolverService.getRecipients(recipientsQuery)); return recipientsList; } diff --git a/engine/src/main/java/com/redhat/cloud/notifications/recipients/recipientsresolver/pojo/RecipientsQuery.java b/engine/src/main/java/com/redhat/cloud/notifications/recipients/recipientsresolver/pojo/RecipientsQuery.java index 0ae0234efd..032eb7e8c2 100644 --- a/engine/src/main/java/com/redhat/cloud/notifications/recipients/recipientsresolver/pojo/RecipientsQuery.java +++ b/engine/src/main/java/com/redhat/cloud/notifications/recipients/recipientsresolver/pojo/RecipientsQuery.java @@ -1,7 +1,7 @@ package com.redhat.cloud.notifications.recipients.recipientsresolver.pojo; import com.fasterxml.jackson.databind.annotation.JsonNaming; -import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriterion; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; import com.redhat.cloud.notifications.processors.email.connector.dto.RecipientSettings; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; @@ -24,5 +24,5 @@ public class RecipientsQuery { public boolean subscribedByDefault; - public ExternalAuthorizationCriterion externalAuthorizationCriteria; + public RecipientsAuthorizationCriterion recipientsAuthorizationCriterion; } diff --git a/engine/src/main/java/com/redhat/cloud/notifications/transformers/BaseTransformer.java b/engine/src/main/java/com/redhat/cloud/notifications/transformers/BaseTransformer.java index 785971845a..d6855c18d1 100644 --- a/engine/src/main/java/com/redhat/cloud/notifications/transformers/BaseTransformer.java +++ b/engine/src/main/java/com/redhat/cloud/notifications/transformers/BaseTransformer.java @@ -29,6 +29,7 @@ public class BaseTransformer { public static final String PAYLOAD = "payload"; public static final String SOURCE = "source"; public static final String TIMESTAMP = "timestamp"; + public static final String RECIPIENTS_AUTHORIZATION_CRITERION = "recipients_authorization_criterion"; /** * Transforms the given event into a {@link JsonObject}. @@ -45,6 +46,9 @@ public JsonObject toJsonObject(final Event event) { message.put(BUNDLE, action.getBundle()); message.put(CONTEXT, JsonObject.mapFrom(action.getContext())); message.put(EVENT_TYPE, action.getEventType()); + if (action.getRecipientsAuthorizationCriterion() != null) { + message.put(RECIPIENTS_AUTHORIZATION_CRITERION, JsonObject.mapFrom(action.getRecipientsAuthorizationCriterion())); + } message.put( EVENTS, new JsonArray( diff --git a/engine/src/test/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriteriaExtractorTest.java b/engine/src/test/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriteriaExtractorTest.java deleted file mode 100644 index 7f1d62cf79..0000000000 --- a/engine/src/test/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriteriaExtractorTest.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.redhat.cloud.notifications.processors; - -import com.redhat.cloud.notifications.events.EventWrapperAction; -import com.redhat.cloud.notifications.ingress.Action; -import com.redhat.cloud.notifications.ingress.Context; -import com.redhat.cloud.notifications.ingress.Metadata; -import com.redhat.cloud.notifications.ingress.Payload; -import com.redhat.cloud.notifications.models.EmailAggregation; -import com.redhat.cloud.notifications.models.Event; -import com.redhat.cloud.notifications.models.EventType; -import com.redhat.cloud.notifications.transformers.BaseTransformer; -import io.quarkus.test.junit.QuarkusTest; -import jakarta.inject.Inject; -import org.junit.jupiter.api.Test; -import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static java.time.ZoneOffset.UTC; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -@QuarkusTest -public class ExternalAuthorizationCriteriaExtractorTest { - - @Inject - ExternalAuthorizationCriterionExtractor externalAuthorizationCriteriaExtractor; - - @Inject - BaseTransformer baseTransformer; - - @Test - void testExtractionFromEvent() { - Context context = null; - assertNull(externalAuthorizationCriteriaExtractor.extract(createEvent(context))); - - context = new Context.ContextBuilder() - .withAdditionalProperty("not_null_context", "123456") - .build(); - assertNull(externalAuthorizationCriteriaExtractor.extract(createEvent(context))); - - context = new Context.ContextBuilder() - .withAdditionalProperty(ExternalAuthorizationCriterionExtractor.EXTERNAL_AUTHORIZATION_CRITERIA, null) - .build(); - assertNull(externalAuthorizationCriteriaExtractor.extract(createEvent(context))); - - ExternalAuthorizationCriterion.Type kesselAssetType = new ExternalAuthorizationCriterion.Type(RandomStringUtils.randomAlphanumeric(10), RandomStringUtils.randomAlphanumeric(10)); - ExternalAuthorizationCriterion externalAuthorizationCriterion = new ExternalAuthorizationCriterion(kesselAssetType, RandomStringUtils.randomAlphanumeric(20), RandomStringUtils.randomAlphanumeric(10)); - - context = new Context.ContextBuilder() - .withAdditionalProperty(ExternalAuthorizationCriterionExtractor.EXTERNAL_AUTHORIZATION_CRITERIA, Map.of("type", externalAuthorizationCriterion.getType(), "id", externalAuthorizationCriterion.getId(), "relation", externalAuthorizationCriterion.getRelation())) - .build(); - assertEquals(externalAuthorizationCriterion, externalAuthorizationCriteriaExtractor.extract(createEvent(context))); - } - - @Test - void testExtractionFromEmailAggregation() { - Context context = null; - assertNull(externalAuthorizationCriteriaExtractor.extract(createEmailAggregation(context))); - - context = new Context.ContextBuilder() - .withAdditionalProperty("not_null_context", "123456") - .build(); - assertNull(externalAuthorizationCriteriaExtractor.extract(createEmailAggregation(context))); - - context = new Context.ContextBuilder() - .withAdditionalProperty(ExternalAuthorizationCriterionExtractor.EXTERNAL_AUTHORIZATION_CRITERIA, null) - .build(); - assertNull(externalAuthorizationCriteriaExtractor.extract(createEmailAggregation(context))); - - ExternalAuthorizationCriterion.Type kesselAssetType = new ExternalAuthorizationCriterion.Type(RandomStringUtils.randomAlphanumeric(10), RandomStringUtils.randomAlphanumeric(10)); - ExternalAuthorizationCriterion externalAuthorizationCriterion = new ExternalAuthorizationCriterion(kesselAssetType, RandomStringUtils.randomAlphanumeric(20), RandomStringUtils.randomAlphanumeric(10)); - - context = new Context.ContextBuilder() - .withAdditionalProperty(ExternalAuthorizationCriterionExtractor.EXTERNAL_AUTHORIZATION_CRITERIA, Map.of("type", externalAuthorizationCriterion.getType(), "id", externalAuthorizationCriterion.getId(), "relation", externalAuthorizationCriterion.getRelation())) - .build(); - assertEquals(externalAuthorizationCriterion, externalAuthorizationCriteriaExtractor.extract(createEmailAggregation(context))); - } - - private EmailAggregation createEmailAggregation(Context context) { - EmailAggregation emailAggregation = new EmailAggregation(); - emailAggregation.setPayload(baseTransformer.toJsonObject(createEvent(context))); - return emailAggregation; - } - - private Event createEvent(Context context) { - String orgId = RandomStringUtils.randomNumeric(6); - Action action = new Action.ActionBuilder() - .withBundle("rhel") - .withApplication("policies") - .withEventType("policy-triggered") - .withOrgId(orgId) - .withTimestamp(LocalDateTime.now(UTC)) - .withContext(context) - .withEvents(List.of( - new com.redhat.cloud.notifications.ingress.Event.EventBuilder() - .withMetadata(new Metadata.MetadataBuilder().build()) - .withPayload(new Payload.PayloadBuilder() - .withAdditionalProperty("foo", "bar") - .build() - ).build() - )).build(); - - final EventType eventType = new EventType(); - eventType.setId(UUID.randomUUID()); - - Event event = new Event(); - event.setId(UUID.randomUUID()); - event.setEventWrapper(new EventWrapperAction(action)); - event.setEventType(eventType); - event.setOrgId(orgId); - return event; - } -} diff --git a/engine/src/test/java/com/redhat/cloud/notifications/processors/drawer/DrawerProcessorTest.java b/engine/src/test/java/com/redhat/cloud/notifications/processors/drawer/DrawerProcessorTest.java index 8a593dd1b6..04cd0b7512 100644 --- a/engine/src/test/java/com/redhat/cloud/notifications/processors/drawer/DrawerProcessorTest.java +++ b/engine/src/test/java/com/redhat/cloud/notifications/processors/drawer/DrawerProcessorTest.java @@ -9,6 +9,7 @@ import com.redhat.cloud.notifications.ingress.Context; import com.redhat.cloud.notifications.ingress.Metadata; import com.redhat.cloud.notifications.ingress.Payload; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; import com.redhat.cloud.notifications.models.Application; import com.redhat.cloud.notifications.models.Bundle; import com.redhat.cloud.notifications.models.Endpoint; @@ -17,7 +18,6 @@ import com.redhat.cloud.notifications.models.EventType; import com.redhat.cloud.notifications.models.NotificationHistory; import com.redhat.cloud.notifications.models.SystemSubscriptionProperties; -import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriterion; import com.redhat.cloud.notifications.recipients.User; import com.redhat.cloud.notifications.recipients.recipientsresolver.ExternalRecipientsResolver; import io.quarkus.test.InjectMock; @@ -109,7 +109,7 @@ void shouldCreateTwoDrawerNotifications() { user1.setId("bar"); user2.setUsername("bar"); - when(externalRecipientsResolver.recipientUsers(any(), any(), any(), any(), eq(true), any(ExternalAuthorizationCriterion.class))) + when(externalRecipientsResolver.recipientUsers(any(), any(), any(), any(), eq(true), any(RecipientsAuthorizationCriterion.class))) .thenReturn(Set.of(user1, user2)); Event createdEvent = createEvent(); diff --git a/recipients-resolver/pom.xml b/recipients-resolver/pom.xml index 045522564e..3f8d0590fb 100644 --- a/recipients-resolver/pom.xml +++ b/recipients-resolver/pom.xml @@ -24,6 +24,13 @@ ${project.version} + + + com.redhat.cloud.common + insights-notification-schemas-java + ${insights-notification-schemas-java.version} + + org.project-kessel diff --git a/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/model/ExternalAuthorizationCriterion.java b/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/model/ExternalAuthorizationCriterion.java deleted file mode 100644 index 1119282255..0000000000 --- a/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/model/ExternalAuthorizationCriterion.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.redhat.cloud.notifications.recipients.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import jakarta.validation.constraints.NotNull; -import java.util.Objects; - -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) -@JsonIgnoreProperties(ignoreUnknown = true) -public class ExternalAuthorizationCriterion { - - @NotNull - private Type type; - - @NotNull - private String id; - - @NotNull - private String relation; - - public ExternalAuthorizationCriterion(Type type, String id, String relation) { - this.type = type; - this.id = id; - this.relation = relation; - } - - public @NotNull Type getType() { - return type; - } - - public @NotNull String getId() { - return id; - } - - public @NotNull String getRelation() { - return relation; - } - - public static class Type { - public String name; - public String namespace; - - public Type(String name, String namespace) { - this.name = name; - this.namespace = namespace; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Type type = (Type) o; - return Objects.equals(name, type.name) && Objects.equals(namespace, type.namespace); - } - - @Override - public int hashCode() { - return Objects.hash(name, namespace); - } - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ExternalAuthorizationCriterion that = (ExternalAuthorizationCriterion) o; - return Objects.equals(type, that.type) && Objects.equals(id, that.id) && Objects.equals(relation, that.relation); - } - - @Override - public int hashCode() { - return Objects.hash(type.hashCode(), id, relation); - } -} diff --git a/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/resolver/RecipientsResolver.java b/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/resolver/RecipientsResolver.java index d1106f0b10..4d649258c4 100644 --- a/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/resolver/RecipientsResolver.java +++ b/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/resolver/RecipientsResolver.java @@ -1,7 +1,7 @@ package com.redhat.cloud.notifications.recipients.resolver; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; import com.redhat.cloud.notifications.recipients.config.RecipientsResolverConfig; -import com.redhat.cloud.notifications.recipients.model.ExternalAuthorizationCriterion; import com.redhat.cloud.notifications.recipients.model.RecipientSettings; import com.redhat.cloud.notifications.recipients.model.User; import com.redhat.cloud.notifications.recipients.resolver.kessel.KesselService; @@ -36,17 +36,17 @@ public Set findRecipients(String orgId, Set recipientSe } @CacheResult(cacheName = "find-recipients") - public Set findRecipients(String orgId, Set recipientSettings, Set subscribers, Set unsubscribers, boolean subscribedByDefault, ExternalAuthorizationCriterion externalAuthorizationCriteria) { + public Set findRecipients(String orgId, Set recipientSettings, Set subscribers, Set unsubscribers, boolean subscribedByDefault, RecipientsAuthorizationCriterion recipientsAuthorizationCriterion) { Optional> requestUsersIntersection = extractRequestUsersIntersection(recipientSettings); Set lowerCaseSubscribers = toLowerCaseOrEmpty(subscribers); Set lowerCaseUnsubscribers = toLowerCaseOrEmpty(unsubscribers); return recipientSettings.stream() - .flatMap(r -> recipientUsers(orgId, r, requestUsersIntersection, lowerCaseSubscribers, lowerCaseUnsubscribers, subscribedByDefault, externalAuthorizationCriteria).stream()) + .flatMap(r -> recipientUsers(orgId, r, requestUsersIntersection, lowerCaseSubscribers, lowerCaseUnsubscribers, subscribedByDefault, recipientsAuthorizationCriterion).stream()) .collect(toSet()); } - private Set recipientUsers(String orgId, RecipientSettings request, Optional> requestUsersIntersection, Set subscribers, Set unsubscribers, boolean subscribedByDefault, ExternalAuthorizationCriterion externalAuthorizationCriteria) { + private Set recipientUsers(String orgId, RecipientSettings request, Optional> requestUsersIntersection, Set subscribers, Set unsubscribers, boolean subscribedByDefault, RecipientsAuthorizationCriterion recipientsAuthorizationCriterion) { /* * When: @@ -67,8 +67,8 @@ private Set recipientUsers(String orgId, RecipientSettings request, Option } final Set authorizedUsers = new HashSet<>(); - if (recipientsResolverConfig.isUseKesselEnabled() && !fetchedUsers.isEmpty() && null != externalAuthorizationCriteria) { - authorizedUsers.addAll(findAuthorizedUsersWithCriteria(externalAuthorizationCriteria)); + if (recipientsResolverConfig.isUseKesselEnabled() && !fetchedUsers.isEmpty() && null != recipientsAuthorizationCriterion) { + authorizedUsers.addAll(findAuthorizedUsersWithCriterion(recipientsAuthorizationCriterion)); } // The fetched users are cached, so we need to create a new Set to avoid altering the cached data. @@ -86,7 +86,7 @@ private Set recipientUsers(String orgId, RecipientSettings request, Option return true; } - if (recipientsResolverConfig.isUseKesselEnabled() && null != externalAuthorizationCriteria && !authorizedUsers.contains(lowerCaseUsername)) { + if (recipientsResolverConfig.isUseKesselEnabled() && null != recipientsAuthorizationCriterion && !authorizedUsers.contains(lowerCaseUsername)) { return true; } @@ -142,7 +142,7 @@ private static Optional> extractRequestUsersIntersection(Set findAuthorizedUsersWithCriteria(ExternalAuthorizationCriterion externalAuthorizationCriteria) { + private Set findAuthorizedUsersWithCriterion(RecipientsAuthorizationCriterion externalAuthorizationCriteria) { Set authorizedUsers = new HashSet<>(); if (externalAuthorizationCriteria != null) { try { diff --git a/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/resolver/kessel/KesselService.java b/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/resolver/kessel/KesselService.java index e1755ddcac..523c6469b3 100644 --- a/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/resolver/kessel/KesselService.java +++ b/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/resolver/kessel/KesselService.java @@ -1,7 +1,7 @@ package com.redhat.cloud.notifications.recipients.resolver.kessel; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; import com.redhat.cloud.notifications.recipients.config.RecipientsResolverConfig; -import com.redhat.cloud.notifications.recipients.model.ExternalAuthorizationCriterion; import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; @@ -39,9 +39,9 @@ void postConstruct() { lookupClient = clientsManager.getLookupClient(); } - public Set lookupSubjects(ExternalAuthorizationCriterion externalAuthorizationCriteria) { + public Set lookupSubjects(RecipientsAuthorizationCriterion recipientsAuthorizationCriterion) { Set userNames = new HashSet<>(); - LookupSubjectsRequest request = getLookupSubjectsRequest(externalAuthorizationCriteria); + LookupSubjectsRequest request = getLookupSubjectsRequest(recipientsAuthorizationCriterion); for (Iterator it = lookupClient.lookupSubjects(request); it.hasNext();) { LookupSubjectsResponse response = it.next(); @@ -50,15 +50,15 @@ public Set lookupSubjects(ExternalAuthorizationCriterion externalAuthori return userNames; } - private static LookupSubjectsRequest getLookupSubjectsRequest(ExternalAuthorizationCriterion externalAuthorizationCriteria) { + private static LookupSubjectsRequest getLookupSubjectsRequest(RecipientsAuthorizationCriterion recipientsAuthorizationCriterion) { LookupSubjectsRequest request = LookupSubjectsRequest.newBuilder() .setResource(ObjectReference.newBuilder() .setType(ObjectType.newBuilder() - .setNamespace(externalAuthorizationCriteria.getType().namespace) - .setName(externalAuthorizationCriteria.getType().name).build()) - .setId(externalAuthorizationCriteria.getId()) + .setNamespace(recipientsAuthorizationCriterion.getType().getNamespace()) + .setName(recipientsAuthorizationCriterion.getType().getName()).build()) + .setId(recipientsAuthorizationCriterion.getId()) .build()) - .setRelation(externalAuthorizationCriteria.getRelation()) + .setRelation(recipientsAuthorizationCriterion.getRelation()) .setSubjectType(ObjectType.newBuilder().setNamespace(RBAC_NAMESPACE).setName(SUBJECT_TYPE_USER).build()) .build(); return request; diff --git a/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/rest/RecipientsResolverResource.java b/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/rest/RecipientsResolverResource.java index 90d4c0fa0a..7048225ea0 100644 --- a/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/rest/RecipientsResolverResource.java +++ b/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/rest/RecipientsResolverResource.java @@ -31,6 +31,6 @@ public Set getRecipients(@NotNull @Valid RecipientsQuery recipientsQuery) recipientsQuery.subscribers, recipientsQuery.unsubscribers, recipientsQuery.subscribedByDefault, - recipientsQuery.externalAuthorizationCriteria); + recipientsQuery.recipientsAuthorizationCriterion); } } diff --git a/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/rest/pojo/RecipientsQuery.java b/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/rest/pojo/RecipientsQuery.java index 7954c056ff..13730f288b 100644 --- a/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/rest/pojo/RecipientsQuery.java +++ b/recipients-resolver/src/main/java/com/redhat/cloud/notifications/recipients/rest/pojo/RecipientsQuery.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonNaming; -import com.redhat.cloud.notifications.recipients.model.ExternalAuthorizationCriterion; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; import com.redhat.cloud.notifications.recipients.model.RecipientSettings; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; @@ -26,5 +26,5 @@ public class RecipientsQuery { public boolean subscribedByDefault; - public ExternalAuthorizationCriterion externalAuthorizationCriteria; + public RecipientsAuthorizationCriterion recipientsAuthorizationCriterion; } diff --git a/recipients-resolver/src/test/java/com/redhat/cloud/notifications/recipients/resolver/RecipientsResolverTest.java b/recipients-resolver/src/test/java/com/redhat/cloud/notifications/recipients/resolver/RecipientsResolverTest.java index 15422fdf9d..e3a96a817b 100644 --- a/recipients-resolver/src/test/java/com/redhat/cloud/notifications/recipients/resolver/RecipientsResolverTest.java +++ b/recipients-resolver/src/test/java/com/redhat/cloud/notifications/recipients/resolver/RecipientsResolverTest.java @@ -1,7 +1,8 @@ package com.redhat.cloud.notifications.recipients.resolver; +import com.redhat.cloud.notifications.ingress.RecipientsAuthorizationCriterion; +import com.redhat.cloud.notifications.ingress.Type; import com.redhat.cloud.notifications.recipients.config.RecipientsResolverConfig; -import com.redhat.cloud.notifications.recipients.model.ExternalAuthorizationCriterion; import com.redhat.cloud.notifications.recipients.model.RecipientSettings; import com.redhat.cloud.notifications.recipients.model.User; import com.redhat.cloud.notifications.recipients.resolver.kessel.KesselService; @@ -131,14 +132,19 @@ void testNotSubscribedByDefaultAndDefaultSettings() { @ParameterizedTest @CsvSource({"true,false", "true,true", "false,true", "false,false"}) void testNotSubscribedByDefaultAndAdminsOnlyWithOrWithoutKessel(boolean useKessel, boolean useJsonObjectAsAuthData) { - ExternalAuthorizationCriterion externalAuthorizationCriteria = null; + RecipientsAuthorizationCriterion externalAuthorizationCriteria = null; // update Kessel feature flag only if use Kessel is true, to keep check on default behaviour if (useKessel) { when(recipientsResolverConfig.isUseKesselEnabled()).thenReturn(useKessel); } if (useJsonObjectAsAuthData) { - ExternalAuthorizationCriterion.Type kesselAssetType = new ExternalAuthorizationCriterion.Type("host", "namespace_test"); - externalAuthorizationCriteria = new ExternalAuthorizationCriterion(kesselAssetType, "defaultId", "relationship"); + Type kesselAssetType = new Type(); + kesselAssetType.setNamespace("namespace_test"); + kesselAssetType.setName("host"); + externalAuthorizationCriteria = new RecipientsAuthorizationCriterion(); + externalAuthorizationCriteria.setId("defaultId"); + externalAuthorizationCriteria.setRelation("relationship"); + externalAuthorizationCriteria.setType(kesselAssetType); when(kesselService.lookupSubjects(any())).thenReturn(Set.of("user1", "admin1")); } Set recipients = recipientsResolver.findRecipients(