diff --git a/quarkus/config-api/src/main/java/org/keycloak/config/EventOptions.java b/quarkus/config-api/src/main/java/org/keycloak/config/EventOptions.java index 07324229c05..c61ccc89a2d 100644 --- a/quarkus/config-api/src/main/java/org/keycloak/config/EventOptions.java +++ b/quarkus/config-api/src/main/java/org/keycloak/config/EventOptions.java @@ -23,22 +23,7 @@ public class EventOptions { .category(OptionCategory.EVENTS) .description("Comma-separated list of events to be collected for user event metrics. This option can be used to reduce the number of metrics created as by default all user events create a metric.") .buildTime(false) - .expectedValues(sortedListOfEvents()) .deprecatedMetadata(DeprecatedMetadata.deprecateValues("Use `remove_credential` instead of `remove_totp`, and `update_credential` instead of `update_totp` and `update_password`.", "remove_totp", "update_totp", "update_password")) .build(); - private static List sortedListOfEvents() { - List events = new java.util.ArrayList<>(List.of("register", "login", "code_to_token", "logout", "client_login", "refresh_token", "introspect_token", "federated_identity_link", - "remove_federated_identity", "update_email", "update_profile", - "verify_email", "verify_profile", "grant_consent", "update_consent", "revoke_grant", "send_verify_email", "send_reset_password", "send_identity_provider_link", - "reset_password", "restart_authentication", "invalid_signature", "register_node", "unregister_node", "user_info_request", "identity_provider_link_account", "identity_provider_login", - "identity_provider_first_login", "identity_provider_post_login", "identity_provider_response", "identity_provider_retrieve_token", "impersonate", "custom_required_action", - "execute_actions", "execute_action_token", "client_info", "client_register", "client_update", "client_delete", "client_initiated_account_linking", "token_exchange", - "oauth2_device_auth", "oauth2_device_verify_user_code", "oauth2_device_code_to_token", "authreqid_to_token", "permission_token", "delete_account", "pushed_authorization_request", - "user_disabled_by_permanent_lockout", "user_disabled_by_temporary_lockout", "oauth2_extension_grant", "federated_identity_override_link", "update_credential", "remove_credential", - "invite_org", "remove_totp", "update_totp", "update_password", "user_session_deleted", "verifiable_credential_request", "verifiable_credential_offer_request", "verifiable_credential_nonce_request")); - events.sort(String::compareToIgnoreCase); - return events; - } - } diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/EventPropertyMappers.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/EventPropertyMappers.java index fe544c8eaf0..31af38bdd5d 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/EventPropertyMappers.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/EventPropertyMappers.java @@ -1,8 +1,11 @@ package org.keycloak.quarkus.runtime.configuration.mappers; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.keycloak.common.Profile; +import org.keycloak.events.EventType; import static org.keycloak.config.EventOptions.USER_EVENT_METRICS_ENABLED; import static org.keycloak.config.EventOptions.USER_EVENT_METRICS_EVENTS; @@ -27,7 +30,7 @@ final class EventPropertyMappers implements PropertyMapperGrouping { .paramLabel("tags") .isEnabled(EventPropertyMappers::userEventsMetricsTags, "user event metrics are enabled") .build(), - fromOption(USER_EVENT_METRICS_EVENTS) + fromOption(USER_EVENT_METRICS_EVENTS.toBuilder().expectedValues(expectedUserMetricEvents()).build()) .to("kc.spi-events-listener--micrometer-user-event-metrics--events") .paramLabel("events") .isEnabled(EventPropertyMappers::userEventsMetricsTags, "user event metrics are enabled") @@ -35,6 +38,23 @@ final class EventPropertyMappers implements PropertyMapperGrouping { ); } + private static List expectedUserMetricEvents() { + List values = new ArrayList<>(); + for (EventType event : EventType.values()) { + if (event.name().endsWith("_ERROR")) { + continue; + } + if (event == EventType.VALIDATE_ACCESS_TOKEN) { + // event is deprecated and no longer used in the code base + continue; + } + String value = event.name().toLowerCase(); + values.add(value); + } + Collections.sort(values); + return values; + } + private static boolean userEventsMetricsEnabled() { return metricsEnabled() && Profile.isFeatureEnabled(Profile.Feature.USER_EVENT_METRICS); } diff --git a/quarkus/runtime/src/test/java/org/keycloak/config/EventOptionsTest.java b/quarkus/runtime/src/test/java/org/keycloak/config/EventOptionsTest.java index 5c3574abfe9..c5000890bb9 100644 --- a/quarkus/runtime/src/test/java/org/keycloak/config/EventOptionsTest.java +++ b/quarkus/runtime/src/test/java/org/keycloak/config/EventOptionsTest.java @@ -28,37 +28,13 @@ import static org.junit.Assert.fail; public class EventOptionsTest { - /** - * This test ensures that list of CLI options is in-sync with the {@link EventType} enum. - * That enum is not directly accessible by the CLI classes, that's why there is this test. - */ @Test - public void testAllEnumsArePresent() { - List expectedValues = new ArrayList<>(EventOptions.USER_EVENT_METRICS_EVENTS.getExpectedValues()); + public void testDeprecatedArePresent() { List deprecatedValues = new ArrayList<>(EventOptions.USER_EVENT_METRICS_EVENTS.getDeprecatedMetadata().get().getDeprecatedValues()); - List missingOptions = new ArrayList<>(); for (EventType event : EventType.values()) { - if (event.name().endsWith("_ERROR")) { - continue; - } - if (event == EventType.VALIDATE_ACCESS_TOKEN) { - // event is deprecated and no longer used in the code base - continue; - } String value = event.name().toLowerCase(); - if (expectedValues.contains(value)) { - expectedValues.remove(value); - } else { - missingOptions.add(value); - } deprecatedValues.remove(value); } - if (!missingOptions.isEmpty()) { - fail("Missing event types " + missingOptions + " in event-metrics-user-events"); - } - if (!expectedValues.isEmpty()) { - fail("Unknown event types " + expectedValues + " found in event-metrics-user-events"); - } if (!deprecatedValues.isEmpty()) { fail("Unknown event types " + deprecatedValues + " found in event-metrics-user-events"); }