Fix some identations and code conventions
This commit is contained in:
parent
000b47a581
commit
2782beafe6
10 changed files with 182 additions and 187 deletions
|
@ -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<M extends RoleMapperModel, S extends ResourceNode> {
|
||||
|
||||
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<M extends RoleMapperModel, S extends ResourceNode>
|
|||
this.componentId = componentId;
|
||||
this.em = session.getProvider(JpaConnectionProvider.class).getEntityManager();
|
||||
this.type = type;
|
||||
this.LOGGER = logger;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
|
|
@ -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<GroupModel, Group> {
|
||||
|
||||
|
@ -64,7 +65,7 @@ public class GroupAdapter extends Adapter<GroupModel, Group> {
|
|||
.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<GroupModel, Group> {
|
|||
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<GroupModel, Group> {
|
|||
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,10 +112,7 @@ public class GroupAdapter extends Adapter<GroupModel, Group> {
|
|||
return false;
|
||||
}
|
||||
var group = session.groups().getGroupById(realm, id);
|
||||
if (group != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return group != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,7 +139,7 @@ public class GroupAdapter extends Adapter<GroupModel, Group> {
|
|||
}
|
||||
user.joinGroup(group);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn(e);
|
||||
logger.warn(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, String> defaultHeaders;
|
||||
final protected Map<String, String> 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<String, String> defaultHeaders;
|
||||
protected final Map<String, String> expectedResponseHeaders;
|
||||
|
||||
public ScimClient(ComponentModel model, KeycloakSession session) {
|
||||
this.model = model;
|
||||
|
@ -59,7 +55,7 @@ public class ScimClient {
|
|||
break;
|
||||
}
|
||||
|
||||
defaultHeaders.put(HttpHeaders.CONTENT_TYPE,contentType);
|
||||
defaultHeaders.put(HttpHeaders.CONTENT_TYPE, contentType);
|
||||
|
||||
scimRequestBuilder = new ScimRequestBuilder(scimApplicationBaseUrl, genScimClientConfig());
|
||||
|
||||
|
@ -92,7 +88,7 @@ public class ScimClient {
|
|||
}
|
||||
|
||||
protected String BearerAuthentication() {
|
||||
return "Bearer " + model.get("auth-pass") ;
|
||||
return "Bearer " + model.get("auth-pass");
|
||||
}
|
||||
|
||||
protected EntityManager getEM() {
|
||||
|
@ -131,19 +127,19 @@ public class ScimClient {
|
|||
.create(adapter.getResourceClass(), adapter.getSCIMEndpoint())
|
||||
.setResource(adapter.toSCIM())
|
||||
.sendRequest();
|
||||
} catch ( ResponseException e) {
|
||||
} 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 <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void replace(Class<A> aClass,
|
||||
M kcModel) {
|
||||
|
@ -160,13 +156,12 @@ public class ScimClient {
|
|||
return scimRequestBuilder
|
||||
.update(adapter.getResourceClass(), adapter.getSCIMEndpoint(), adapter.getExternalId())
|
||||
.setResource(adapter.toSCIM())
|
||||
.sendRequest() ;
|
||||
} catch ( ResponseException e) {
|
||||
|
||||
.sendRequest();
|
||||
} catch (ResponseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
if (!response.isSuccess()){
|
||||
if (!response.isSuccess()) {
|
||||
LOGGER.warn(response.getResponseBody());
|
||||
LOGGER.warn(response.getHttpStatus());
|
||||
}
|
||||
|
@ -197,7 +192,7 @@ public class ScimClient {
|
|||
}
|
||||
});
|
||||
|
||||
if (!response.isSuccess()){
|
||||
if (!response.isSuccess()) {
|
||||
LOGGER.warn(response.getResponseBody());
|
||||
LOGGER.warn(response.getHttpStatus());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<UserModel, User> {
|
||||
|
||||
private String username;
|
||||
|
@ -167,7 +166,7 @@ public class UserAdapter extends Adapter<UserModel, User> {
|
|||
var uri = new URI("Users/" + externalId);
|
||||
meta.setLocation(uri.toString());
|
||||
} catch (URISyntaxException e) {
|
||||
LOGGER.warn(e);
|
||||
logger.warn(e);
|
||||
}
|
||||
user.setMeta(meta);
|
||||
List<PersonRole> roles = new ArrayList<PersonRole>();
|
||||
|
@ -197,10 +196,7 @@ public class UserAdapter extends Adapter<UserModel, User> {
|
|||
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<UserModel, User> {
|
|||
}
|
||||
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) {
|
||||
|
|
|
@ -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<ResourceType, Pattern> patterns = new HashMap<ResourceType, Pattern>();
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ScimEventListenerProvider.class);
|
||||
|
||||
private final ScimDispatcher dispatcher;
|
||||
|
||||
private final KeycloakSession session;
|
||||
|
||||
private final Map<ResourceType, Pattern> patterns = new HashMap<ResourceType, Pattern>();
|
||||
|
||||
public ScimEventListenerProvider(KeycloakSession session) {
|
||||
this.session = session;
|
||||
|
|
|
@ -4,8 +4,8 @@ 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
|
||||
|
@ -13,8 +13,10 @@ import jakarta.persistence.Table;
|
|||
@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 = "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;
|
||||
|
@ -74,5 +76,4 @@ public class ScimResource {
|
|||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
|
|
|
@ -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<ScimStorageProvider>, ImportSynchronization {
|
||||
final private Logger LOGGER = Logger.getLogger(ScimStorageProviderFactory.class);
|
||||
public final static String ID = "scim";
|
||||
protected static final List<ProviderConfigProperty> configMetadata;
|
||||
|
||||
private final Logger LOGGER = Logger.getLogger(ScimStorageProviderFactory.class);
|
||||
|
||||
public static final String ID = "scim";
|
||||
|
||||
private static final List<ProviderConfigProperty> 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,7 +118,7 @@ public class ScimStorageProviderFactory
|
|||
|
||||
@Override
|
||||
public List<ProviderConfigProperty> getConfigProperties() {
|
||||
return configMetadata;
|
||||
return CONFIG_METADATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue