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 Jan 23, 2019
2 parents ede61bc + e619fe5 commit d85d3ca
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 133 deletions.
Expand Up @@ -431,6 +431,10 @@ public boolean isEmpty(Object whatever) {
}
return whateverString.isEmpty();
}

public PrismContext getPrismContext() {
return prismContext;
}

public <T> Collection<T> getExtensionPropertyValues(ObjectType object, String namespace, String localPart) {
return getExtensionPropertyValues(object, new javax.xml.namespace.QName(namespace, localPart));
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,6 +53,8 @@
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionReturnTypeType;

Expand All @@ -65,6 +67,8 @@
public class Jsr223ScriptEvaluator implements ScriptEvaluator {

private static final String LANGUAGE_URL_BASE = MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX + "/expression/language#";

private static final Trace LOGGER = TraceManager.getTrace(Jsr223ScriptEvaluator.class);

private final ScriptEngine scriptEngine;
private final PrismContext prismContext;
Expand Down Expand Up @@ -130,12 +134,19 @@ public <T, V extends PrismValue> List<V> evaluate(ScriptExpressionEvaluatorType
if (javaReturnType == null) {
javaReturnType = prismContext.getSchemaRegistry().getCompileTimeClass(xsdReturnType);
}

if (javaReturnType == null && (outputDefinition instanceof PrismContainerDefinition<?>)) {
// This is the case when we need a container, but we do not have compile-time class for that
// E.g. this may be container in object extension (MID-5080)
javaReturnType = (Class<T>) PrismContainerValue.class;
}

if (javaReturnType == null) {
// TODO quick and dirty hack - because this could be because of enums defined in schema extension (MID-2399)
// ...and enums (xsd:simpleType) are not parsed into ComplexTypeDefinitions
javaReturnType = (Class) String.class;
javaReturnType = (Class<T>) String.class;
}
LOGGER.trace("expected return type: XSD={}, Java={}", xsdReturnType, javaReturnType);

List<V> pvals = new ArrayList<>();

Expand Down
Expand Up @@ -441,10 +441,10 @@ public void evaluateBody(Task task, OperationResult parentResult) throws Express

evaluateCondition(task, result);

boolean conditionOutputOld = computeConditionResult(conditionOutputTriple.getNonPositiveValues());
boolean conditionOutputOld = computeConditionResult(conditionOutputTriple==null ? null : conditionOutputTriple.getNonPositiveValues());
boolean conditionResultOld = conditionOutputOld && conditionMaskOld;

boolean conditionOutputNew = computeConditionResult(conditionOutputTriple.getNonNegativeValues());
boolean conditionOutputNew = computeConditionResult(conditionOutputTriple==null ? null : conditionOutputTriple.getNonNegativeValues());
boolean conditionResultNew = conditionOutputNew && conditionMaskNew;

if (!conditionResultOld && !conditionResultNew) {
Expand Down
Expand Up @@ -498,6 +498,10 @@ public class AbstractConfiguredModelIntegrationTest extends AbstractModelIntegra
protected static final ItemName PIRACY_MARK = new ItemName(NS_PIRACY, "mark");
protected static final ItemName PIRACY_KEY = new ItemName(NS_PIRACY, "key");
protected static final ItemName PIRACY_BINARY_ID = new ItemName(NS_PIRACY, "binaryId");
protected static final ItemName PIRACY_COST_CENTER = new ItemName(NS_PIRACY, "costCenter");
protected static final ItemName PIRACY_RISK_VECTOR = new ItemName(NS_PIRACY, "riskVector");
protected static final ItemName PIRACY_RISK_VECTOR_RISK = new ItemName(NS_PIRACY, "risk");
protected static final ItemName PIRACY_RISK_VECTOR_VALUE = new ItemName(NS_PIRACY, "value");
protected static final ItemName RELATION_PIRACY_CAPTAIN = new ItemName(NS_PIRACY, "captain");

protected static final ItemPath ROLE_EXTENSION_COST_CENTER_PATH = ItemPath
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -83,8 +83,7 @@ public void test050GetRolePirate() throws Exception {
display("Role pirate", role);
assertRolePirate(role);

result.computeStatus();
TestUtil.assertSuccess("getObject result", result);
assertSuccess(result);
}

protected void assertRolePirate(PrismObject<RoleType> role) {
Expand Down Expand Up @@ -1183,16 +1182,16 @@ public void test200AddRoleSwashbuckler() throws Exception {

PrismObject<RoleType> role = PrismTestUtil.parseObject(ROLE_SWASHBUCKLER_FILE);
ObjectDelta<RoleType> roleDelta = DeltaFactory.Object.createAddDelta(role);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(roleDelta);

XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();

// WHEN
modelService.executeChanges(deltas, null, task, result);
displayWhen(TEST_NAME);
executeChanges(roleDelta, null, task, result);

// THEN
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
displayThen(TEST_NAME);
assertSuccess(result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();

assertNotNull("No account OID in resulting delta", groupOid);
Expand Down Expand Up @@ -1233,6 +1232,40 @@ public void test200AddRoleSwashbuckler() throws Exception {
dummyAuditService.assertTarget(ROLE_SWASHBUCKLER_OID);
dummyAuditService.assertExecutionSuccess();
}

/**
* MID-5080
*/
@Test
public void test210ModifyRoleSwashbucklerRiskLevel() throws Exception {
final String TEST_NAME = "test210ModifyRoleSwashbucklerRiskLevel";
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
prepareTest(AssignmentPolicyEnforcementType.RELATIVE);

assertRoleBefore(ROLE_SWASHBUCKLER_OID)
.extension()
.assertItems(PIRACY_COST_CENTER);

// WHEN
displayWhen(TEST_NAME);
modifyObjectReplaceProperty(RoleType.class, ROLE_SWASHBUCKLER_OID, RoleType.F_RISK_LEVEL, task, result, "99");

// THEN
displayThen(TEST_NAME);
assertSuccess(result);

assertRoleAfter(ROLE_SWASHBUCKLER_OID)
.assertRiskLevel("99")
.extension()
.assertItems(PIRACY_COST_CENTER, PIRACY_RISK_VECTOR)
.containerSingle(PIRACY_RISK_VECTOR)
.assertPropertyEquals(PIRACY_RISK_VECTOR_RISK, "X")
.assertPropertyEquals(PIRACY_RISK_VECTOR_VALUE, 99);
}

private void prepareTest(AssignmentPolicyEnforcementType enforcement) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
assumeAssignmentPolicy(enforcement);
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2013-2017 Evolveum
~ Copyright (c) 2013-2019 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,26 +31,67 @@
<valueEnumerationRef oid="70000000-0000-0000-1111-000000000021" type="LookupTableType"/>
</item>

<mapping>
<strength>weak</strength>
<source>
<path>name</path>
</source>
<source>
<path>$focus/requestable</path>
</source>
<expression>
<script>
<code>
'Requestable role ' + name
</code>
</script>
</expression>
<target>
<path>description</path>
</target>
<condition>
<path>$requestable</path>
</condition>
</mapping>
<item>
<ref>description</ref>
<mapping>
<strength>weak</strength>
<source>
<path>name</path>
</source>
<source>
<path>$focus/requestable</path>
</source>
<expression>
<script>
<code>
'Requestable role ' + name
</code>
</script>
</expression>
<condition>
<path>$requestable</path>
</condition>
</mapping>
</item>

<!-- MID-5080 -->
<item>
<ref>extension/riskVector</ref>
<mapping>
<name>role-risk-vector</name>
<strength>strong</strength>
<trace>true</trace>
<source>
<path>name</path>
</source>
<source>
<path>riskLevel</path>
</source>
<expression>
<script>
<code>
import com.evolveum.midpoint.prism.PrismContainerValue
import com.evolveum.midpoint.prism.PrismProperty
import javax.xml.namespace.QName

PrismContainerValue cval = basic.getPrismContext().itemFactory().createContainerValue()
PrismProperty pRisk = basic.getPrismContext().itemFactory().createProperty(new QName(null, "risk"))
pRisk.setRealValue("X")
cval.add(pRisk)
PrismProperty pValue = basic.getPrismContext().itemFactory().createProperty(new QName(null, "value"))
pValue.setRealValue(riskLevel.toInteger())
cval.add(pValue)
return cval
</code>
</script>
</expression>
<condition>
<trace>true</trace>
<script>
<code>riskLevel != null</code>
</script>
</condition>
</mapping>
</item>

</objectTemplate>
1 change: 1 addition & 0 deletions model/model-intest/src/test/resources/logback-test.xml
Expand Up @@ -99,6 +99,7 @@
<logger name="com.evolveum.midpoint.model.common.expression.evaluator.AssignmentExpressionEvaluator" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.expression.evaluator.AssociationExpressionEvaluator" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.stringpolicy.ValuePolicyGenerator" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.common.expression.script.jsr223.Jsr223ScriptEvaluator" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.controller.ObjectMerger" level="DEBUG" />
<logger name="com.evolveum.midpoint.notifications" level="DEBUG" />
<logger name="com.evolveum.midpoint.security" level="DEBUG" />
Expand Down
20 changes: 19 additions & 1 deletion model/model-intest/src/test/resources/schema/piracy.xsd
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!--
~ Copyright (c) 2010-2017 Evolveum
~ Copyright (c) 2010-2019 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,6 +77,7 @@
</xsd:annotation>
</xsd:element>
<xsd:element name="mark" type="tns:MarkType" minOccurs="0" maxOccurs="1">
<!-- Enumeration -->
</xsd:element>
<xsd:element name="key" type="xsd:base64Binary" minOccurs="0" maxOccurs="1">
<xsd:annotation>
Expand Down Expand Up @@ -156,6 +157,23 @@
</xsd:annotation>
</xsd:element>
<xsd:element ref="tns:sea"/>
<xsd:element name="riskVector" type="tns:RiskVectorType" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="RiskVectorType">
<xsd:annotation>
<xsd:documentation>
Prism container in role extension.
MID-5080
</xsd:documentation>
<xsd:appinfo>
<a:container>true</a:container>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="risk" type="xsd:string" minOccurs="1"/>
<xsd:element name="value" type="xsd:int" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>

Expand Down
Expand Up @@ -5583,6 +5583,11 @@ protected RoleAsserter<Void> assertRole(PrismObject<RoleType> role, String messa
return asserter;
}

protected RoleAsserter<Void> assertRoleBefore(String oid) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
RoleAsserter<Void> asserter = assertRole(oid, "before");
return asserter;
}

protected RoleAsserter<Void> assertRoleAfter(String oid) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
RoleAsserter<Void> asserter = assertRole(oid, "after");
return asserter;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1007,14 +1007,31 @@ public static <T> boolean isEmpty(T val) {
public static <T, V extends PrismValue> V convertToPrismValue(T value, ItemDefinition definition, String contextDescription, PrismContext prismContext) throws ExpressionEvaluationException {
if (definition instanceof PrismReferenceDefinition) {
return (V) ((ObjectReferenceType) value).asReferenceValue();

} else if (definition instanceof PrismContainerDefinition) {
try {
prismContext.adopt((Containerable) value);
((Containerable) value).asPrismContainerValue().applyDefinition(definition);
} catch (SchemaException e) {
throw new ExpressionEvaluationException(e.getMessage() + " " + contextDescription, e);

if (value instanceof Containerable) {
try {
prismContext.adopt((Containerable) value);
((Containerable) value).asPrismContainerValue().applyDefinition(definition);
} catch (SchemaException e) {
throw new ExpressionEvaluationException(e.getMessage() + " " + contextDescription, e);
}
return (V) ((Containerable) value).asPrismContainerValue();

} else if (value instanceof PrismContainerValue<?>) {
try {
prismContext.adopt((PrismContainerValue) value);
((PrismContainerValue) value).applyDefinition(definition);
} catch (SchemaException e) {
throw new ExpressionEvaluationException(e.getMessage() + " " + contextDescription, e);
}
return (V) ((PrismContainerValue) value);

} else {
throw new ExpressionEvaluationException("Expected Containerable or PrismContainerValue as expression output, got "+value.getClass());
}
return (V) ((Containerable) value).asPrismContainerValue();

} else {
return (V) prismContext.itemFactory().createPropertyValue(value);
}
Expand Down
Expand Up @@ -172,22 +172,17 @@ public AbstractRoleAsserter<F,RA> assertLocality(String expectedOrig) {
}

public AbstractRoleAsserter<F,RA> assertDisplayName(String expectedOrig) {
assertPolyStringProperty(OrgType.F_DISPLAY_NAME, expectedOrig);
assertPolyStringProperty(AbstractRoleType.F_DISPLAY_NAME, expectedOrig);
return this;
}

public AbstractRoleAsserter<F,RA> assertIdentifier(String expectedOrig) {
assertPropertyEquals(OrgType.F_IDENTIFIER, expectedOrig);
assertPropertyEquals(AbstractRoleType.F_IDENTIFIER, expectedOrig);
return this;
}

public AbstractRoleAsserter<F,RA> assertTenant(Boolean expected) {
assertPropertyEquals(OrgType.F_TENANT, expected);
return this;
}

public AbstractRoleAsserter<F,RA> assertIsTenant() {
assertPropertyEquals(OrgType.F_TENANT, true);

public AbstractRoleAsserter<F,RA> assertRiskLevel(String expected) {
assertPropertyEquals(AbstractRoleType.F_RISK_LEVEL, expected);
return this;
}

Expand Down

0 comments on commit d85d3ca

Please sign in to comment.