Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Sep 17, 2021
2 parents 1e455e5 + 930061c commit 74bb2c0
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,24 @@
<span wicket:id="buttons"/>
</div>

<div class="col-lg-9 col-md-10 col-sm-10 col-xs-10">
<div class="box">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="box box-solid">
<div class="box-body">

<div wicket:id="mainPanel"></div>

<div class="row">
<div class="col-lg-3 col-md-2 col-sm-2 col-xs-2">
<div wicket:id="navigation"></div>
</div>
<div class="col-lg-9 col-md-10 col-sm-10 col-xs-10">
<div wicket:id="mainPanel"></div>
</div>
</div>
</div>
</div>
</div>
</form>
<div class="col-lg-3 col-md-2 col-sm-2 col-xs-2">
<div wicket:id="navigation"></div>
</div>
</div>
</wicket:fragment>

<wicket:fragment wicket:id="progressPanelFragment">
<div wicket:id="progressPanel"></div>
</div>
</wicket:fragment>
<!-- <div wicket:id="progressPanel"></div>-->
<!-- <div wicket:id="details">-->
<!-- <div class="row">-->
<!-- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">-->
<!-- <div wicket:id="summary"></div>-->
<!-- </div>-->
<!-- <form wicket:id="mainForm">-->
<!-- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">-->
<!-- <span wicket:id="buttons"/>-->
<!-- </div>-->

<!-- <div class="col-lg-9 col-md-10 col-sm-10 col-xs-10">-->
<!-- <div class="box">-->
<!-- <div class="box-body">-->

<!-- <div wicket:id="mainPanel"></div>-->

