Skip to content

Commit

Permalink
skip disabled mapping + test
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed May 24, 2021
1 parent cadaf29 commit 4d92603
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
Expand Up @@ -565,6 +565,10 @@ public boolean isProfiling() {
return profiling;
}

public boolean isEnabled() {
return isNotFalse(mappingBean.isEnabled());
}

public Long getEtime() {
if (evaluationStartTime == null || evaluationEndTime == null) {
return null;
Expand Down
Expand Up @@ -77,6 +77,11 @@ public <V extends PrismValue, D extends ItemDefinition, F extends ObjectType> vo
throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, SecurityViolationException,
ConfigurationException, CommunicationException {

if (!mapping.isEnabled()) {
LOGGER.debug("Skipping mapping evaluation, because mapping is disabled, {}", mapping);
return;
}

ExpressionEnvironment<F, V, D> env = new ExpressionEnvironment<>();
env.setLensContext(lensContext);
env.setProjectionContext(projContext);
Expand Down
Expand Up @@ -106,6 +106,8 @@ public class TestMapping extends AbstractMappingTest {

private static final TestResource<RoleType> ROLE_TIMED = new TestResource<>(TEST_DIR, "role-timed.xml", "9af2f6d7-564f-45f8-bd8a-2f5cef1596a8");

private static final TestResource<RoleType> ROLE_DISABLED_MAPPING = new TestResource<>(TEST_DIR, "role-disabled-mapping.xml", "f7228a46-bc75-11eb-8529-0242ac130003");

private static final String CAPTAIN_JACK_FULL_NAME = "Captain Jack Sparrow";

private static final String SHIP_BLACK_PEARL = "Black Pearl";
Expand Down Expand Up @@ -163,6 +165,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
repoAddObjectFromFile(ROLE_BLUE_POETRY_FILE, initResult);
repoAddObjectFromFile(ROLE_COBALT_NEVERLAND_FILE, initResult);
repoAddObjectFromFile(ROLE_TIMED.file, initResult);
repoAddObjectFromFile(ROLE_DISABLED_MAPPING.file, initResult);

assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

Expand Down Expand Up @@ -3358,6 +3361,40 @@ public void test700TimedOutbound() throws Exception {
.assertTimestampFuture("P2M", 20000);
}

/**
* Assign Disabled Mapping role. This role has strong mapping to cobalt resource
* wealth attribute and strong, but disabled mapping to weapon attribute. Account
* on the Cobalt resource should be created, byt weapon attribute has not to be
* evaluated.
*/
@Test
public void test750assignRoleDisabledMapping() throws Exception {
given();
Task task = getTestTask();
OperationResult result = getTestOperationResult();

when();
UserType user = new UserType(prismContext)
.name("test750")
.beginAssignment()
.targetRef(ROLE_DISABLED_MAPPING.oid, RoleType.COMPLEX_TYPE)
.end();
String oid = addObject(user.asPrismObject(), task, result);

then();
assertSuccess(result);

assertUser(oid, "User after")
.assertName("test750")
.assertAssignments(1)
.assignments().assertRole(ROLE_DISABLED_MAPPING.oid);

assertDummyAccountAttribute(RESOURCE_DUMMY_COBALT_NAME, "test750",
DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEALTH_NAME, 30000);
assertDummyAccountNoAttribute(RESOURCE_DUMMY_COBALT_NAME, "test750",
DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME);
}

private String rumFrom(String locality) {
return "rum from " + locality;
}
Expand Down
@@ -0,0 +1,38 @@
<!--
~ Copyright (c) 2021 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<role xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
oid="f7228a46-bc75-11eb-8529-0242ac130003">
<name>role-disabled-mapping</name>
<inducement>
<construction>
<resourceRef oid="7f8a927c-cac4-11e7-9733-9f90849f6d4a" type="c:ResourceType"/> <!-- Dummy Cobalt -->
<kind>account</kind>
<attribute>
<ref>ri:wealth</ref>
<outbound>
<strength>strong</strength>
<expression>
<value>30000</value>
</expression>
</outbound>
</attribute>
<attribute>
<ref>ri:weapon</ref>
<outbound>
<enabled>false</enabled>
<strength>strong</strength>
<expression>
<value>knife</value>
</expression>
</outbound>
</attribute>
</construction>
</inducement>
</role>

0 comments on commit 4d92603

Please sign in to comment.