From 2782beafe6baf9ef0035fee9bb8a9be41b3285db Mon Sep 17 00:00:00 2001 From: Brendan Le Ny Date: Wed, 12 Jun 2024 14:47:45 +0200 Subject: [PATCH] Fix some identations and code conventions --- src/main/java/sh/libre/scim/core/Adapter.java | 10 +- .../java/sh/libre/scim/core/GroupAdapter.java | 40 +++--- .../java/sh/libre/scim/core/ScimClient.java | 121 +++++++++--------- .../sh/libre/scim/core/ScimDispatcher.java | 12 +- .../java/sh/libre/scim/core/UserAdapter.java | 32 ++--- .../scim/event/ScimEventListenerProvider.java | 20 +-- .../java/sh/libre/scim/jpa/ScimResource.java | 97 +++++++------- .../libre/scim/jpa/ScimResourceProvider.java | 3 +- .../scim/jpa/ScimResourceProviderFactory.java | 4 +- .../storage/ScimStorageProviderFactory.java | 30 ++--- 10 files changed, 182 insertions(+), 187 deletions(-) diff --git a/src/main/java/sh/libre/scim/core/Adapter.java b/src/main/java/sh/libre/scim/core/Adapter.java index d5cbb0d7a0..3c27741d77 100644 --- a/src/main/java/sh/libre/scim/core/Adapter.java +++ b/src/main/java/sh/libre/scim/core/Adapter.java @@ -1,11 +1,9 @@ package sh.libre.scim.core; -import java.util.stream.Stream; - +import de.captaingoldfish.scim.sdk.common.resources.ResourceNode; import jakarta.persistence.EntityManager; import jakarta.persistence.NoResultException; import jakarta.persistence.TypedQuery; - import org.jboss.logging.Logger; import org.keycloak.connections.jpa.JpaConnectionProvider; import org.keycloak.models.KeycloakSession; @@ -13,11 +11,11 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.RoleMapperModel; import sh.libre.scim.jpa.ScimResource; -import de.captaingoldfish.scim.sdk.common.resources.ResourceNode; +import java.util.stream.Stream; public abstract class Adapter { - protected final Logger LOGGER; + protected final Logger logger; protected final String realmId; protected final RealmModel realm; protected final String type; @@ -36,7 +34,7 @@ public abstract class Adapter this.componentId = componentId; this.em = session.getProvider(JpaConnectionProvider.class).getEntityManager(); this.type = type; - this.LOGGER = logger; + this.logger = logger; } public String getId() { diff --git a/src/main/java/sh/libre/scim/core/GroupAdapter.java b/src/main/java/sh/libre/scim/core/GroupAdapter.java index 5b5b94420a..1351fe0d95 100644 --- a/src/main/java/sh/libre/scim/core/GroupAdapter.java +++ b/src/main/java/sh/libre/scim/core/GroupAdapter.java @@ -1,20 +1,21 @@ package sh.libre.scim.core; +import de.captaingoldfish.scim.sdk.common.resources.Group; +import de.captaingoldfish.scim.sdk.common.resources.complex.Meta; +import de.captaingoldfish.scim.sdk.common.resources.multicomplex.Member; +import jakarta.persistence.NoResultException; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.jboss.logging.Logger; +import org.keycloak.models.GroupModel; +import org.keycloak.models.KeycloakSession; + import java.net.URI; import java.net.URISyntaxException; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import jakarta.persistence.NoResultException; -import de.captaingoldfish.scim.sdk.common.resources.Group; -import de.captaingoldfish.scim.sdk.common.resources.multicomplex.Member; -import de.captaingoldfish.scim.sdk.common.resources.complex.Meta; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; -import org.jboss.logging.Logger; -import org.keycloak.models.GroupModel; -import org.keycloak.models.KeycloakSession; public class GroupAdapter extends Adapter { @@ -64,7 +65,7 @@ public class GroupAdapter extends Adapter { .getSingleResult(); this.members.add(userMapping.getId()); } catch (NoResultException e) { - LOGGER.warnf("member %s not found for scim group %s", groupMember.getValue().get(), group.getId().get()); + logger.warnf("member %s not found for scim group %s", groupMember.getValue().get(), group.getId().get()); } } } @@ -81,16 +82,16 @@ public class GroupAdapter extends Adapter { var groupMember = new Member(); try { var userMapping = this.query("findById", member, "User").getSingleResult(); - LOGGER.debug(userMapping.getExternalId()); - LOGGER.debug(userMapping.getId()); + logger.debug(userMapping.getExternalId()); + logger.debug(userMapping.getId()); groupMember.setValue(userMapping.getExternalId()); var ref = new URI(String.format("Users/%s", userMapping.getExternalId())); groupMember.setRef(ref.toString()); group.addMember(groupMember); } catch (NoResultException e) { - LOGGER.warnf("member %s not found for group %s", member, id); + logger.warnf("member %s not found for group %s", member, id); } catch (URISyntaxException e) { - LOGGER.warnf("bad ref uri"); + logger.warnf("bad ref uri"); } } } @@ -99,7 +100,7 @@ public class GroupAdapter extends Adapter { var uri = new URI("Groups/" + externalId); meta.setLocation(uri.toString()); } catch (URISyntaxException e) { - LOGGER.warn(e); + logger.warn(e); } group.setMeta(meta); return group; @@ -111,16 +112,13 @@ public class GroupAdapter extends Adapter { return false; } var group = session.groups().getGroupById(realm, id); - if (group != null) { - return true; - } - return false; + return group != null; } @Override public Boolean tryToMap() { var group = session.groups().getGroupsStream(realm).filter( - x -> StringUtils.equals(x.getName(), externalId) || StringUtils.equals(x.getName(), displayName)) + x -> StringUtils.equals(x.getName(), externalId) || StringUtils.equals(x.getName(), displayName)) .findFirst(); if (group.isPresent()) { setId(group.get().getId()); @@ -141,7 +139,7 @@ public class GroupAdapter extends Adapter { } user.joinGroup(group); } catch (Exception e) { - LOGGER.warn(e); + logger.warn(e); } } } diff --git a/src/main/java/sh/libre/scim/core/ScimClient.java b/src/main/java/sh/libre/scim/core/ScimClient.java index e3b1b72c35..08c257cf6c 100644 --- a/src/main/java/sh/libre/scim/core/ScimClient.java +++ b/src/main/java/sh/libre/scim/core/ScimClient.java @@ -1,12 +1,6 @@ package sh.libre.scim.core; -import java.util.HashMap; -import java.util.Map; - -import jakarta.persistence.EntityManager; -import jakarta.persistence.NoResultException; -import jakarta.ws.rs.ProcessingException; - +import com.google.common.net.HttpHeaders; import de.captaingoldfish.scim.sdk.client.ScimClientConfig; import de.captaingoldfish.scim.sdk.client.ScimRequestBuilder; import de.captaingoldfish.scim.sdk.client.http.BasicAuth; @@ -14,7 +8,12 @@ import de.captaingoldfish.scim.sdk.client.response.ServerResponse; import de.captaingoldfish.scim.sdk.common.exceptions.ResponseException; import de.captaingoldfish.scim.sdk.common.resources.ResourceNode; import de.captaingoldfish.scim.sdk.common.response.ListResponse; - +import io.github.resilience4j.core.IntervalFunction; +import io.github.resilience4j.retry.RetryConfig; +import io.github.resilience4j.retry.RetryRegistry; +import jakarta.persistence.EntityManager; +import jakarta.persistence.NoResultException; +import jakarta.ws.rs.ProcessingException; import org.jboss.logging.Logger; import org.keycloak.component.ComponentModel; import org.keycloak.connections.jpa.JpaConnectionProvider; @@ -22,23 +21,20 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.RoleMapperModel; import org.keycloak.storage.user.SynchronizationResult; -import com.google.common.net.HttpHeaders; - -import io.github.resilience4j.core.IntervalFunction; -import io.github.resilience4j.retry.RetryConfig; -import io.github.resilience4j.retry.RetryRegistry; +import java.util.HashMap; +import java.util.Map; public class ScimClient { - final protected Logger LOGGER = Logger.getLogger(ScimClient.class); - final protected ScimRequestBuilder scimRequestBuilder; - final protected RetryRegistry registry; - final protected KeycloakSession session; - final protected String contentType; - final protected ComponentModel model; - final protected String scimApplicationBaseUrl; - final protected Map defaultHeaders; - final protected Map expectedResponseHeaders; + protected final Logger LOGGER = Logger.getLogger(ScimClient.class); + protected final ScimRequestBuilder scimRequestBuilder; + protected final RetryRegistry registry; + protected final KeycloakSession session; + protected final String contentType; + protected final ComponentModel model; + protected final String scimApplicationBaseUrl; + protected final Map defaultHeaders; + protected final Map expectedResponseHeaders; public ScimClient(ComponentModel model, KeycloakSession session) { this.model = model; @@ -51,48 +47,48 @@ public class ScimClient { switch (model.get("auth-mode")) { case "BEARER": defaultHeaders.put(HttpHeaders.AUTHORIZATION, - BearerAuthentication()); + BearerAuthentication()); break; case "BASIC_AUTH": defaultHeaders.put(HttpHeaders.AUTHORIZATION, - BasicAuthentication()); + BasicAuthentication()); break; } - defaultHeaders.put(HttpHeaders.CONTENT_TYPE,contentType); + defaultHeaders.put(HttpHeaders.CONTENT_TYPE, contentType); scimRequestBuilder = new ScimRequestBuilder(scimApplicationBaseUrl, genScimClientConfig()); RetryConfig retryConfig = RetryConfig.custom() - .maxAttempts(10) - .intervalFunction(IntervalFunction.ofExponentialBackoff()) - .retryExceptions(ProcessingException.class) - .build(); + .maxAttempts(10) + .intervalFunction(IntervalFunction.ofExponentialBackoff()) + .retryExceptions(ProcessingException.class) + .build(); registry = RetryRegistry.of(retryConfig); } protected String BasicAuthentication() { - return BasicAuth.builder() - .username(model.get("auth-user")) - .password(model.get("auth-pass")) - .build() - .getAuthorizationHeaderValue(); + return BasicAuth.builder() + .username(model.get("auth-user")) + .password(model.get("auth-pass")) + .build() + .getAuthorizationHeaderValue(); } protected ScimClientConfig genScimClientConfig() { return ScimClientConfig.builder() - .httpHeaders(defaultHeaders) - .connectTimeout(5) - .requestTimeout(5) - .socketTimeout(5) - .expectedHttpResponseHeaders(expectedResponseHeaders) - .hostnameVerifier((s, sslSession) -> true) - .build(); + .httpHeaders(defaultHeaders) + .connectTimeout(5) + .requestTimeout(5) + .socketTimeout(5) + .expectedHttpResponseHeaders(expectedResponseHeaders) + .hostnameVerifier((s, sslSession) -> true) + .build(); } protected String BearerAuthentication() { - return "Bearer " + model.get("auth-pass") ; + return "Bearer " + model.get("auth-pass"); } protected EntityManager getEM() { @@ -114,7 +110,7 @@ public class ScimClient { } public > void create(Class aClass, - M kcModel) { + M kcModel) { var adapter = getAdapter(aClass); adapter.apply(kcModel); if (adapter.skip) @@ -128,25 +124,25 @@ public class ScimClient { ServerResponse response = retry.executeSupplier(() -> { try { return scimRequestBuilder - .create(adapter.getResourceClass(), adapter.getSCIMEndpoint()) - .setResource(adapter.toSCIM()) - .sendRequest(); - } catch ( ResponseException e) { + .create(adapter.getResourceClass(), adapter.getSCIMEndpoint()) + .setResource(adapter.toSCIM()) + .sendRequest(); + } catch (ResponseException e) { throw new RuntimeException(e); } }); - if (!response.isSuccess()){ + if (!response.isSuccess()) { LOGGER.warn(response.getResponseBody()); LOGGER.warn(response.getHttpStatus()); } adapter.apply(response.getResource()); adapter.saveMapping(); - }; + } public > void replace(Class aClass, - M kcModel) { + M kcModel) { var adapter = getAdapter(aClass); try { adapter.apply(kcModel); @@ -158,15 +154,14 @@ public class ScimClient { ServerResponse response = retry.executeSupplier(() -> { try { return scimRequestBuilder - .update(adapter.getResourceClass(), adapter.getSCIMEndpoint(), adapter.getExternalId()) - .setResource(adapter.toSCIM()) - .sendRequest() ; - } catch ( ResponseException e) { - + .update(adapter.getResourceClass(), adapter.getSCIMEndpoint(), adapter.getExternalId()) + .setResource(adapter.toSCIM()) + .sendRequest(); + } catch (ResponseException e) { throw new RuntimeException(e); } }); - if (!response.isSuccess()){ + if (!response.isSuccess()) { LOGGER.warn(response.getResponseBody()); LOGGER.warn(response.getHttpStatus()); } @@ -178,7 +173,7 @@ public class ScimClient { } public > void delete(Class aClass, - String id) { + String id) { var adapter = getAdapter(aClass); adapter.setId(id); @@ -191,13 +186,13 @@ public class ScimClient { ServerResponse response = retry.executeSupplier(() -> { try { return scimRequestBuilder.delete(adapter.getResourceClass(), adapter.getSCIMEndpoint(), adapter.getExternalId()) - .sendRequest(); + .sendRequest(); } catch (ResponseException e) { throw new RuntimeException(e); } }); - if (!response.isSuccess()){ + if (!response.isSuccess()) { LOGGER.warn(response.getResponseBody()); LOGGER.warn(response.getHttpStatus()); } @@ -237,7 +232,7 @@ public class ScimClient { LOGGER.info("Import"); try { var adapter = getAdapter(aClass); - ServerResponse> response = scimRequestBuilder.list(adapter.getResourceClass(), adapter.getSCIMEndpoint()).get().sendRequest(); + ServerResponse> response = scimRequestBuilder.list(adapter.getResourceClass(), adapter.getSCIMEndpoint()).get().sendRequest(); ListResponse resourceTypeListResponse = response.getResource(); for (var resource : resourceTypeListResponse.getListedResources()) { @@ -277,8 +272,8 @@ public class ScimClient { case "DELETE_REMOTE": LOGGER.info("Delete remote resource"); scimRequestBuilder - .delete(adapter.getResourceClass(), adapter.getSCIMEndpoint(), resource.getId().get()) - .sendRequest(); + .delete(adapter.getResourceClass(), adapter.getSCIMEndpoint(), resource.getId().get()) + .sendRequest(); syncRes.increaseRemoved(); break; } @@ -295,7 +290,7 @@ public class ScimClient { } public > void sync(Class aClass, - SynchronizationResult syncRes) { + SynchronizationResult syncRes) { if (this.model.get("sync-import", false)) { this.importResources(aClass, syncRes); } diff --git a/src/main/java/sh/libre/scim/core/ScimDispatcher.java b/src/main/java/sh/libre/scim/core/ScimDispatcher.java index 293106b030..aca3e53b47 100644 --- a/src/main/java/sh/libre/scim/core/ScimDispatcher.java +++ b/src/main/java/sh/libre/scim/core/ScimDispatcher.java @@ -1,20 +1,22 @@ package sh.libre.scim.core; -import java.util.function.Consumer; - import org.apache.commons.lang3.StringUtils; import org.jboss.logging.Logger; import org.keycloak.component.ComponentModel; import org.keycloak.models.KeycloakSession; - import sh.libre.scim.storage.ScimStorageProviderFactory; +import java.util.function.Consumer; + public class ScimDispatcher { + public static final String SCOPE_USER = "user"; + public static final String SCOPE_GROUP = "group"; - final private KeycloakSession session; - final private Logger LOGGER = Logger.getLogger(ScimDispatcher.class); + private static final Logger LOGGER = Logger.getLogger(ScimDispatcher.class); + + private final KeycloakSession session; public ScimDispatcher(KeycloakSession session) { this.session = session; diff --git a/src/main/java/sh/libre/scim/core/UserAdapter.java b/src/main/java/sh/libre/scim/core/UserAdapter.java index 4d40d5590e..582f2a1ece 100644 --- a/src/main/java/sh/libre/scim/core/UserAdapter.java +++ b/src/main/java/sh/libre/scim/core/UserAdapter.java @@ -1,5 +1,16 @@ package sh.libre.scim.core; +import de.captaingoldfish.scim.sdk.common.resources.User; +import de.captaingoldfish.scim.sdk.common.resources.complex.Meta; +import de.captaingoldfish.scim.sdk.common.resources.complex.Name; +import de.captaingoldfish.scim.sdk.common.resources.multicomplex.Email; +import de.captaingoldfish.scim.sdk.common.resources.multicomplex.PersonRole; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.jboss.logging.Logger; +import org.keycloak.models.KeycloakSession; +import org.keycloak.models.UserModel; + import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -9,18 +20,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Stream; -import de.captaingoldfish.scim.sdk.common.resources.User; -import de.captaingoldfish.scim.sdk.common.resources.multicomplex.Email; -import de.captaingoldfish.scim.sdk.common.resources.complex.Name; -import de.captaingoldfish.scim.sdk.common.resources.multicomplex.PersonRole; -import de.captaingoldfish.scim.sdk.common.resources.complex.Meta; - -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; -import org.jboss.logging.Logger; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.UserModel; - public class UserAdapter extends Adapter { private String username; @@ -167,7 +166,7 @@ public class UserAdapter extends Adapter { var uri = new URI("Users/" + externalId); meta.setLocation(uri.toString()); } catch (URISyntaxException e) { - LOGGER.warn(e); + logger.warn(e); } user.setMeta(meta); List roles = new ArrayList(); @@ -197,10 +196,7 @@ public class UserAdapter extends Adapter { return false; } var user = session.users().getUserById(realm, id); - if (user != null) { - return true; - } - return false; + return user != null; } @Override @@ -215,7 +211,7 @@ public class UserAdapter extends Adapter { } if ((sameUsernameUser != null && sameEmailUser != null) && (sameUsernameUser.getId() != sameEmailUser.getId())) { - LOGGER.warnf("found 2 possible users for remote user %s %s", username, email); + logger.warnf("found 2 possible users for remote user %s %s", username, email); return false; } if (sameUsernameUser != null) { diff --git a/src/main/java/sh/libre/scim/event/ScimEventListenerProvider.java b/src/main/java/sh/libre/scim/event/ScimEventListenerProvider.java index b64cf49739..647bec7aee 100644 --- a/src/main/java/sh/libre/scim/event/ScimEventListenerProvider.java +++ b/src/main/java/sh/libre/scim/event/ScimEventListenerProvider.java @@ -1,8 +1,5 @@ package sh.libre.scim.event; -import java.util.HashMap; -import java.util.regex.Pattern; - import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.jboss.logging.Logger; @@ -15,16 +12,23 @@ import org.keycloak.events.admin.ResourceType; import org.keycloak.models.GroupModel; import org.keycloak.models.KeycloakSession; import org.keycloak.models.UserModel; - import sh.libre.scim.core.GroupAdapter; import sh.libre.scim.core.ScimDispatcher; import sh.libre.scim.core.UserAdapter; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + public class ScimEventListenerProvider implements EventListenerProvider { - final Logger LOGGER = Logger.getLogger(ScimEventListenerProvider.class); - ScimDispatcher dispatcher; - KeycloakSession session; - HashMap patterns = new HashMap(); + + private static final Logger LOGGER = Logger.getLogger(ScimEventListenerProvider.class); + + private final ScimDispatcher dispatcher; + + private final KeycloakSession session; + + private final Map patterns = new HashMap(); public ScimEventListenerProvider(KeycloakSession session) { this.session = session; diff --git a/src/main/java/sh/libre/scim/jpa/ScimResource.java b/src/main/java/sh/libre/scim/jpa/ScimResource.java index 62dbdf0ee5..1de3faa040 100644 --- a/src/main/java/sh/libre/scim/jpa/ScimResource.java +++ b/src/main/java/sh/libre/scim/jpa/ScimResource.java @@ -4,75 +4,76 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.IdClass; -import jakarta.persistence.NamedQuery; import jakarta.persistence.NamedQueries; +import jakarta.persistence.NamedQuery; import jakarta.persistence.Table; @Entity @IdClass(ScimResourceId.class) @Table(name = "SCIM_RESOURCE") @NamedQueries({ - @NamedQuery(name = "findById", query = "from ScimResource where realmId = :realmId and componentId = :componentId and type = :type and id = :id"), - @NamedQuery(name = "findByExternalId", query = "from ScimResource where realmId = :realmId and componentId = :componentId and type = :type and externalId = :id") }) + @NamedQuery(name = "findById", query = "from ScimResource where realmId = :realmId and componentId = :componentId and type = :type and id = :id"), + @NamedQuery(name = "findByExternalId", query = "from ScimResource where realmId = :realmId and componentId = :componentId and type = :type and externalId = :id") +}) public class ScimResource { - @Id - @Column(name = "ID", nullable = false) - private String id; - @Id - @Column(name = "REALM_ID", nullable = false) - private String realmId; + @Id + @Column(name = "ID", nullable = false) + private String id; - @Id - @Column(name = "COMPONENT_ID", nullable = false) - private String componentId; + @Id + @Column(name = "REALM_ID", nullable = false) + private String realmId; - @Id - @Column(name = "TYPE", nullable = false) - private String type; + @Id + @Column(name = "COMPONENT_ID", nullable = false) + private String componentId; - @Id - @Column(name = "EXTERNAL_ID", nullable = false) - private String externalId; + @Id + @Column(name = "TYPE", nullable = false) + private String type; - public String getId() { - return id; - } + @Id + @Column(name = "EXTERNAL_ID", nullable = false) + private String externalId; - public void setId(String id) { - this.id = id; - } + public String getId() { + return id; + } - public String getRealmId() { - return realmId; - } + public void setId(String id) { + this.id = id; + } - public void setRealmId(String realmId) { - this.realmId = realmId; - } + public String getRealmId() { + return realmId; + } - public String getComponentId() { - return componentId; - } + public void setRealmId(String realmId) { + this.realmId = realmId; + } - public void setComponentId(String componentId) { - this.componentId = componentId; - } + public String getComponentId() { + return componentId; + } - public String getExternalId() { - return externalId; - } + public void setComponentId(String componentId) { + this.componentId = componentId; + } - public void setExternalId(String externalId) { - this.externalId = externalId; - } + public String getExternalId() { + return externalId; + } - public String getType() { - return type; - } + public void setExternalId(String externalId) { + this.externalId = externalId; + } - public void setType(String type) { - this.type = type; - } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } } diff --git a/src/main/java/sh/libre/scim/jpa/ScimResourceProvider.java b/src/main/java/sh/libre/scim/jpa/ScimResourceProvider.java index 5da5880085..ab12d4cc43 100644 --- a/src/main/java/sh/libre/scim/jpa/ScimResourceProvider.java +++ b/src/main/java/sh/libre/scim/jpa/ScimResourceProvider.java @@ -1,10 +1,9 @@ package sh.libre.scim.jpa; -import java.util.List; - import org.keycloak.connections.jpa.entityprovider.JpaEntityProvider; import java.util.Collections; +import java.util.List; public class ScimResourceProvider implements JpaEntityProvider { diff --git a/src/main/java/sh/libre/scim/jpa/ScimResourceProviderFactory.java b/src/main/java/sh/libre/scim/jpa/ScimResourceProviderFactory.java index 682ccbee04..6f4162ed4b 100644 --- a/src/main/java/sh/libre/scim/jpa/ScimResourceProviderFactory.java +++ b/src/main/java/sh/libre/scim/jpa/ScimResourceProviderFactory.java @@ -7,7 +7,9 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSessionFactory; public class ScimResourceProviderFactory implements JpaEntityProviderFactory { - final static String ID ="scim-resource"; + + static final String ID = "scim-resource"; + @Override public void close() { } diff --git a/src/main/java/sh/libre/scim/storage/ScimStorageProviderFactory.java b/src/main/java/sh/libre/scim/storage/ScimStorageProviderFactory.java index f8df06125d..4362146015 100644 --- a/src/main/java/sh/libre/scim/storage/ScimStorageProviderFactory.java +++ b/src/main/java/sh/libre/scim/storage/ScimStorageProviderFactory.java @@ -1,12 +1,8 @@ package sh.libre.scim.storage; -import java.util.Date; -import java.util.List; - +import de.captaingoldfish.scim.sdk.common.constants.HttpHeader; import jakarta.ws.rs.core.MediaType; - import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; import org.jboss.logging.Logger; import org.keycloak.component.ComponentModel; import org.keycloak.models.KeycloakSession; @@ -20,20 +16,24 @@ import org.keycloak.storage.UserStorageProviderModel; import org.keycloak.storage.user.ImportSynchronization; import org.keycloak.storage.user.SynchronizationResult; import org.keycloak.timer.TimerProvider; - import sh.libre.scim.core.GroupAdapter; import sh.libre.scim.core.ScimDispatcher; import sh.libre.scim.core.UserAdapter; -import de.captaingoldfish.scim.sdk.common.constants.HttpHeader; +import java.util.Date; +import java.util.List; public class ScimStorageProviderFactory implements UserStorageProviderFactory, ImportSynchronization { - final private Logger LOGGER = Logger.getLogger(ScimStorageProviderFactory.class); - public final static String ID = "scim"; - protected static final List configMetadata; + + private final Logger LOGGER = Logger.getLogger(ScimStorageProviderFactory.class); + + public static final String ID = "scim"; + + private static final List CONFIG_METADATA; + static { - configMetadata = ProviderConfigurationBuilder.create() + CONFIG_METADATA = ProviderConfigurationBuilder.create() .property() .name("endpoint") .type(ProviderConfigProperty.STRING_TYPE) @@ -47,7 +47,7 @@ public class ScimStorageProviderFactory .type(ProviderConfigProperty.LIST_TYPE) .label("Endpoint content type") .helpText("Only used when endpoint doesn't support application/scim+json") - .options(MediaType.APPLICATION_JSON.toString(), HttpHeader.SCIM_CONTENT_TYPE) + .options(MediaType.APPLICATION_JSON, HttpHeader.SCIM_CONTENT_TYPE) .defaultValue(HttpHeader.SCIM_CONTENT_TYPE) .add() .property() @@ -118,12 +118,12 @@ public class ScimStorageProviderFactory @Override public List getConfigProperties() { - return configMetadata; + return CONFIG_METADATA; } @Override public SynchronizationResult sync(KeycloakSessionFactory sessionFactory, String realmId, - UserStorageProviderModel model) { + UserStorageProviderModel model) { LOGGER.info("sync"); var result = new SynchronizationResult(); KeycloakModelUtils.runJobInTransaction(sessionFactory, new KeycloakSessionTask() { @@ -149,7 +149,7 @@ public class ScimStorageProviderFactory @Override public SynchronizationResult syncSince(Date lastSync, KeycloakSessionFactory sessionFactory, String realmId, - UserStorageProviderModel model) { + UserStorageProviderModel model) { return this.sync(sessionFactory, realmId, model); }