Use switch statements
This commit is contained in:
parent
26dc5edba2
commit
33bc30667d
1 changed files with 71 additions and 61 deletions
|
@ -45,16 +45,20 @@ public class ScimEventListenerProvider implements EventListenerProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(Event event) {
|
public void onEvent(Event event) {
|
||||||
if (event.getType() == EventType.REGISTER) {
|
EventType eventType = event.getType();
|
||||||
var user = getUser(event.getUserId());
|
String eventUserId = event.getUserId();
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.create(UserAdapter.class, user));
|
switch (eventType) {
|
||||||
}
|
case REGISTER -> {
|
||||||
if (event.getType() == EventType.UPDATE_EMAIL || event.getType() == EventType.UPDATE_PROFILE) {
|
var user = getUser(eventUserId);
|
||||||
var user = getUser(event.getUserId());
|
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.create(UserAdapter.class, user));
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.replace(UserAdapter.class, user));
|
}
|
||||||
}
|
case UPDATE_EMAIL, UPDATE_PROFILE -> {
|
||||||
if (event.getType() == EventType.DELETE_ACCOUNT) {
|
var user = getUser(eventUserId);
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.delete(UserAdapter.class, event.getUserId()));
|
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.replace(UserAdapter.class, user));
|
||||||
|
}
|
||||||
|
case DELETE_ACCOUNT ->
|
||||||
|
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.delete(UserAdapter.class, eventUserId));
|
||||||
|
default -> LOGGER.trace("ignore event " + eventType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,61 +70,67 @@ public class ScimEventListenerProvider implements EventListenerProvider {
|
||||||
var matcher = pattern.matcher(event.getResourcePath());
|
var matcher = pattern.matcher(event.getResourcePath());
|
||||||
if (!matcher.find())
|
if (!matcher.find())
|
||||||
return;
|
return;
|
||||||
if (event.getResourceType() == ResourceType.USER) {
|
switch (event.getResourceType()) {
|
||||||
var userId = matcher.group(1);
|
case USER -> {
|
||||||
LOGGER.infof("%s %s", userId, event.getOperationType());
|
var userId = matcher.group(1);
|
||||||
if (event.getOperationType() == OperationType.CREATE) {
|
LOGGER.infof("%s %s", userId, event.getOperationType());
|
||||||
var user = getUser(userId);
|
switch (event.getOperationType()) {
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.create(UserAdapter.class, user));
|
case CREATE -> {
|
||||||
user.getGroupsStream().forEach(group -> {
|
var user = getUser(userId);
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_GROUP, (client) -> client.replace(GroupAdapter.class, group));
|
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.create(UserAdapter.class, user));
|
||||||
});
|
user.getGroupsStream().forEach(group -> {
|
||||||
|
dispatcher.run(ScimDispatcher.SCOPE_GROUP, (client) -> client.replace(GroupAdapter.class, group));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
case UPDATE -> {
|
||||||
|
var user = getUser(userId);
|
||||||
|
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.replace(UserAdapter.class, user));
|
||||||
|
}
|
||||||
|
case DELETE ->
|
||||||
|
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.delete(UserAdapter.class, userId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (event.getOperationType() == OperationType.UPDATE) {
|
case GROUP -> {
|
||||||
|
var groupId = matcher.group(1);
|
||||||
|
LOGGER.infof("group %s %s", groupId, event.getOperationType());
|
||||||
|
switch (event.getOperationType()) {
|
||||||
|
case CREATE -> {
|
||||||
|
var group = getGroup(groupId);
|
||||||
|
dispatcher.run(ScimDispatcher.SCOPE_GROUP, (client) -> client.create(GroupAdapter.class, group));
|
||||||
|
}
|
||||||
|
case UPDATE -> {
|
||||||
|
var group = getGroup(groupId);
|
||||||
|
dispatcher.run(ScimDispatcher.SCOPE_GROUP, (client) -> client.replace(GroupAdapter.class, group));
|
||||||
|
}
|
||||||
|
case DELETE -> dispatcher.run(ScimDispatcher.SCOPE_GROUP,
|
||||||
|
(client) -> client.delete(GroupAdapter.class, groupId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case GROUP_MEMBERSHIP -> {
|
||||||
|
var userId = matcher.group(1);
|
||||||
|
var groupId = matcher.group(2);
|
||||||
|
LOGGER.infof("%s %s from %s", event.getOperationType(), userId, groupId);
|
||||||
|
var group = getGroup(groupId);
|
||||||
|
group.setSingleAttribute("scim-dirty", BooleanUtils.TRUE);
|
||||||
var user = getUser(userId);
|
var user = getUser(userId);
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.replace(UserAdapter.class, user));
|
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.replace(UserAdapter.class, user));
|
||||||
}
|
}
|
||||||
if (event.getOperationType() == OperationType.DELETE) {
|
case REALM_ROLE_MAPPING -> {
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.delete(UserAdapter.class, userId));
|
var type = matcher.group(1);
|
||||||
}
|
var id = matcher.group(2);
|
||||||
}
|
LOGGER.infof("%s %s %s roles", event.getOperationType(), type, id);
|
||||||
if (event.getResourceType() == ResourceType.GROUP) {
|
switch (type) {
|
||||||
var groupId = matcher.group(1);
|
case "users" -> {
|
||||||
LOGGER.infof("group %s %s", groupId, event.getOperationType());
|
var user = getUser(id);
|
||||||
if (event.getOperationType() == OperationType.CREATE) {
|
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.replace(UserAdapter.class, user));
|
||||||
var group = getGroup(groupId);
|
}
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_GROUP, (client) -> client.create(GroupAdapter.class, group));
|
case "groups" -> {
|
||||||
}
|
var group = getGroup(id);
|
||||||
if (event.getOperationType() == OperationType.UPDATE) {
|
session.users().getGroupMembersStream(session.getContext().getRealm(), group).forEach(user -> {
|
||||||
var group = getGroup(groupId);
|
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.replace(UserAdapter.class, user));
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_GROUP, (client) -> client.replace(GroupAdapter.class, group));
|
});
|
||||||
}
|
}
|
||||||
if (event.getOperationType() == OperationType.DELETE) {
|
}
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_GROUP,
|
|
||||||
(client) -> client.delete(GroupAdapter.class, groupId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (event.getResourceType() == ResourceType.GROUP_MEMBERSHIP) {
|
|
||||||
var userId = matcher.group(1);
|
|
||||||
var groupId = matcher.group(2);
|
|
||||||
LOGGER.infof("%s %s from %s", event.getOperationType(), userId, groupId);
|
|
||||||
var group = getGroup(groupId);
|
|
||||||
group.setSingleAttribute("scim-dirty", BooleanUtils.TRUE);
|
|
||||||
var user = getUser(userId);
|
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.replace(UserAdapter.class, user));
|
|
||||||
}
|
|
||||||
if (event.getResourceType() == ResourceType.REALM_ROLE_MAPPING) {
|
|
||||||
var type = matcher.group(1);
|
|
||||||
var id = matcher.group(2);
|
|
||||||
LOGGER.infof("%s %s %s roles", event.getOperationType(), type, id);
|
|
||||||
if (StringUtils.equals(type, "users")) {
|
|
||||||
var user = getUser(id);
|
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.replace(UserAdapter.class, user));
|
|
||||||
} else if (StringUtils.equals(type, "groups")) {
|
|
||||||
var group = getGroup(id);
|
|
||||||
session.users().getGroupMembersStream(session.getContext().getRealm(), group).forEach(user -> {
|
|
||||||
dispatcher.run(ScimDispatcher.SCOPE_USER, (client) -> client.replace(UserAdapter.class, user));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue