Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/support-4.0' into s…
Browse files Browse the repository at this point in the history
…upport-4.0
  • Loading branch information
skublik committed Mar 16, 2020
2 parents 8ff2534 + 3ae6466 commit 4172793
Show file tree
Hide file tree
Showing 101 changed files with 4,559 additions and 3,981 deletions.
Expand Up @@ -1048,6 +1048,10 @@ public void recordNotApplicableIfUnknown() {
}
}

public void recordNotApplicable() {
recordStatus(OperationResultStatus.NOT_APPLICABLE, (String) null);
}

public boolean isMinor() {
return importance == MINOR;
}
Expand Down
Expand Up @@ -168,10 +168,13 @@
<xsd:annotation>
<xsd:documentation>
Reference to the task holding workflow context for wf-related cases.
EXPERIMENTAL. Probably will be removed.
DEPRECATED. Not used any more. The relation is defined the other way:
task.objectRef points to this case.
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:TaskType</a:objectReferenceTargetType>
<a:deprecated>true</a:deprecated>
<a:deprecatedSince>4.0.3</a:deprecatedSince>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Expand Down
Expand Up @@ -62,6 +62,18 @@ static String prettyPrintElementAsProperty(Object element) {
return sb.toString();
}

public static Object prettyPrintLazily(Collection<?> collection) {
if (collection == null) {
return null;
}
return new Object() {
@Override
public String toString() {
return prettyPrint(collection);
}
};
}

