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,16 +112,13 @@ 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
|
||||
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<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;
|
||||
|
@ -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 <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void create(Class<A> aClass,
|
||||
M kcModel) {
|
||||
M kcModel) {
|
||||
var adapter = getAdapter(aClass);
|
||||
adapter.apply(kcModel);
|
||||
if (adapter.skip)
|
||||
|
@ -128,25 +124,25 @@ public class ScimClient {
|
|||
ServerResponse<S> 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 <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void replace(Class<A> aClass,
|
||||
M kcModel) {
|
||||
M kcModel) {
|
||||
var adapter = getAdapter(aClass);
|
||||
try {
|
||||
adapter.apply(kcModel);
|
||||
|
@ -158,15 +154,14 @@ public class ScimClient {
|
|||
ServerResponse<S> 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 <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void delete(Class<A> aClass,
|
||||
String id) {
|
||||
String id) {
|
||||
var adapter = getAdapter(aClass);
|
||||
adapter.setId(id);
|
||||
|
||||
|
@ -191,13 +186,13 @@ public class ScimClient {
|
|||
ServerResponse<S> 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<ListResponse<S>> response = scimRequestBuilder.list(adapter.getResourceClass(), adapter.getSCIMEndpoint()).get().sendRequest();
|
||||
ServerResponse<ListResponse<S>> response = scimRequestBuilder.list(adapter.getResourceClass(), adapter.getSCIMEndpoint()).get().sendRequest();
|
||||
ListResponse<S> 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 <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void sync(Class<A> aClass,
|
||||
SynchronizationResult syncRes) {
|
||||
SynchronizationResult syncRes) {
|
||||
if (this.model.get("sync-import", false)) {
|
||||
this.importResources(aClass, syncRes);
|
||||
}
|
||||
|
|
|
@ -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,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,12 +118,12 @@ public class ScimStorageProviderFactory
|
|||
|
||||
@Override
|
||||
public List<ProviderConfigProperty> 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue