@Test public void testWhenAzureAndEntitled() { when(entitlementService.getEntitlements(anyString(), anyString())).thenReturn(List.of("DATAHUB_AWS_AUTOSCALING", "DATAHUB_AZURE_AUTOSCALING")); boolean entitled = underTest.autoscalingEntitlementEnabled(TEST_USER_CRN, TEST_ACCOUNT_ID, "AZURE"); assertTrue("isEntitled should be true when entitlement found", entitled); }
@Cacheable(cacheNames = "accountEntitlementCache", key = "{#accountId,#cloudPlatform}") public boolean autoscalingEntitlementEnabled(String userCrn, String accountId, String cloudPlatform) { boolean entitled; Optional<String> platformEntitlement = Optional.ofNullable(PLATFORM_ENTITLEMENTS.get(cloudPlatform)); if (!entitlementCheckEnabled || platformEntitlement.map(entitlement -> ALLOWED.equals(entitlement)).orElse(false)) { entitled = true; } else if (platformEntitlement.isEmpty()) { entitled = false; } else { entitled = entitlementService.getEntitlements(userCrn, accountId) .stream().anyMatch(e -> e.equalsIgnoreCase(platformEntitlement.get())); } return entitled; }
EntitlementValidationService { @Cacheable(cacheNames = "accountEntitlementCache", key = "{#accountId,#cloudPlatform}") public boolean autoscalingEntitlementEnabled(String userCrn, String accountId, String cloudPlatform) { boolean entitled; Optional<String> platformEntitlement = Optional.ofNullable(PLATFORM_ENTITLEMENTS.get(cloudPlatform)); if (!entitlementCheckEnabled || platformEntitlement.map(entitlement -> ALLOWED.equals(entitlement)).orElse(false)) { entitled = true; } else if (platformEntitlement.isEmpty()) { entitled = false; } else { entitled = entitlementService.getEntitlements(userCrn, accountId) .stream().anyMatch(e -> e.equalsIgnoreCase(platformEntitlement.get())); } return entitled; } }
EntitlementValidationService { @Cacheable(cacheNames = "accountEntitlementCache", key = "{#accountId,#cloudPlatform}") public boolean autoscalingEntitlementEnabled(String userCrn, String accountId, String cloudPlatform) { boolean entitled; Optional<String> platformEntitlement = Optional.ofNullable(PLATFORM_ENTITLEMENTS.get(cloudPlatform)); if (!entitlementCheckEnabled || platformEntitlement.map(entitlement -> ALLOWED.equals(entitlement)).orElse(false)) { entitled = true; } else if (platformEntitlement.isEmpty()) { entitled = false; } else { entitled = entitlementService.getEntitlements(userCrn, accountId) .stream().anyMatch(e -> e.equalsIgnoreCase(platformEntitlement.get())); } return entitled; }  }
EntitlementValidationService { @Cacheable(cacheNames = "accountEntitlementCache", key = "{#accountId,#cloudPlatform}") public boolean autoscalingEntitlementEnabled(String userCrn, String accountId, String cloudPlatform) { boolean entitled; Optional<String> platformEntitlement = Optional.ofNullable(PLATFORM_ENTITLEMENTS.get(cloudPlatform)); if (!entitlementCheckEnabled || platformEntitlement.map(entitlement -> ALLOWED.equals(entitlement)).orElse(false)) { entitled = true; } else if (platformEntitlement.isEmpty()) { entitled = false; } else { entitled = entitlementService.getEntitlements(userCrn, accountId) .stream().anyMatch(e -> e.equalsIgnoreCase(platformEntitlement.get())); } return entitled; }  @Cacheable(cacheNames = "accountEntitlementCache", key = "{#accountId,#cloudPlatform}") boolean autoscalingEntitlementEnabled(String userCrn, String accountId, String cloudPlatform); }
EntitlementValidationService { @Cacheable(cacheNames = "accountEntitlementCache", key = "{#accountId,#cloudPlatform}") public boolean autoscalingEntitlementEnabled(String userCrn, String accountId, String cloudPlatform) { boolean entitled; Optional<String> platformEntitlement = Optional.ofNullable(PLATFORM_ENTITLEMENTS.get(cloudPlatform)); if (!entitlementCheckEnabled || platformEntitlement.map(entitlement -> ALLOWED.equals(entitlement)).orElse(false)) { entitled = true; } else if (platformEntitlement.isEmpty()) { entitled = false; } else { entitled = entitlementService.getEntitlements(userCrn, accountId) .stream().anyMatch(e -> e.equalsIgnoreCase(platformEntitlement.get())); } return entitled; }  @Cacheable(cacheNames = "accountEntitlementCache", key = "{#accountId,#cloudPlatform}") boolean autoscalingEntitlementEnabled(String userCrn, String accountId, String cloudPlatform);  }