Skip to content

Commit

Permalink
MID-8842 ninja - authentication name/identifier processor + test
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jul 26, 2023
1 parent a2d1f0e commit 528ad16
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.AbstractAuthenticationModuleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthenticationSequenceModuleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthenticationSequenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType;

@SuppressWarnings("unused")
public class AuthenticationNameProcessor 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, AuthenticationSequenceType.class, AuthenticationSequenceType.F_NAME)
|| matchParentTypeAndItemName(
object, path, AuthenticationSequenceModuleType.class, AuthenticationSequenceModuleType.F_NAME)
|| matchParentTypeAndItemName(
object, path, AbstractAuthenticationModuleType.class, AbstractAuthenticationModuleType.F_NAME);
}

@Override
public boolean process(PrismObject<SecurityPolicyType> object, ItemPath path) throws Exception {
Object parent = getItemParent(object, path);
if (parent instanceof AuthenticationSequenceType) {
AuthenticationSequenceType auth = (AuthenticationSequenceType) parent;
auth.setIdentifier(auth.getName());
return true;
}

if (parent instanceof AuthenticationSequenceModuleType) {
AuthenticationSequenceModuleType module = (AuthenticationSequenceModuleType) parent;
module.setIdentifier(module.getName());
return true;
}

if (parent instanceof AbstractAuthenticationModuleType) {
AbstractAuthenticationModuleType module = (AbstractAuthenticationModuleType) parent;
module.setIdentifier(module.getName());
return true;
}

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

Assertions.assertThat(result.hasChanges()).isFalse();
Assertions.assertThat(result.hasChanges()).isTrue();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@
<authentication>
<modules>
<saml2 id="1">
<identifier>deprecated items</identifier>
<name>deprecated items</name>
</saml2>
</modules>
<sequence id="2">
<identifier>sequencename</identifier>
<name>sequencename</name>
<module id="3">
<identifier>deprecated items</identifier>
<name>deprecated items</name>
</module>
</sequence>
</authentication>
</securityPolicy>
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@
</network>
</saml2>
</modules>
<sequence id="2">
<name>sequencename</name>
<module id="3">
<name>deprecated items</name>
</module>
</sequence>
</authentication>
</securityPolicy>

0 comments on commit 528ad16

Please sign in to comment.