Skip to content

Commit

Permalink
MID-8842 ninja - accountPasswordPolicy processor + test
Browse files Browse the repository at this point in the history
(cherry picked from commit a2d1f0e)
  • Loading branch information
1azyman committed Jul 26, 2023
1 parent 68ba7c2 commit 7a8ca6e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.schema.validator.processor;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.validator.UpgradeObjectProcessor;
import com.evolveum.midpoint.schema.validator.UpgradePhase;
import com.evolveum.midpoint.schema.validator.UpgradePriority;
import com.evolveum.midpoint.schema.validator.UpgradeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LensProjectionContextType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

@SuppressWarnings("unused")
public class AccountPasswordPolicyProcessor implements UpgradeObjectProcessor<ObjectType> {

public static final ItemName F_ACCOUNT_PASSWORD_POLICY = new ItemName(ObjectFactory.NAMESPACE, "accountPasswordPolicy");

@Override
public UpgradePhase getPhase() {
return UpgradePhase.BEFORE;
}

@Override
public UpgradePriority getPriority() {
return UpgradePriority.NECESSARY;
}

@Override
public UpgradeType getType() {
return UpgradeType.SEAMLESS;
}

@Override
public boolean isApplicable(PrismObject<?> object, ItemPath path) {
return matchParentTypeAndItemName(
object, path, LensProjectionContextType.class, LensProjectionContextType.F_ACCOUNT_PASSWORD_POLICY_REF)
|| matchParentTypeAndItemName(
object, path, LensProjectionContextType.class, F_ACCOUNT_PASSWORD_POLICY);
}

@Override
public boolean process(PrismObject<ObjectType> object, ItemPath path) throws Exception {
LensProjectionContextType parent = getItemParent(object, path);
parent.setAccountPasswordPolicy(null);
parent.setAccountPasswordPolicyRef(null);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void test10TestResource() throws Exception {
@Test
public void test20TestCaseTaskRef() throws Exception {
testUpgradeValidator("case.xml", result -> {
Assertions.assertThat(result.getItems()).hasSize(1);
Assertions.assertThat(result.getItems()).hasSize(3);

UpgradeValidationItem item = assertGetItem(result, new ProcessorMixin() {
}.getIdentifier(CaseTaskRefProcessor.class));
Expand Down
6 changes: 6 additions & 0 deletions infra/schema/src/test/resources/validator/expected/case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
oid="10a2c2b4-4d02-4f52-a4ac-092d8e321006">

<name>case</name>

<modelContext>
<state>execution</state>
<projectionContext id="1"/>
<projectionContext id="2"/>
</modelContext>
</case>
13 changes: 13 additions & 0 deletions infra/schema/src/test/resources/validator/processor/case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@

<name>case</name>
<taskRef oid="c5baeaf3-e917-4d1a-9aed-8a4bc147f5f9"/>
<modelContext>
<state>execution</state>
<projectionContext id="1">
<accountPasswordPolicy>
<stringPolicy>
<description>123</description>
</stringPolicy>
</accountPasswordPolicy>
</projectionContext>
<projectionContext id="2">
<accountPasswordPolicyRef oid="2db718b6-243a-11e7-a9e5-bbb2545f80ed"/>
</projectionContext>
</modelContext>
</case>

0 comments on commit 7a8ca6e

Please sign in to comment.