FFFF Remove deprecated user event types by rmartinc · Pull Request #55790 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/documentation/server_admin/topics/admin-cli.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,13 @@ You can turn on storage for all available ERROR events, not including auditing e
+
[options="nowrap"]
----
$ kcadm.sh update events/config -r demorealm -s eventsEnabled=true -s 'enabledEventTypes=["LOGIN_ERROR","REGISTER_ERROR","LOGOUT_ERROR","CODE_TO_TOKEN_ERROR","CLIENT_LOGIN_ERROR","FEDERATED_IDENTITY_LINK_ERROR","REMOVE_FEDERATED_IDENTITY_ERROR","UPDATE_EMAIL_ERROR","UPDATE_PROFILE_ERROR","UPDATE_PASSWORD_ERROR","UPDATE_TOTP_ERROR","UPDATE_CREDENTIAL_ERROR","VERIFY_EMAIL_ERROR","REMOVE_TOTP_ERROR","REMOVE_CREDENTIAL_ERROR","SEND_VERIFY_EMAIL_ERROR","SEND_RESET_PASSWORD_ERROR","SEND_IDENTITY_PROVIDER_LINK_ERROR","RESET_PASSWORD_ERROR","IDENTITY_PROVIDER_FIRST_LOGIN_ERROR","IDENTITY_PROVIDER_POST_LOGIN_ERROR","CUSTOM_REQUIRED_ACTION_ERROR","EXECUTE_ACTIONS_ERROR","CLIENT_REGISTER_ERROR","CLIENT_UPDATE_ERROR","CLIENT_DELETE_ERROR"]' -s eventsExpiration=172800
$ kcadm.sh update events/config -r demorealm -s eventsEnabled=true -s 'enabledEventTypes=["LOGIN_ERROR","REGISTER_ERROR","LOGOUT_ERROR","CODE_TO_TOKEN_ERROR","CLIENT_LOGIN_ERROR","FEDERATED_IDENTITY_LINK_ERROR","REMOVE_FEDERATED_IDENTITY_ERROR","UPDATE_EMAIL_ERROR","UPDATE_PROFILE_ERROR","UPDATE_CREDENTIAL_ERROR","VERIFY_EMAIL_ERROR","REMOVE_CREDENTIAL_ERROR","SEND_VERIFY_EMAIL_ERROR","SEND_RESET_PASSWORD_ERROR","SEND_IDENTITY_PROVIDER_LINK_ERROR","RESET_PASSWORD_ERROR","IDENTITY_PROVIDER_FIRST_LOGIN_ERROR","IDENTITY_PROVIDER_POST_LOGIN_ERROR","CUSTOM_REQUIRED_ACTION_ERROR","EXECUTE_ACTIONS_ERROR","CLIENT_REGISTER_ERROR","CLIENT_UPDATE_ERROR","CLIENT_DELETE_ERROR"]' -s eventsExpiration=172800
----
* Windows:
+
[options="nowrap"]
----
c:\> kcadm update events/config -r demorealm -s eventsEnabled=true -s "enabledEventTypes=[\"LOGIN_ERROR\",\"REGISTER_ERROR\",\"LOGOUT_ERROR\",\"CODE_TO_TOKEN_ERROR\",\"CLIENT_LOGIN_ERROR\",\"FEDERATED_IDENTITY_LINK_ERROR\",\"REMOVE_FEDERATED_IDENTITY_ERROR\",\"UPDATE_EMAIL_ERROR\",\"UPDATE_PROFILE_ERROR\",\"UPDATE_PASSWORD_ERROR\",\"UPDATE_TOTP_ERROR\",\"UPDATE_CREDENTIAL_ERROR\",\"VERIFY_EMAIL_ERROR\",\"REMOVE_TOTP_ERROR\",\"REMOVE_CREDENTIAL_ERROR\",\"SEND_VERIFY_EMAIL_ERROR\",\"SEND_RESET_PASSWORD_ERROR\",\"SEND_IDENTITY_PROVIDER_LINK_ERROR\",\"RESET_PASSWORD_ERROR\",\"IDENTITY_PROVIDER_FIRST_LOGIN_ERROR\",\"IDENTITY_PROVIDER_POST_LOGIN_ERROR\",\"CUSTOM_REQUIRED_ACTION_ERROR\",\"EXECUTE_ACTIONS_ERROR\",\"CLIENT_REGISTER_ERROR\",\"CLIENT_UPDATE_ERROR\",\"CLIENT_DELETE_ERROR\"]" -s eventsExpiration=172800
c:\> kcadm update events/config -r demorealm -s eventsEnabled=true -s "enabledEventTypes=[\"LOGIN_ERROR\",\"REGISTER_ERROR\",\"LOGOUT_ERROR\",\"CODE_TO_TOKEN_ERROR\",\"CLIENT_LOGIN_ERROR\",\"FEDERATED_IDENTITY_LINK_ERROR\",\"REMOVE_FEDERATED_IDENTITY_ERROR\",\"UPDATE_EMAIL_ERROR\",\"UPDATE_PROFILE_ERROR\",\"UPDATE_CREDENTIAL_ERROR\",\"VERIFY_EMAIL_ERROR\",\"REMOVE_CREDENTIAL_ERROR\",\"SEND_VERIFY_EMAIL_ERROR\",\"SEND_RESET_PASSWORD_ERROR\",\"SEND_IDENTITY_PROVIDER_LINK_ERROR\",\"RESET_PASSWORD_ERROR\",\"IDENTITY_PROVIDER_FIRST_LOGIN_ERROR\",\"IDENTITY_PROVIDER_POST_LOGIN_ERROR\",\"CUSTOM_REQUIRED_ACTION_ERROR\",\"EXECUTE_ACTIONS_ERROR\",\"CLIENT_REGISTER_ERROR\",\"CLIENT_UPDATE_ERROR\",\"CLIENT_DELETE_ERROR\"]" -s eventsExpiration=172800
----