<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- </form>-->
<!-- <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2">-->
<!-- <div wicket:id="navigation"></div>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<wicket:child/>
</wicket:extend>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected void initFragmentLayout() {
ContainerPanelConfigurationType defaultConfiguration = findDefaultConfiguration();
initMainPanel(defaultConfiguration, form);

add(initNavigation());
form.add(initNavigation());
}
};
}
Expand Down Expand Up @@ -362,8 +362,13 @@ private DetailsNavigationPanel<O> createNavigationPanel(IModel<List<ContainerPan
@Override
protected void onClickPerformed(ContainerPanelConfigurationType config, AjaxRequestTarget target) {
MidpointForm form = getMainForm();
initMainPanel(config, form);
target.add(form);
try {
initMainPanel(config, form);
target.add(form);
} catch (Throwable e) {
error("Cannot instantiate panel, " + e.getMessage());
target.add(getFeedbackPanel());
}
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<div wicket:id="template"></div>
</wicket:fragment>
<wicket:child/>

</wicket:extend>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.evolveum.midpoint.gui.impl.page.admin.component;

import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.component.MultivalueContainerDetailsPanel;
import com.evolveum.midpoint.gui.impl.component.MultivalueContainerListPanelWithDetailsPanel;

Expand All @@ -29,6 +30,7 @@
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.web.application.PanelType;

import javax.xml.namespace.QName;
import java.util.Collections;
import java.util.List;

Expand All @@ -43,7 +45,7 @@ public GenericMultivalueContainerPanel(String id, ObjectDetailsModels<O> model,

@Override
protected void initLayout() {
MultivalueContainerListPanelWithDetailsPanel<C> panel = new MultivalueContainerListPanelWithDetailsPanel<C>(ID_DETAILS, getTypeClass()) {
MultivalueContainerListPanelWithDetailsPanel<C> panel = new MultivalueContainerListPanelWithDetailsPanel<C>(ID_DETAILS, getListTypeClass()) {
@Override
protected MultivalueContainerDetailsPanel<C> getMultivalueContainerDetailsPanel(ListItem<PrismContainerValueWrapper<C>> item) {
return null;
Expand Down Expand Up @@ -71,7 +73,7 @@ protected List<IColumn<PrismContainerValueWrapper<C>, String>> createDefaultColu

@Override
protected boolean isCollectionViewPanel() {
return getPanelConfiguration().getListView() !=null;
return getPanelConfiguration().getListView() != null;
}

//TODO generalize
Expand All @@ -88,7 +90,7 @@ protected CompiledObjectCollectionView getObjectCollectionView() {
Task task = getPageBase().createSimpleTask("Compile collection");
OperationResult result = task.getResult();
try {
return getPageBase().getModelInteractionService().compileObjectCollectionView(collectionRefSpecificationType, getTypeClass(), task, result);
return getPageBase().getModelInteractionService().compileObjectCollectionView(collectionRefSpecificationType, getListTypeClass(), task, result);
} catch (Throwable e) {
e.printStackTrace();
}
Expand All @@ -97,9 +99,21 @@ protected CompiledObjectCollectionView getObjectCollectionView() {
};
// SingleContainerPanel<C> panel = new SingleContainerPanel<>(ID_DETAILS, createContainerModel(), getType());
add(panel);
}

private <C extends Containerable> Class<C> getListTypeClass() {
return (Class<C>) WebComponentUtil.qnameToClass(getPrismContext(), getListType());
}

AssignmentType a;
private QName getListType() {
if (getPanelConfiguration().getListView() == null) {
throw new IllegalArgumentException("Cannot instantiate panel without proper configuration. List view configuration missing for " + getPanelConfiguration());
}

if (getPanelConfiguration().getListView().getType() == null) {
throw new IllegalArgumentException("Cannot instantiate panel without proper configuration. Type is mandatory for list view configuration in " + getPanelConfiguration());
}
return getPanelConfiguration().getListView().getType();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div class="box">
<div class="box box-solid">
<div class="box-body">
<div class="main-button-bar">
<fieldset class="objectButtons col-lg-2">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--
~ Copyright (c) 2021 Evolveum
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:extend>

<wicket:fragment wicket:id="progressPanelFragment">
<div wicket:id="progressPanel"></div>
</wicket:fragment>
<wicket:child/>
</wicket:extend>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,24 @@ private Collection<ObjectDeltaOperation<? extends ObjectType>> executeChangesRaw
AuditEventRecord auditRecordRequest = createAuditEventRecordRaw(AuditEventStage.REQUEST, requestIdentifier,
targetRef, ObjectDeltaOperation.cloneDeltaCollection(deltas));
// we don't know auxiliary information (resource, objectName) at this moment -- so we do nothing
auditHelper.audit(auditRecordRequest, null, task, result);

ExpressionType eventRecordingExpression = null;

PrismObject<SystemConfigurationType> config = systemObjectCache.getSystemConfiguration(result);
if (config != null && config.asObjectable() != null && config.asObjectable().getAudit() != null
&& config.asObjectable().getAudit().getEventRecording() != null) {
SystemConfigurationAuditEventRecordingType eventRecording = config.asObjectable().getAudit().getEventRecording();
eventRecordingExpression = eventRecording.getExpression();
}

if (eventRecordingExpression != null) {
// MID-6839
auditRecordRequest = auditHelper.evaluateRecordingExpression(eventRecordingExpression,
auditRecordRequest, null, null, task, result);
}
if (auditRecordRequest != null) {
auditHelper.audit(auditRecordRequest, null, task, result);
}

Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = new ArrayList<>();
try {
Expand All @@ -481,7 +498,14 @@ private Collection<ObjectDeltaOperation<? extends ObjectType>> executeChangesRaw
AuditEventRecord auditRecordExecution = createAuditEventRecordRaw(AuditEventStage.EXECUTION, requestIdentifier, targetRef, executedDeltas);
auditRecordExecution.setTimestamp(System.currentTimeMillis());
auditRecordExecution.setOutcome(result.getStatus());
auditHelper.audit(auditRecordExecution, null, task, result);
if (eventRecordingExpression != null) {
// MID-6839
auditRecordExecution = auditHelper.evaluateRecordingExpression(eventRecordingExpression,
auditRecordExecution, null, null, task, result);
}
if (auditRecordExecution != null) {
auditHelper.audit(auditRecordExecution, null, task, result);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public class ClockworkAuditHelper {

private static final String OP_EVALUATE_AUDIT_RECORD_PROPERTY =
ClockworkAuditHelper.class.getName() + ".evaluateAuditRecordProperty";
private static final String OP_EVALUATE_RECORDING_SCRIPT =
ClockworkAuditHelper.class.getName() + ".evaluateRecordingScript";

@Autowired private PrismContext prismContext;
@Autowired private AuditHelper auditHelper;
Expand Down Expand Up @@ -212,7 +210,7 @@ <F extends ObjectType> void auditEvent(

if (eventRecordingExpression != null) {
// MID-6839
auditRecord = evaluateRecordingExpression(eventRecordingExpression,
auditRecord = auditHelper.evaluateRecordingExpression(eventRecordingExpression,
auditRecord, primaryObject, context, task, result);
}

Expand All @@ -230,42 +228,6 @@ <F extends ObjectType> void auditEvent(
}
}

private <F extends ObjectType> AuditEventRecord evaluateRecordingExpression(
ExpressionType expression, AuditEventRecord auditRecord,
PrismObject<? extends ObjectType> primaryObject, LensContext<F> context,
Task task, OperationResult parentResult) {
OperationResult result = parentResult.createMinorSubresult(OP_EVALUATE_RECORDING_SCRIPT);

try {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_TARGET, primaryObject, PrismObject.class);
variables.put(ExpressionConstants.VAR_AUDIT_RECORD, auditRecord, AuditEventRecord.class);
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(
new ExpressionEnvironment<>(context, null, task, result));
try {
PrismValue returnValue = ExpressionUtil.evaluateExpression(
variables, null, expression, context.getPrivilegedExpressionProfile(),
expressionFactory, OP_EVALUATE_RECORDING_SCRIPT, task, result);
return returnValue != null
? (AuditEventRecord) returnValue.getRealValue()
: null;
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't evaluate audit recording expression", t);
// Copied from evaluateAuditRecordProperty: Intentionally not throwing the exception. The error is marked as partial.
// (It would be better to mark it as fatal and to derive overall result as partial, but we aren't that far yet.)
result.recordPartialError(t);
} finally {
result.recordSuccessIfUnknown();
}

// In case of failure we want to return original auditRecord, although it might be
// modified by some part of the script too - this we have to suffer.
return auditRecord;
}

private <F extends ObjectType> void evaluateAuditRecordProperty(SystemConfigurationAuditEventRecordingPropertyType propertyDef,
AuditEventRecord auditRecord, PrismObject<? extends ObjectType> primaryObject, LensContext<F> context, Task task,
OperationResult parentResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

import java.util.Collection;

import com.evolveum.midpoint.model.common.expression.ExpressionEnvironment;
import com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder;
import com.evolveum.midpoint.model.impl.lens.ClockworkAuditHelper;
import com.evolveum.midpoint.model.impl.lens.LensContext;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;
import com.evolveum.midpoint.repo.common.expression.ExpressionUtil;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.expression.VariablesMap;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationKindType;

import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -48,13 +59,16 @@ public class AuditHelper {
@Autowired private AuditService auditService;
@Autowired private PrismContext prismContext;
@Autowired private SchemaService schemaService;
@Autowired private ExpressionFactory expressionFactory;

@Autowired
@Qualifier("cacheRepositoryService")
private RepositoryService repositoryService;

private static final String OP_AUDIT = AuditHelper.class.getName() + ".audit";
private static final String OP_RESOLVE_NAME = AuditHelper.class.getName() + ".resolveName";
private static final String OP_EVALUATE_RECORDING_SCRIPT =
AuditHelper.class.getName() + ".evaluateRecordingScript";

/**
* @param externalNameResolver Name resolver that should be tried first. It should be fast.
Expand Down Expand Up @@ -124,4 +138,47 @@ private void resolveNamesInDeltas(
resolveNames(delta, nameResolver, prismContext);
}
}

public <F extends ObjectType> AuditEventRecord evaluateRecordingExpression(
ExpressionType expression, AuditEventRecord auditRecord,
PrismObject<? extends ObjectType> primaryObject, LensContext<F> context,
Task task, OperationResult parentResult) {
OperationResult result = parentResult.createMinorSubresult(OP_EVALUATE_RECORDING_SCRIPT);

try {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_TARGET, primaryObject, PrismObject.class);
variables.put(ExpressionConstants.VAR_AUDIT_RECORD, auditRecord, AuditEventRecord.class);
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(
new ExpressionEnvironment<>(context, null, task, result));
try {
PrismValue returnValue = ExpressionUtil.evaluateExpression(
variables,
null,
expression, context != null ? context.getPrivilegedExpressionProfile() : null,
expressionFactory,
OP_EVALUATE_RECORDING_SCRIPT,
task,
result
);

return returnValue != null
? (AuditEventRecord) returnValue.getRealValue()
: null;
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't evaluate audit recording expression", t);
// Copied from evaluateAuditRecordProperty: Intentionally not throwing the exception. The error is marked as partial.
// (It would be better to mark it as fatal and to derive overall result as partial, but we aren't that far yet.)
result.recordPartialError(t);
} finally {
result.recordSuccessIfUnknown();
}

// In case of failure we want to return original auditRecord, although it might be
// modified by some part of the script too - this we have to suffer.
return auditRecord;
}
}

0 comments on commit 74bb2c0

Please sign in to comment.