public static String prettyPrint(Collection<?> collection) {
return prettyPrint(collection, 0);
}
Expand Down
Expand Up @@ -834,7 +834,7 @@ public PrismObject<O> getObjectCurrentOrOld() {

@Override
public boolean isOfType(Class<?> aClass) {
if (objectTypeClass != null && aClass.isAssignableFrom(objectTypeClass)) {
if (aClass.isAssignableFrom(objectTypeClass)) {
return true;
}
PrismObject<O> object = getObjectAny();
Expand Down
Expand Up @@ -1326,7 +1326,10 @@ private <F extends ObjectType> void finishLoadOfProjectionContext(LensContext<F>
//Determine refined schema and password policies for account type
RefinedObjectClassDefinition structuralObjectClassDef = projContext.getStructuralObjectClassDefinition();
if (structuralObjectClassDef != null) {
loadProjectionSecurityPolicy(context, projContext, task, result);
LOGGER.trace("Finishing loading of projection context: security policy");
SecurityPolicyType projectionSecurityPolicy = securityHelper.locateProjectionSecurityPolicy(projContext.getStructuralObjectClassDefinition(), task, result);
LOGGER.trace("Located security policy for: {},\n {}", projContext, projectionSecurityPolicy);
projContext.setProjectionSecurityPolicy(projectionSecurityPolicy);
} else {
LOGGER.trace("No structural object class definition, skipping determining security policy");
}
Expand All @@ -1343,51 +1346,6 @@ private <F extends ObjectType> void finishLoadOfProjectionContext(LensContext<F>
setPrimaryDeltaOldValue(projContext);
}

private <F extends ObjectType> void loadProjectionSecurityPolicy(LensContext<F> context,
LensProjectionContext projContext, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
LOGGER.trace("Finishing loading of projection context: security policy");
ObjectReferenceType securityPolicyRef = projContext.getStructuralObjectClassDefinition().getSecurityPolicyRef();
if (securityPolicyRef == null || securityPolicyRef.getOid() == null) {
LOGGER.trace("Security policy not defined for the projection context.");
loadProjectionLegacyPasswordPolicy(context, projContext, task, result);
return;
}
LOGGER.trace("Loading security policy {} for projection context: {}", securityPolicyRef, projContext);
PrismObject<SecurityPolicyType> securityPolicy = cacheRepositoryService.getObject(SecurityPolicyType.class, securityPolicyRef.getOid(), null, result);
if (securityPolicy == null) {
LOGGER.debug("Security policy {} defined for the projection does not exist", securityPolicyRef);
return;
}
LOGGER.trace("Found legacy password policy: {}", securityPolicy);
projContext.setProjectionSecurityPolicy(securityPolicy.asObjectable());
}


private <F extends ObjectType> void loadProjectionLegacyPasswordPolicy(LensContext<F> context,
LensProjectionContext projContext, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
ObjectReferenceType passwordPolicyRef = projContext.getStructuralObjectClassDefinition().getPasswordPolicy();
if (passwordPolicyRef == null || passwordPolicyRef.getOid() == null) {
LOGGER.trace("Legacy password policy not defined for the projection context.");
return;
}
LOGGER.trace("Loading legacy password policy {} for projection context: {}", passwordPolicyRef, projContext);
PrismObject<ValuePolicyType> passwordPolicy = cacheRepositoryService.getObject(
ValuePolicyType.class, passwordPolicyRef.getOid(), null, result);
if (passwordPolicy == null) {
LOGGER.debug("Legacy password policy {} defined for the projection does not exist", passwordPolicyRef);
return;
}
ObjectReferenceType dummyPasswordPolicyRef = new ObjectReferenceType();
dummyPasswordPolicyRef.asReferenceValue().setObject(passwordPolicy);
PrismObject<SecurityPolicyType> securityPolicy = prismContext.createObject(SecurityPolicyType.class);
securityPolicy.asObjectable()
.beginCredentials()
.beginPassword()
.valuePolicyRef(dummyPasswordPolicyRef);
projContext.setProjectionSecurityPolicy(securityPolicy.asObjectable());
}


private <F extends ObjectType> boolean needToReload(LensContext<F> context,
LensProjectionContext projContext) {
ResourceShadowDiscriminator discr = projContext.getResourceShadowDiscriminator();
Expand Down
Expand Up @@ -142,39 +142,27 @@ private <F extends AssignmentHolderType> void processAssignmentActivation(LensCo
// We care only about existing assignments here. New assignments will be taken care of in the executor
// (OperationalDataProcessor). And why care about deleted assignments?
Collection<EvaluatedAssignmentImpl<?>> zeroSet = evaluatedAssignmentTriple.getZeroSet();
if (zeroSet == null) {
return;
}
LensFocusContext<F> focusContext = context.getFocusContext();
for (EvaluatedAssignmentImpl<?> evaluatedAssignment: zeroSet) {
if (evaluatedAssignment.isVirtual()) {
continue;
}
AssignmentType assignmentType = evaluatedAssignment.getAssignmentType();
ActivationType currentActivationType = assignmentType.getActivation();
ActivationStatusType expectedEffectiveStatus = activationComputer.getEffectiveStatus(assignmentType.getLifecycleState(), currentActivationType, null);
if (currentActivationType == null) {
PrismContainerDefinition<ActivationType> activationDef = focusContext.getObjectDefinition().findContainerDefinition(SchemaConstants.PATH_ASSIGNMENT_ACTIVATION);
ContainerDelta<ActivationType> activationDelta = activationDef.createEmptyDelta(
ItemPath.create(FocusType.F_ASSIGNMENT, assignmentType.getId(), AssignmentType.F_ACTIVATION));
ActivationType newActivationType = new ActivationType();
activationDelta.setValuesToReplace(newActivationType.asPrismContainerValue());
newActivationType.setEffectiveStatus(expectedEffectiveStatus);
focusContext.swallowToSecondaryDelta(activationDelta);
} else {
ActivationStatusType currentEffectiveStatus = currentActivationType.getEffectiveStatus();
if (!expectedEffectiveStatus.equals(currentEffectiveStatus)) {
PrismPropertyDefinition<ActivationStatusType> effectiveStatusPropertyDef = focusContext.getObjectDefinition().findPropertyDefinition(SchemaConstants.PATH_ASSIGNMENT_ACTIVATION_EFFECTIVE_STATUS);
PropertyDelta<ActivationStatusType> effectiveStatusDelta = effectiveStatusPropertyDef.createEmptyDelta(
ItemPath.create(FocusType.F_ASSIGNMENT, assignmentType.getId(), AssignmentType.F_ACTIVATION, ActivationType.F_EFFECTIVE_STATUS));
effectiveStatusDelta.setRealValuesToReplace(expectedEffectiveStatus);
focusContext.swallowToSecondaryDelta(effectiveStatusDelta);
}
AssignmentType assignment = evaluatedAssignment.getAssignmentType();
ActivationType currentActivation = assignment.getActivation();
ActivationStatusType currentEffectiveStatus = currentActivation != null ? currentActivation.getEffectiveStatus() : null;
ActivationStatusType expectedEffectiveStatus = activationComputer.getEffectiveStatus(assignment.getLifecycleState(),
currentActivation, null);
if (currentEffectiveStatus != expectedEffectiveStatus) {
PrismPropertyDefinition<ActivationStatusType> effectiveStatusPropertyDef = focusContext.getObjectDefinition()
.findPropertyDefinition(SchemaConstants.PATH_ASSIGNMENT_ACTIVATION_EFFECTIVE_STATUS);
PropertyDelta<ActivationStatusType> effectiveStatusDelta = effectiveStatusPropertyDef.createEmptyDelta(
ItemPath.create(FocusType.F_ASSIGNMENT, assignment.getId(), AssignmentType.F_ACTIVATION, ActivationType.F_EFFECTIVE_STATUS));
effectiveStatusDelta.setRealValuesToReplace(expectedEffectiveStatus);
focusContext.swallowToSecondaryDelta(effectiveStatusDelta);
}
}
}


private <F extends FocusType> void processActivationAdministrativeAndValidity(LensFocusContext<F> focusContext, XMLGregorianCalendar now,
OperationResult result)
throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException {
Expand Down
Expand Up @@ -13,16 +13,14 @@
import com.evolveum.midpoint.model.api.PipelineItem;
import com.evolveum.midpoint.notifications.api.NotificationManager;
import com.evolveum.midpoint.notifications.api.events.CustomEvent;
import com.evolveum.midpoint.notifications.api.events.Event;
import com.evolveum.midpoint.notifications.api.events.factory.CustomEventFactory;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.LightweightIdentifierGenerator;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventHandlerType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventOperationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventStatusType;
import com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -34,13 +32,11 @@
@Component
public class NotifyExecutor extends BaseActionExecutor {

@Autowired
private LightweightIdentifierGenerator lightweightIdentifierGenerator;

@Autowired(required = false) // During some tests this might be unavailable
private NotificationManager notificationManager;

private static final Trace LOGGER = TraceManager.getTrace(NotifyExecutor.class);
@Autowired(required = false)
private CustomEventFactory customEventFactory;

private static final String NAME = "notify";
private static final String PARAM_SUBTYPE = "subtype";
Expand Down Expand Up @@ -80,18 +76,21 @@ public PipelineData execute(ActionExpressionType expression, PipelineData input,
if (notificationManager == null) {
throw new IllegalStateException("Notification manager is unavailable");
}
if (customEventFactory == null) {
throw new IllegalStateException("Custom event factory is unavailable");
}

int eventCount = 0;
if (forWholeInput) {
Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, input.getData(), operation, status, context.getChannel());
CustomEvent event = customEventFactory.createEvent(subtype, handler, input.getData(), operation, status, context.getChannel());
notificationManager.processEvent(event, context.getTask(), globalResult);
eventCount++;
} else {
for (PipelineItem item: input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, value, operation, status, context.getChannel());
CustomEvent event = customEventFactory.createEvent(subtype, handler, value, operation, status, context.getChannel());
notificationManager.processEvent(event, context.getTask(), result);
eventCount++;
operationsHelper.trimAndCloneResult(result, globalResult, context);
Expand Down
Expand Up @@ -9,8 +9,10 @@
import javax.xml.datatype.Duration;
import javax.xml.soap.SOAPMessage;

import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.model.api.ModelAuditRecorder;
import com.evolveum.midpoint.model.impl.util.AuditHelper;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.security.api.HttpConnectionInformation;
import com.evolveum.midpoint.security.enforcer.api.SecurityEnforcer;

Expand Down Expand Up @@ -74,6 +76,7 @@ public class SecurityHelper implements ModelAuditRecorder {
@Autowired private AuditHelper auditHelper;
@Autowired private ModelObjectResolver objectResolver;
@Autowired private SecurityEnforcer securityEnforcer;
@Autowired private PrismContext prismContext;

@Override
public void auditLoginSuccess(@NotNull UserType user, @NotNull ConnectionEnvironment connEnv) {
Expand Down Expand Up @@ -223,6 +226,46 @@ public <F extends FocusType> SecurityPolicyType locateGlobalSecurityPolicy(Prism
return null;
}

public SecurityPolicyType locateProjectionSecurityPolicy(RefinedObjectClassDefinition structuralObjectClassDefinition, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
LOGGER.trace("Finishing loading of projection context: security policy");
ObjectReferenceType securityPolicyRef = structuralObjectClassDefinition.getSecurityPolicyRef();
if (securityPolicyRef == null || securityPolicyRef.getOid() == null) {
LOGGER.trace("Security policy not defined for the projection context.");
return loadProjectionLegacyPasswordPolicy(structuralObjectClassDefinition, task, result);
}
LOGGER.trace("Loading security policy {} from: {}", securityPolicyRef, structuralObjectClassDefinition);
SecurityPolicyType securityPolicy = objectResolver.resolve(securityPolicyRef, SecurityPolicyType.class, null, " projection security policy", task, result);
if (securityPolicy == null) {
LOGGER.debug("Security policy {} defined for the projection does not exist", securityPolicyRef);
return null;
}
postProcessSecurityPolicy(securityPolicy, task, result);
return securityPolicy;
}

private SecurityPolicyType loadProjectionLegacyPasswordPolicy(RefinedObjectClassDefinition structuralObjectClassDefinition, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ObjectReferenceType passwordPolicyRef = structuralObjectClassDefinition.getPasswordPolicy();
if (passwordPolicyRef == null || passwordPolicyRef.getOid() == null) {
LOGGER.trace("Legacy password policy not defined for the projection context.");
return null;
}
LOGGER.trace("Loading legacy password policy {} from: {}", passwordPolicyRef, structuralObjectClassDefinition);
ValuePolicyType passwordPolicy = objectResolver.resolve(passwordPolicyRef,
ValuePolicyType.class, null, " projection legacy password policy ", task, result);
if (passwordPolicy == null) {
LOGGER.debug("Legacy password policy {} defined for the projection does not exist", passwordPolicyRef);
return null;
}
ObjectReferenceType dummyPasswordPolicyRef = new ObjectReferenceType();
dummyPasswordPolicyRef.asReferenceValue().setObject(passwordPolicy.asPrismObject());
PrismObject<SecurityPolicyType> securityPolicy = prismContext.createObject(SecurityPolicyType.class);
securityPolicy.asObjectable()
.beginCredentials()
.beginPassword()
.valuePolicyRef(dummyPasswordPolicyRef);
return securityPolicy.asObjectable();
}

private <F extends FocusType> SecurityPolicyType resolveGlobalSecurityPolicy(PrismObject<F> user, SystemConfigurationType systemConfiguration, Task task, OperationResult result) throws CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ObjectReferenceType globalSecurityPolicyRef = systemConfiguration.getGlobalSecurityPolicyRef();
if (globalSecurityPolicyRef != null) {
Expand Down
Expand Up @@ -1112,6 +1112,7 @@ private <F extends FocusType> void executeActions(SynchronizationContext<F> sync
String handlerUri = actionDef.getHandlerUri();
if (handlerUri == null) {
LOGGER.error("Action definition in resource {} doesn't contain handler URI", syncCtx.getResource());
parentResult.recordFatalError("Action definition in resource " + syncCtx.getResource() + "doesn't contain handler URI.");
throw new ConfigurationException(
"Action definition in resource " + syncCtx.getResource() + " doesn't contain handler URI");
}
Expand Down

0 comments on commit 4172793

Please sign in to comment.