You can reset stored event types to *all available event types*. Setting the value to an empty list is the same as enumerating all.
Expand Down
9 changes: 0 additions & 9 deletions docs/documentation/server_admin/topics/events/login.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,9 @@ image:images/search-user-event.png[Search user event]
|Send Password Reset
|{project_name} sends a password reset email.

|Update Password (deprecated)
|The password for an account changes.

|Update Credential
|The password or (time-based) one-time Password (OTP/TOTP) settings for an account changes.

|Update TOTP (deprecated)
|The Time-based One-time Password (TOTP) settings for an account changes.

|Remove TOTP (deprecated)
|{project_name} removes TOTP from an account.

|Remove Credential
|{project_name} removes a credential from an account.

Expand Down
6 changes: 6 additions & 0 deletions docs/documentation/upgrading/topics/changes/changes-27_0_0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1163,3 +1163,9 @@ The *Passkeys Conditional UI Authenticator* and its associated feature `passkeys
This authenticator was an early implementation of passkeys support. It was deprecated in previous versions once passkeys were integrated directly into the default login pages, and it was maintained only for backward compatibility.

If you are still using this authenticator, migrate to the default link:{adminguide_link}#passkeys_server_administration_guide[Passkeys] integration in {project_name}.

=== Deprecated user event types have been removed

The deprecated user event types (`VALIDATE_ACCESS_TOKEN`, `UPDATE_PASSWORD`, `UPDATE_TOTP`, `REMOVE_TOTP`, and their associated error types) have been removed. `VALIDATE_ACCESS_TOKEN` was deprecated a long time ago and is never triggered by {project_name}. The other types were replaced in version 26.0 by the generic credential variants (`UPDATE_CREDENTIAL` and `REMOVE_CREDENTIAL`). Until this release, both the specific and generic events (for example, `UPDATE_PASSWORD` and `UPDATE_CREDENTIAL`) were fired, but moving forward, only the generic types are used.

A new `UNKNOWN` event type has been added to represent removed event types when retrieving historical events stored in the database. This event type is never fired for new events.
9 changes: 1 addition & 8 deletions js/libs/keycloak-admin-client/src/defs/eventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ type EventType =
| "CLIENT_LOGIN_ERROR"
| "REFRESH_TOKEN"
| "REFRESH_TOKEN_ERROR"
| "VALIDATE_ACCESS_TOKEN"
| "VALIDATE_ACCESS_TOKEN_ERROR"
| "INTROSPECT_TOKEN"
| "INTROSPECT_TOKEN_ERROR"
| "FEDERATED_IDENTITY_LINK"
Expand All @@ -23,14 +21,9 @@ type EventType =
| "UPDATE_EMAIL_ERROR"
| "UPDATE_PROFILE"
| "UPDATE_PROFILE_ERROR"
| "UPDATE_PASSWORD"
| "UPDATE_PASSWORD_ERROR"
| "UPDATE_TOTP"
| "UPDATE_TOTP_ERROR"
| "UNKNOWN"
| "VERIFY_EMAIL"
| "VERIFY_EMAIL_ERROR"
| "REMOVE_TOTP"
| "REMOVE_TOTP_ERROR"
| "REVOKE_GRANT"
| "REVOKE_GRANT_ERROR"
| "SEND_VERIFY_EMAIL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static Event convertEvent(EventEntity eventEntity) {
Event event = new Event();
event.setId(eventEntity.getId() == null ? UUID.randomUUID().toString() : eventEntity.getId());
event.setTime(eventEntity.getTime());
event.setType(EventType.valueOf(eventEntity.getType()));
event.setType(EventType.valueOfDefaultUnknown(eventEntity.getType()));
Comment thread
rmartinc marked this conversation as resolved.
Resolved
Comment thread
rmartinc marked this conversation as resolved.
Resolved
event.setRealmId(eventEntity.getRealmId());
event.setClientId(eventEntity.getClientId());
event.setUserId(eventEntity.getUserId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package org.keycloak.migration.migrators;

import java.util.Set;
import java.util.stream.Collectors;

import org.keycloak.events.EventType;
import org.keycloak.migration.ModelVersion;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
Expand All @@ -39,21 +43,17 @@ public ModelVersion getVersion() {
return VERSION;
}

@Override
public void migrate(KeycloakSession session) {
// Liquibase migrates persisted themes; Java migration is only needed for imports.
}

@Override
public void migrateRealm(KeycloakSession session, RealmModel realm) {
updateLoginTheme(realm);
updateAccountTheme(realm);
// Liquibase migrates persisted themes; Java migration is only needed for imports.
migrateEventTypes(realm);
}

@Override
public void migrateImport(KeycloakSession session, RealmModel realm, RealmRepresentation rep, boolean skipUserDependent) {
updateLoginTheme(realm);
updateAccountTheme(realm);
migrateEventTypes(realm);
}

private void updateLoginTheme(RealmModel realm) {
Expand All @@ -73,6 +73,56 @@ private void updateAccountTheme(RealmModel realm) {
}
}

void migrateEventTypes(RealmModel realm) {
Set<String> enabledEventTypes = realm.getEnabledEventTypesStream().collect(Collectors.toSet());
if (migrateUpdateCredentialEvents(enabledEventTypes)
| migrateUpdateCredentialErrorEvents(enabledEventTypes)
| migrateRemoveCredentialEvents(enabledEventTypes)
| migrateRemoveCredentialErrorEvents(enabledEventTypes)
| migrateValidateAccessEvents(enabledEventTypes)) {
if (enabledEventTypes.isEmpty()) {
realm.setEventsEnabled(false);
}
realm.setEnabledEventTypes(enabledEventTypes);
Comment thread
rmartinc marked this conversation as resolved.
Resolved
}
}

private static boolean migrateUpdateCredentialEvents(Set<String> enabledEventTypes) {
if (enabledEventTypes.removeAll(Set.of("UPDATE_PASSWORD", "UPDATE_TOTP"))) {
enabledEventTypes.add(EventType.UPDATE_CREDENTIAL.name());
return true;
}
return false;
}

private static boolean migrateUpdateCredentialErrorEvents(Set<String> enabledEventTypes) {
if (enabledEventTypes.removeAll(Set.of("UPDATE_PASSWORD_ERROR", "UPDATE_TOTP_ERROR"))) {
enabledEventTypes.add(EventType.UPDATE_CREDENTIAL_ERROR.name());
return true;
}
return false;
}

private static boolean migrateRemoveCredentialEvents(Set<String> enabledEventTypes) {
if (enabledEventTypes.remove("REMOVE_TOTP")) {
enabledEventTypes.add(EventType.REMOVE_CREDENTIAL.name());
return true;
}
return false;
}

private static boolean migrateRemoveCredentialErrorEvents(Set<String> enabledEventTypes) {
if (enabledEventTypes.remove("REMOVE_TOTP_ERROR")) {
enabledEventTypes.add(EventType.REMOVE_CREDENTIAL_ERROR.name());
return true;
}
return false;
}

private static boolean migrateValidateAccessEvents(Set<String> enabledEventTypes) {
return enabledEventTypes.removeAll(Set.of("VALIDATE_ACCESS_TOKEN", "VALIDATE_ACCESS_TOKEN_ERROR"));
}

private static boolean isLegacyLoginTheme(String theme) {
return "keycloak".equals(theme)
|| "keycloak.v2".equals(theme)
Expand Down
10BC8
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.keycloak.models.ClientModel;
Expand All @@ -33,16 +35,12 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;

public class MigrateTo27_0_0Test {

private final MigrateTo27_0_0 migrator = new MigrateTo27_0_0();

@Test
public void migrateDoesNotAccessPersistedRealms() {
migrator.migrate(null);
}

@Test
public void migrateRealmUpdatesBuiltinLoginThemes() {
assertLoginThemeMigrated("keycloak.v2", "keycloak.v3");
Expand Down Expand Up @@ -101,15 +99,85 @@ public void migrateImportUpdatesLoginAndAccountThemes() {
assertThat(realm.getAccountTheme(), is("keycloak.v4"));
}

@Test
public void migrateEventTypesEmpty() {
migrateEventTypes(Set.of(), Set.of());
}

@Test
public void migrateEventTypesNotPresent() {
migrateEventTypes(Set.of("LOGIN", "LOGIN_ERROR"), Set.of("LOGIN", "LOGIN_ERROR"));
}

@Test
public void migrateEventTypesAll() {
migrateEventTypes(Set.of("VALIDATE_ACCESS_TOKEN", "VALIDATE_ACCESS_TOKEN_ERROR", "UPDATE_PASSWORD",
"UPDATE_PASSWORD_ERROR", "UPDATE_TOTP", "UPDATE_TOTP_ERROR", "REMOVE_TOTP", "REMOVE_TOTP_ERROR"),
Set.of("UPDATE_CREDENTIAL", "UPDATE_CREDENTIAL_ERROR", "REMOVE_CREDENTIAL", "REMOVE_CREDENTIAL_ERROR"));
}

@Test
public void migrateEventTypesSuccess() {
migrateEventTypes(Set.of("LOGIN", "UPDATE_PASSWORD", "UPDATE_TOTP", "REMOVE_TOTP"),
Set.of("LOGIN", "UPDATE_CREDENTIAL", "REMOVE_CREDENTIAL"));
}

@Test
public void migrateEventTypesError() {
migrateEventTypes(Set.of("LOGIN", "UPDATE_PASSWORD_ERROR", "UPDATE_TOTP_ERROR", "REMOVE_TOTP_ERROR"),
Set.of("LOGIN", "UPDATE_CREDENTIAL_ERROR", "REMOVE_CREDENTIAL_ERROR"));
}

@Test
public void migrateEventTypesUpdatesOnly() {
migrateEventTypes(Set.of("LOGIN", "UPDATE_PASSWORD", "UPDATE_PASSWORD_ERROR"),
Set.of("LOGIN", "UPDATE_CREDENTIAL", "UPDATE_CREDENTIAL_ERROR"));
}

@Test
public void migrateEventTypesRemovesOnly() {
migrateEventTypes(Set.of("LOGIN", "REMOVE_TOTP_ERROR", "REMOVE_TOTP"),
Set.of("LOGIN", "REMOVE_CREDENTIAL", "REMOVE_CREDENTIAL_ERROR"));
}

@Test
public void migrateEventTypeAlreadyPresent() {
migrateEventTypes(Set.of("LOGIN", "UPDATE_CREDENTIAL", "UPDATE_CREDENTIAL_ERROR", "VALIDATE_ACCESS_TOKEN",
"REMOVE_CREDENTIAL", "REMOVE_CREDENTIAL_ERROR", "VALIDATE_ACCESS_TOKEN_ERROR", "UPDATE_PASSWORD",
"UPDATE_PASSWORD_ERROR", "UPDATE_TOTP", "UPDATE_TOTP_ERROR", "REMOVE_TOTP", "REMOVE_TOTP_ERROR"),
Set.of("LOGIN", "UPDATE_CREDENTIAL", "UPDATE_CREDENTIAL_ERROR", "REMOVE_CREDENTIAL", "REMOVE_CREDENTIAL_ERROR"));
}

public void migrateEventTypes(Set<String> enabledEventTypes, Set<String> expectedEventTypes) {
RealmModel realm = new RealmModelDelegate(null) {

private Set<String> set = Set.copyOf(enabledEventTypes);

@Override
public Stream<String> getEnabledEventTypesStream() {
return set.stream();
}

@Override
public void setEnabledEventTypes(Set<String> enabledEventTypes) {
this.set = enabledEventTypes;
}

};

migrator.migrateEventTypes(realm);
assertEquals(expectedEventTypes, realm.getEnabledEventTypesStream().collect(Collectors.toSet()));
}

private void assertLoginThemeMigrated(String before, String after) {
RealmModel realm = realmWithThemes(before, null);
migrator.migrateRealm(null, realm);
migrator.migrateImport(null, realm, new RealmRepresentation(), false);
assertThat(realm.getLoginTheme(), is(equalTo(after)));
}

private void assertAccountThemeMigrated(String before, String after) {
RealmModel realm = realmWithThemes(null, before);
migrator.migrateRealm(null, realm);
migrator.migrateImport(null, realm, new RealmRepresentation(), false);
if (after == null) {
assertThat(realm.getAccountTheme(), nullValue());
} else {
Expand Down Expand Up @@ -146,6 +214,11 @@ public void setAccountTheme(String theme) {
public Stream<ClientModel> getClientsStream() {
return Stream.empty();
}

@Override
public Stream<String> getEnabledEventTypesStream() {
return Stream.empty();
}
};
}

Expand All @@ -165,6 +238,11 @@ public String getAccountTheme() {
public Stream<ClientModel> getClientsStream() {
return clients;
}

@Override
public Stream<String> getEnabledEventTypesStream() {
return Stream.empty();
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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)
.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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ private static List<String> expectedUserMetricEvents() {
if (event.name().endsWith("_ERROR")) {
continue;
}
if (event == EventType.VALIDATE_ACCESS_TOKEN) {
// event is deprecated and no longer used in the code base
if (event == EventType.UNKNOWN) {
// event is a placeholder for removed event types, should not be fired
continue;
}
String value = event.name().toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

package org.keycloak.config;

import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

import org.keycloak.events.EventType;

Expand All @@ -30,7 +31,8 @@ public class EventOptionsTest {

@Test
public void testDeprecatedArePresent() {
List<String> deprecatedValues = new ArrayList<>(EventOptions.USER_EVENT_METRICS_EVENTS.getDeprecatedMetadata().get().getDeprecatedValues());
Optional<DeprecatedMetadata> optional = EventOptions.USER_EVENT_METRICS_EVENTS.getDeprecatedMetadata();
Set<String> deprecatedValues = optional.isPresent() ? optional.get().getDeprecatedValues() : new HashSet<>();
for (EventType event : EventType.values()) {
String value = event.name().toLowerCase();
deprecatedValues.remove(value);
Expand Down
Loading
Loading
0