Skip to content

Commit

Permalink
MID-8842 ninja - credentials reset name processor
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Aug 1, 2023
1 parent 9c02654 commit f3216fb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.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.CredentialsResetPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType;

@SuppressWarnings("unused")
public class CredentialsResetNameProcessor implements UpgradeObjectProcessor<SecurityPolicyType> {

@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, CredentialsResetPolicyType.class, CredentialsResetPolicyType.F_NAME);
}

@Override
public boolean process(PrismObject<SecurityPolicyType> object, ItemPath path) throws Exception {
CredentialsResetPolicyType resetPolicy = object.asObjectable().getCredentialsReset();
if (resetPolicy.getIdentifier() == null) {
resetPolicy.setIdentifier(resetPolicy.getName());
}
resetPolicy.setName(null);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void test40TestRole() throws Exception {
public void test50SecurityPolicy() throws Exception {
testUpgradeValidator("security-policy.xml", result -> {
Assertions.assertThat(result.getItems())
.hasSize(3);
.hasSize(4);

Assertions.assertThat(result.hasChanges()).isTrue();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
</module>
</sequence>
</authentication>
<credentialsReset>
<identifier>sample-name</identifier>
</credentialsReset>
</securityPolicy>
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@
</module>
</sequence>
</authentication>
<credentialsReset>
<name>sample-name</name>
</credentialsReset>
</securityPolicy>

0 comments on commit f3216fb

Please sign in to comment.