Skip to content

Commit

Permalink
Fix identity mgmt configuration handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Aug 2, 2022
1 parent ef62f3f commit 360dd70
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ public boolean isFocusTemplateSetExplicitly() {
}

// preliminary version
public @Nullable IdentityManagementConfiguration getIdentityManagementConfiguration() {
return focusTemplate != null ?
IdentityManagementConfiguration.of(focusTemplate) :
null;
public @NotNull IdentityManagementConfiguration getIdentityManagementConfiguration() {
return IdentityManagementConfiguration.of(focusTemplate);
}

public LifecycleStateModelType getLifecycleModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public <O extends ObjectType> void applyOnElementAdd(
@NotNull O objectToAdd,
@NotNull LensElementContext<O> elementContext) throws ConfigurationException, SchemaException {
IdentityManagementConfiguration configuration = getIdentityManagementConfiguration(elementContext);
if (configuration == null) {
if (configuration == null || configuration.hasNoItems()) {
LOGGER.trace("No identity management configuration for {}: identity data will not be updated", elementContext);
return;
}
Expand All @@ -84,7 +84,7 @@ public <O extends ObjectType> void applyOnElementModify(
@NotNull Class<O> objectClass,
@NotNull LensElementContext<O> elementContext) throws SchemaException, ConfigurationException {
IdentityManagementConfiguration configuration = getIdentityManagementConfiguration(elementContext);
if (configuration == null) {
if (configuration == null || configuration.hasNoItems()) {
LOGGER.trace("No identity management configuration for {}: identity data will not be updated", elementContext);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
* Wraps all the configuration related to management of `identities` container, correlation, and so on.
Expand All @@ -35,8 +36,11 @@ private IdentityManagementConfiguration(@NotNull ObjectTemplateType objectTempla
this.objectTemplate = objectTemplate;
}

public static IdentityManagementConfiguration of(@NotNull ObjectTemplateType objectTemplate) {
return new IdentityManagementConfiguration(objectTemplate);
public static IdentityManagementConfiguration of(@Nullable ObjectTemplateType objectTemplate) {
return new IdentityManagementConfiguration(
Objects.requireNonNullElseGet(
objectTemplate,
ObjectTemplateType::new));
}

public @NotNull Collection<IdentityItemConfiguration> getItems() throws ConfigurationException {
Expand All @@ -53,11 +57,19 @@ public static IdentityManagementConfiguration of(@NotNull ObjectTemplateType obj

public @Nullable IdentityItemConfiguration getForPath(@NotNull ItemPath path) throws ConfigurationException {
for (ObjectTemplateItemDefinitionType itemDefBean : objectTemplate.getItem()) {
ItemPathType ref = itemDefBean.getRef();
if (ref != null && ref.getItemPath().equivalent(path)) {
return IdentityItemConfiguration.of(itemDefBean, itemDefBean.getIdentity());
IdentityItemDefinitionType identityBean = itemDefBean.getIdentity();
if (identityBean != null) {
ItemPathType ref = itemDefBean.getRef();
if (ref != null && ref.getItemPath().equivalent(path)) {
return IdentityItemConfiguration.of(itemDefBean, identityBean);
}
}
}
return null;
}

// TODO improve --- TODO what if empty config is legal?
public boolean hasNoItems() throws ConfigurationException {
return getItems().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class ClockworkSource extends MSource {

@NotNull private final Context context;

@NotNull private final IdentityManagementConfiguration identityManagementConfiguration;

ClockworkSource(
PrismObject<ShadowType> currentShadow,
@Nullable ObjectDelta<ShadowType> aPrioriDelta,
Expand All @@ -67,6 +69,8 @@ class ClockworkSource extends MSource {
this.projectionContext = projectionContext;
this.context = context;
this.beans = context.beans;
this.identityManagementConfiguration =
projectionContext.getLensContext().getFocusContext().getIdentityManagementConfiguration();
}

@Override
Expand Down Expand Up @@ -357,10 +361,7 @@ <V extends PrismValue, D extends ItemDefinition<?>> InboundMappingInContext<V, D

@Override
@Nullable IdentityItemConfiguration getIdentityItemConfiguration(@NotNull ItemPath itemPath) throws ConfigurationException {
IdentityManagementConfiguration identityManagementConfiguration =
getFocusContext().getIdentityManagementConfiguration();
return identityManagementConfiguration != null ?
identityManagementConfiguration.getForPath(itemPath) : null;
return identityManagementConfiguration.getForPath(itemPath);
}

private @NotNull LensFocusContext<? extends ObjectType> getFocusContext() {
Expand Down

0 comments on commit 360dd70

Please sign in to comment.