Remove unnecessary AbstractConfigPropertySynchronizer class (#33002)

Closes #33000

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
This commit is contained in:
Stefan Guilhen 2024-09-18 03:58:32 -03:00 committed by GitHub
parent da5fd31a5f
commit 5ff9e9147d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 53 deletions

View file

@ -1,45 +0,0 @@
/*
* Copyright 2022 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.broker.provider.mappersync;
import org.jboss.logging.Logger;
import org.keycloak.models.IdentityProviderMapperModel;
import org.keycloak.models.RealmModel;
import org.keycloak.provider.ProviderEvent;
import org.keycloak.utils.StringUtil;
import java.util.Map;
import java.util.function.Consumer;
/**
* Abstract base class for updating a single reference (specified via a single config property).
*
* @author <a href="mailto:daniel.fesenmeyer@bosch.io">Daniel Fesenmeyer</a>
*/
public abstract class AbstractConfigPropertySynchronizer<T extends ProviderEvent> implements ConfigSynchronizer<T> {
private static final Logger LOG = Logger.getLogger(AbstractConfigPropertySynchronizer.class);
protected void logEventProcessed(String configPropertyName, String previousValue, String newValue, String realmName,
String mapperName, String idpAlias) {
LOG.infof(
"Reference of type '%s' changed from '%s' to '%s' in realm '%s'. Adjusting the reference from mapper '%s' of IDP '%s'.",
configPropertyName, previousValue, newValue, realmName, mapperName, idpAlias);
}
}

View file

@ -17,6 +17,7 @@
package org.keycloak.broker.provider.mappersync;
import org.jboss.logging.Logger;
import org.keycloak.models.IdentityProviderMapperModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
@ -28,7 +29,17 @@ import org.keycloak.provider.ProviderEvent;
* @author <a href="mailto:daniel.fesenmeyer@bosch.io">Daniel Fesenmeyer</a>
*/
public interface ConfigSynchronizer<T extends ProviderEvent> {
Logger LOG = Logger.getLogger(ConfigSynchronizer.class);
Class<T> getEventClass();
void handleEvent(T event);
default void logEventProcessed(String configPropertyName, String previousValue, String newValue, String realmName,
String mapperName, String idpAlias) {
LOG.infof(
"Reference of type '%s' changed from '%s' to '%s' in realm '%s'. Adjusting the reference from mapper '%s' of IDP '%s'.",
configPropertyName, previousValue, newValue, realmName, mapperName, idpAlias);
}
}

View file

@ -33,7 +33,7 @@ import static org.keycloak.models.utils.KeycloakModelUtils.GROUP_PATH_SEPARATOR;
*
* @author <a href="mailto:daniel.fesenmeyer@bosch.io">Daniel Fesenmeyer</a>
*/
public class GroupConfigPropertyByPathSynchronizer extends AbstractConfigPropertySynchronizer<GroupModel.GroupPathChangeEvent> {
public class GroupConfigPropertyByPathSynchronizer implements ConfigSynchronizer<GroupModel.GroupPathChangeEvent> {
public static final GroupConfigPropertyByPathSynchronizer INSTANCE = new GroupConfigPropertyByPathSynchronizer();
@ -53,7 +53,7 @@ public class GroupConfigPropertyByPathSynchronizer extends AbstractConfigPropert
event.getKeycloakSession().identityProviders().getMappersStream(Map.of(ConfigConstants.GROUP, event.getPreviousPath()), null, null)
.forEach(idpMapper -> {
idpMapper.getConfig().put(ConfigConstants.GROUP, event.getNewPath());
super.logEventProcessed(ConfigConstants.GROUP, event.getPreviousPath(), event.getNewPath(), event.getRealm().getName(),
logEventProcessed(ConfigConstants.GROUP, event.getPreviousPath(), event.getNewPath(), event.getRealm().getName(),
idpMapper.getName(), idpMapper.getIdentityProviderAlias());
event.getKeycloakSession().identityProviders().updateMapper(idpMapper);
});
@ -65,7 +65,7 @@ public class GroupConfigPropertyByPathSynchronizer extends AbstractConfigPropert
String currentGroupPath = idpMapper.getConfig().get(ConfigConstants.GROUP);
String newGroupPath = event.getNewPath() + currentGroupPath.substring(event.getPreviousPath().length());
idpMapper.getConfig().put(ConfigConstants.GROUP, newGroupPath);
super.logEventProcessed(ConfigConstants.GROUP, currentGroupPath, newGroupPath, event.getRealm().getName(),
logEventProcessed(ConfigConstants.GROUP, currentGroupPath, newGroupPath, event.getRealm().getName(),
idpMapper.getName(), idpMapper.getIdentityProviderAlias());
event.getKeycloakSession().identityProviders().updateMapper(idpMapper);
});

View file

@ -31,7 +31,7 @@ import java.util.function.Consumer;
*
* @author <a href="mailto:daniel.fesenmeyer@bosch.io">Daniel Fesenmeyer</a>
*/
public class RoleConfigPropertyByClientIdSynchronizer extends AbstractConfigPropertySynchronizer<ClientModel.ClientIdChangeEvent> {
public class RoleConfigPropertyByClientIdSynchronizer implements ConfigSynchronizer<ClientModel.ClientIdChangeEvent> {
public static final RoleConfigPropertyByClientIdSynchronizer INSTANCE =
new RoleConfigPropertyByClientIdSynchronizer();
@ -54,7 +54,7 @@ public class RoleConfigPropertyByClientIdSynchronizer extends AbstractConfigProp
String configuredRoleName = KeycloakModelUtils.parseRole(currentRoleValue)[1];
String newRoleValue = KeycloakModelUtils.buildRoleQualifier(event.getNewClientId(), configuredRoleName);
idpMapper.getConfig().put(ConfigConstants.ROLE, newRoleValue);
super.logEventProcessed(ConfigConstants.ROLE, currentRoleValue, newRoleValue, event.getUpdatedClient().getRealm().getName(),
logEventProcessed(ConfigConstants.ROLE, currentRoleValue, newRoleValue, event.getUpdatedClient().getRealm().getName(),
idpMapper.getName(), idpMapper.getIdentityProviderAlias());
event.getKeycloakSession().identityProviders().updateMapper(idpMapper);
});

View file

@ -31,8 +31,7 @@ import java.util.function.Consumer;
*
* @author <a href="mailto:daniel.fesenmeyer@bosch.io">Daniel Fesenmeyer</a>
*/
public class RoleConfigPropertyByRoleNameSynchronizer
extends AbstractConfigPropertySynchronizer<RoleModel.RoleNameChangeEvent> {
public class RoleConfigPropertyByRoleNameSynchronizer implements ConfigSynchronizer<RoleModel.RoleNameChangeEvent> {
public static final RoleConfigPropertyByRoleNameSynchronizer INSTANCE =
new RoleConfigPropertyByRoleNameSynchronizer();
@ -54,7 +53,7 @@ public class RoleConfigPropertyByRoleNameSynchronizer
.forEach(idpMapper -> {
String newRoleValue = KeycloakModelUtils.buildRoleQualifier(event.getClientId(), event.getNewName());
idpMapper.getConfig().put(ConfigConstants.ROLE, newRoleValue);
super.logEventProcessed(ConfigConstants.ROLE, currentRoleValue, newRoleValue, event.getRealm().getName(),
logEventProcessed(ConfigConstants.ROLE, currentRoleValue, newRoleValue, event.getRealm().getName(),
idpMapper.getName(), idpMapper.getIdentityProviderAlias());
event.getKeycloakSession().identityProviders().updateMapper(idpMapper);
});