You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by mm...@apache.org on 2020/03/07 15:49:50 UTC

[syncope] 06/06: cntd with attr rel policy and ITs

This is an automated email from the ASF dual-hosted git repository.

mmoayyed pushed a commit to branch SYNCOPE-163-1
in repository https://gitbox.apache.org/repos/asf/syncope.git

commit 4653790b660fdab848b36db8f1d6067ddd912e81
Author: Misagh Moayyed <mm...@gmail.com>
AuthorDate: Sat Mar 7 19:19:18 2020 +0330

    cntd with attr rel policy and ITs
---
 .../lib/access/AbstractAccessPolicyConf.java       |   8 +-
 .../src/test/resources/domains/MasterContent.xml   |   4 +-
 .../core/persistence/jpa/dao/JPARealmDAO.java      |   3 +
 .../jpa/inner/AbstractClientAppTest.java           |   2 +-
 .../src/test/resources/domains/MasterContent.xml   |   4 +-
 .../java/data/PolicyDataBinderImpl.java            |  50 ++++++-----
 .../org/apache/syncope/fit/core/PolicyITCase.java  | 100 +++++++++------------
 7 files changed, 82 insertions(+), 89 deletions(-)

diff --git a/common/am/lib/src/main/java/org/apache/syncope/common/lib/access/AbstractAccessPolicyConf.java b/common/am/lib/src/main/java/org/apache/syncope/common/lib/access/AbstractAccessPolicyConf.java
index 0f26b4d..a0be8bb 100644
--- a/common/am/lib/src/main/java/org/apache/syncope/common/lib/access/AbstractAccessPolicyConf.java
+++ b/common/am/lib/src/main/java/org/apache/syncope/common/lib/access/AbstractAccessPolicyConf.java
@@ -35,7 +35,7 @@ public abstract class AbstractAccessPolicyConf implements Serializable, AccessPo
 
     private boolean enabled = true;
 
-    private boolean singleSignOnEnabled = true;
+    private boolean ssoEnabled = true;
 
     private Map<String, List<String>> requiredAttributes = new LinkedHashMap<>();
 
@@ -63,11 +63,11 @@ public abstract class AbstractAccessPolicyConf implements Serializable, AccessPo
 
     @Override
     public boolean isSsoEnabled() {
-        return singleSignOnEnabled;
+        return this.ssoEnabled;
     }
 
-    public void setSingleSignOnEnabled(final boolean singleSignOnEnabled) {
-        this.singleSignOnEnabled = singleSignOnEnabled;
+    public void setSsoEnabled(final boolean ssoEnabled) {
+        this.ssoEnabled = ssoEnabled;
     }
 
     @Override
diff --git a/core/persistence-jpa-json/src/test/resources/domains/MasterContent.xml b/core/persistence-jpa-json/src/test/resources/domains/MasterContent.xml
index e9037de..62eee58 100644
--- a/core/persistence-jpa-json/src/test/resources/domains/MasterContent.xml
+++ b/core/persistence-jpa-json/src/test/resources/domains/MasterContent.xml
@@ -46,7 +46,7 @@ under the License.
   
   <!-- authentication policies -->
   <Implementation id="MyDefaultAuthenticationPolicyConf" type="AUTH_POLICY_CONFIGURATIONS" engine="JAVA"
-                  body='{"@class":"org.apache.syncope.common.lib.authentication.DefaultAuthenticationPolicyConf","authenticationModules":["LdapAuthenticationTest"]}'/>
+                  body='{"@class":"org.apache.syncope.common.lib.authentication.policy.DefaultAuthenticationPolicyConf","authenticationModules":["LdapAuthenticationTest"]}'/>
   <AuthenticationPolicy id="659b9906-4b6e-4bc0-aca0-6809dff346d4" name="MyDefaultAuthenticationPolicyConf" 
                         description="an authentication policy" />
   <AuthenticationPolicy id="b912a0d4-a890-416f-9ab8-84ab077eb028" name="DefaultAuthenticationPolicy" 
@@ -55,7 +55,7 @@ under the License.
   
   <!-- access policies -->
   <Implementation id="MyDefaultAccessPolicyConf" type="ACCESS_POLICY_CONFIGURATIONS" engine="JAVA"
-                  body='{"@class":"org.apache.syncope.common.lib.access.DefaultAccessPolicyConf","name":"MyDefaultAccessPolicyConf","enabled":true,"singleSignOnEnabled":true}'/>
+                  body='{"@class":"org.apache.syncope.common.lib.access.DefaultAccessPolicyConf","name":"MyDefaultAccessPolicyConf","enabled":true,"ssoEnabled":true}'/>
   <AccessPolicy id="419935c7-deb3-40b3-8a9a-683037e523a2" name="MyDefaultAccessPolicyConf"
                 description="an access policy" />
 
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARealmDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARealmDAO.java
index e3c60a1..f98bba4 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARealmDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPARealmDAO.java
@@ -33,6 +33,7 @@ import org.apache.syncope.core.persistence.api.entity.Implementation;
 import org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy;
 import org.apache.syncope.core.persistence.api.entity.Realm;
 import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
+import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
 import org.apache.syncope.core.persistence.api.entity.policy.AuthenticationPolicy;
 import org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy;
 import org.apache.syncope.core.persistence.api.entity.policy.Policy;
@@ -158,6 +159,8 @@ public class JPARealmDAO extends AbstractDAO<Realm> implements RealmDAO {
             policyColumn = "authenticationPolicy";
         } else if (policy instanceof AccessPolicy) {
             policyColumn = "accessPolicy";
+        } else if (policy instanceof AttrReleasePolicy) {
+            policyColumn = "attrReleasePolicy";
         }
 
         TypedQuery<Realm> query = entityManager().createQuery(
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AbstractClientAppTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AbstractClientAppTest.java
index cdfe2dd..03491f1 100644
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AbstractClientAppTest.java
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AbstractClientAppTest.java
@@ -55,7 +55,7 @@ public class AbstractClientAppTest extends AbstractTest {
         conf.setEnabled(true);
         conf.setName("Example Access Policy for an application");
         conf.setRequiredAttributes(Map.of("attribute1", List.of("value1", "value2")));
-        conf.setSingleSignOnEnabled(false);
+        conf.setSsoEnabled(false);
 
         Implementation type = entityFactory.newEntity(Implementation.class);
         type.setKey("AccessPolicyConfKey");
diff --git a/core/persistence-jpa/src/test/resources/domains/MasterContent.xml b/core/persistence-jpa/src/test/resources/domains/MasterContent.xml
index 7375f12..5857d2c 100644
--- a/core/persistence-jpa/src/test/resources/domains/MasterContent.xml
+++ b/core/persistence-jpa/src/test/resources/domains/MasterContent.xml
@@ -46,7 +46,7 @@ under the License.
   
   <!-- authentication policies -->
   <Implementation id="MyDefaultAuthenticationPolicyConf" type="AUTH_POLICY_CONFIGURATIONS" engine="JAVA"
-                  body='{"@class":"org.apache.syncope.common.lib.authentication.DefaultAuthenticationPolicyConf","authenticationModules":["LdapAuthenticationTest"]}'/>
+                  body='{"@class":"org.apache.syncope.common.lib.authentication.policy.DefaultAuthenticationPolicyConf","authenticationModules":["LdapAuthenticationTest"]}'/>
   <AuthenticationPolicy id="659b9906-4b6e-4bc0-aca0-6809dff346d4" name="MyDefaultAuthenticationPolicyConf" 
                         description="an authentication policy" />
   <AuthenticationPolicy id="b912a0d4-a890-416f-9ab8-84ab077eb028" name="DefaultAuthenticationPolicy" 
@@ -55,7 +55,7 @@ under the License.
   
   <!-- access policies -->
   <Implementation id="MyDefaultAccessPolicyConf" type="ACCESS_POLICY_CONFIGURATIONS" engine="JAVA"
-                  body='{"@class":"org.apache.syncope.common.lib.access.DefaultAccessPolicyConf","name":"MyDefaultAccessPolicyConf","enabled":true,"singleSignOnEnabled":true}'/>
+                  body='{"@class":"org.apache.syncope.common.lib.access.DefaultAccessPolicyConf","name":"MyDefaultAccessPolicyConf","enabled":true,"ssoEnabled":true}'/>
   <AccessPolicy id="419935c7-deb3-40b3-8a9a-683037e523a2" name="MyDefaultAccessPolicyConf"
                 description="an access policy" />
 
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/PolicyDataBinderImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/PolicyDataBinderImpl.java
index 69be000..005e992 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/PolicyDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/PolicyDataBinderImpl.java
@@ -18,15 +18,14 @@
  */
 package org.apache.syncope.core.provisioning.java.data;
 
-import java.util.stream.Collectors;
-import org.apache.syncope.common.lib.to.AccessPolicyTO;
-import org.apache.syncope.core.provisioning.api.data.PolicyDataBinder;
-import org.apache.syncope.common.lib.policy.PolicyTO;
 import org.apache.syncope.common.lib.policy.AccountPolicyTO;
-import org.apache.syncope.common.lib.to.AuthenticationPolicyTO;
 import org.apache.syncope.common.lib.policy.PasswordPolicyTO;
+import org.apache.syncope.common.lib.policy.PolicyTO;
 import org.apache.syncope.common.lib.policy.PullPolicyTO;
 import org.apache.syncope.common.lib.policy.PushPolicyTO;
+import org.apache.syncope.common.lib.to.AccessPolicyTO;
+import org.apache.syncope.common.lib.to.AttrReleasePolicyTO;
+import org.apache.syncope.common.lib.to.AuthenticationPolicyTO;
 import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
 import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
 import org.apache.syncope.core.persistence.api.dao.ImplementationDAO;
@@ -34,24 +33,28 @@ import org.apache.syncope.core.persistence.api.dao.NotFoundException;
 import org.apache.syncope.core.persistence.api.dao.RealmDAO;
 import org.apache.syncope.core.persistence.api.entity.AnyType;
 import org.apache.syncope.core.persistence.api.entity.Entity;
-import org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy;
 import org.apache.syncope.core.persistence.api.entity.EntityFactory;
 import org.apache.syncope.core.persistence.api.entity.Implementation;
-import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
-import org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy;
 import org.apache.syncope.core.persistence.api.entity.Realm;
 import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
+import org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy;
+import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
 import org.apache.syncope.core.persistence.api.entity.policy.AuthenticationPolicy;
+import org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy;
 import org.apache.syncope.core.persistence.api.entity.policy.Policy;
 import org.apache.syncope.core.persistence.api.entity.policy.PullCorrelationRuleEntity;
 import org.apache.syncope.core.persistence.api.entity.policy.PullPolicy;
 import org.apache.syncope.core.persistence.api.entity.policy.PushCorrelationRuleEntity;
 import org.apache.syncope.core.persistence.api.entity.policy.PushPolicy;
+import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
+import org.apache.syncope.core.provisioning.api.data.PolicyDataBinder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.stream.Collectors;
+
 @Component
 public class PolicyDataBinderImpl implements PolicyDataBinder {
 
@@ -97,7 +100,7 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
             });
             // remove all implementations not contained in the TO
             passwordPolicy.getRules().
-                    removeIf(implementation -> !passwordPolicyTO.getRules().contains(implementation.getKey()));
+                removeIf(implementation -> !passwordPolicyTO.getRules().contains(implementation.getKey()));
         } else if (policyTO instanceof AccountPolicyTO) {
             if (result == null) {
                 result = (T) entityFactory.newEntity(AccountPolicy.class);
@@ -119,7 +122,7 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
             });
             // remove all implementations not contained in the TO
             accountPolicy.getRules().
-                    removeIf(implementation -> !accountPolicyTO.getRules().contains(implementation.getKey()));
+                removeIf(implementation -> !accountPolicyTO.getRules().contains(implementation.getKey()));
 
             accountPolicy.getResources().clear();
             accountPolicyTO.getPassthroughResources().forEach(resourceName -> {
@@ -162,7 +165,7 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
             });
             // remove all rules not contained in the TO
             pullPolicy.getCorrelationRules().removeIf(anyFilter
-                    -> !pullPolicyTO.getCorrelationRules().containsKey(anyFilter.getAnyType().getKey()));
+                -> !pullPolicyTO.getCorrelationRules().containsKey(anyFilter.getAnyType().getKey()));
         } else if (policyTO instanceof PushPolicyTO) {
             if (result == null) {
                 result = (T) entityFactory.newEntity(PushPolicy.class);
@@ -195,7 +198,7 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
             });
             // remove all rules not contained in the TO
             pushPolicy.getCorrelationRules().removeIf(anyFilter
-                    -> !pushPolicyTO.getCorrelationRules().containsKey(anyFilter.getAnyType().getKey()));
+                -> !pushPolicyTO.getCorrelationRules().containsKey(anyFilter.getAnyType().getKey()));
         } else if (policyTO instanceof AuthenticationPolicyTO) {
             if (result == null) {
                 result = (T) entityFactory.newEntity(AuthenticationPolicy.class);
@@ -247,7 +250,7 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
             passwordPolicyTO.setHistoryLength(passwordPolicy.getHistoryLength());
 
             passwordPolicyTO.getRules().addAll(
-                    passwordPolicy.getRules().stream().map(Entity::getKey).collect(Collectors.toList()));
+                passwordPolicy.getRules().stream().map(Entity::getKey).collect(Collectors.toList()));
         } else if (policy instanceof AccountPolicy) {
             AccountPolicy accountPolicy = AccountPolicy.class.cast(policy);
             AccountPolicyTO accountPolicyTO = new AccountPolicyTO();
@@ -257,10 +260,10 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
             accountPolicyTO.setPropagateSuspension(accountPolicy.isPropagateSuspension());
 
             accountPolicyTO.getRules().addAll(
-                    accountPolicy.getRules().stream().map(Entity::getKey).collect(Collectors.toList()));
+                accountPolicy.getRules().stream().map(Entity::getKey).collect(Collectors.toList()));
 
             accountPolicyTO.getPassthroughResources().addAll(
-                    accountPolicy.getResources().stream().map(Entity::getKey).collect(Collectors.toList()));
+                accountPolicy.getResources().stream().map(Entity::getKey).collect(Collectors.toList()));
         } else if (policy instanceof PullPolicy) {
             PullPolicy pullPolicy = PullPolicy.class.cast(policy);
             PullPolicyTO pullPolicyTO = new PullPolicyTO();
@@ -268,7 +271,7 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
 
             pullPolicyTO.setConflictResolutionAction(((PullPolicy) policy).getConflictResolutionAction());
             pullPolicy.getCorrelationRules().
-                    forEach(rule -> pullPolicyTO.getCorrelationRules().
+                forEach(rule -> pullPolicyTO.getCorrelationRules().
                     put(rule.getAnyType().getKey(), rule.getImplementation().getKey()));
         } else if (policy instanceof PushPolicy) {
             PushPolicy pushPolicy = PushPolicy.class.cast(policy);
@@ -277,7 +280,7 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
 
             pushPolicyTO.setConflictResolutionAction(((PushPolicy) policy).getConflictResolutionAction());
             pushPolicy.getCorrelationRules().
-                    forEach(rule -> pushPolicyTO.getCorrelationRules().
+                forEach(rule -> pushPolicyTO.getCorrelationRules().
                     put(rule.getAnyType().getKey(), rule.getImplementation().getKey()));
         } else if (policy instanceof AuthenticationPolicy) {
             AuthenticationPolicyTO authenticationPolicyTO = new AuthenticationPolicyTO();
@@ -285,21 +288,24 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
         } else if (policy instanceof AccessPolicy) {
             AccessPolicyTO accessPolicyTO = new AccessPolicyTO();
             policyTO = (T) accessPolicyTO;
+        } else if (policy instanceof AttrReleasePolicy) {
+            AttrReleasePolicyTO attrReleasePolicyTO = new AttrReleasePolicyTO();
+            policyTO = (T) attrReleasePolicyTO;
         }
 
         if (policyTO != null) {
             policyTO.setKey(policy.getKey());
             policyTO.setDescription(policy.getDescription());
 
-            if (!(policy instanceof AuthenticationPolicy) && !(policy instanceof AccessPolicyTO)) {
+            if (!(policy instanceof AuthenticationPolicy)
+                && !(policy instanceof AccessPolicy)
+                && !(policy instanceof AttrReleasePolicy)) {
                 for (ExternalResource resource : resourceDAO.findByPolicy(policy)) {
                     policyTO.getUsedByResources().add(resource.getKey());
                 }
             }
-            if (!(policy instanceof AccessPolicyTO)) {
-                for (Realm realm : realmDAO.findByPolicy(policy)) {
-                    policyTO.getUsedByRealms().add(realm.getFullPath());
-                }
+            for (Realm realm : realmDAO.findByPolicy(policy)) {
+                policyTO.getUsedByRealms().add(realm.getFullPath());
             }
         }
 
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
index 6b5ec98..529c117 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
@@ -18,38 +18,26 @@
  */
 package org.apache.syncope.fit.core;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Set;
-import javax.ws.rs.core.Response;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.SerializationUtils;
 import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.access.DefaultAccessPolicyConf;
 import org.apache.syncope.common.lib.authentication.policy.DefaultAuthenticationPolicyConf;
-import org.apache.syncope.common.lib.to.AccessPolicyTO;
 import org.apache.syncope.common.lib.policy.AccountPolicyTO;
-import org.apache.syncope.common.lib.to.AuthenticationPolicyTO;
-import org.apache.syncope.common.lib.policy.PasswordPolicyTO;
-import org.apache.syncope.common.lib.policy.PullPolicyTO;
 import org.apache.syncope.common.lib.policy.DefaultAccountRuleConf;
-import org.apache.syncope.common.lib.types.AMImplementationType;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf;
+import org.apache.syncope.common.lib.policy.PasswordPolicyTO;
+import org.apache.syncope.common.lib.policy.PullPolicyTO;
 import org.apache.syncope.common.lib.policy.PushPolicyTO;
-import org.apache.syncope.common.lib.types.PolicyType;
+import org.apache.syncope.common.lib.to.AccessPolicyTO;
+import org.apache.syncope.common.lib.to.AuthenticationPolicyTO;
 import org.apache.syncope.common.lib.to.ImplementationTO;
+import org.apache.syncope.common.lib.types.AMImplementationType;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.IdMImplementationType;
 import org.apache.syncope.common.lib.types.IdRepoImplementationType;
 import org.apache.syncope.common.lib.types.ImplementationEngine;
+import org.apache.syncope.common.lib.types.PolicyType;
 import org.apache.syncope.common.rest.api.RESTHeaders;
 import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
 import org.apache.syncope.fit.AbstractITCase;
@@ -58,6 +46,15 @@ import org.apache.syncope.fit.core.reference.DummyPushCorrelationRule;
 import org.junit.jupiter.api.Test;
 import org.junit.platform.commons.util.StringUtils;
 
+import javax.ws.rs.core.Response;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.jupiter.api.Assertions.*;
+
 public class PolicyITCase extends AbstractITCase {
 
     private static AuthenticationPolicyTO buildAuthenticationPolicyTO() {
@@ -66,7 +63,7 @@ public class PolicyITCase extends AbstractITCase {
         ImplementationTO implementationTO = null;
         try {
             implementationTO = implementationService.read(
-                    AMImplementationType.AUTH_POLICY_CONFIGURATIONS, authPolicyName);
+                AMImplementationType.AUTH_POLICY_CONFIGURATIONS, authPolicyName);
         } catch (SyncopeClientException e) {
             if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
                 implementationTO = new ImplementationTO();
@@ -80,7 +77,7 @@ public class PolicyITCase extends AbstractITCase {
 
                 Response response = implementationService.create(implementationTO);
                 implementationTO = implementationService.read(
-                        implementationTO.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
+                    implementationTO.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
                 assertNotNull(implementationTO);
             }
         }
@@ -99,7 +96,7 @@ public class PolicyITCase extends AbstractITCase {
         ImplementationTO implementationTO = null;
         try {
             implementationTO = implementationService.read(
-                    AMImplementationType.ACCESS_POLICY_CONFIGURATIONS, accessPolicyName);
+                AMImplementationType.ACCESS_POLICY_CONFIGURATIONS, accessPolicyName);
         } catch (SyncopeClientException e) {
             if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
                 implementationTO = new ImplementationTO();
@@ -115,7 +112,7 @@ public class PolicyITCase extends AbstractITCase {
 
                 Response response = implementationService.create(implementationTO);
                 implementationTO = implementationService.read(
-                        implementationTO.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
+                    implementationTO.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
                 assertNotNull(implementationTO);
             }
         }
@@ -139,10 +136,10 @@ public class PolicyITCase extends AbstractITCase {
                 corrRule.setEngine(ImplementationEngine.GROOVY);
                 corrRule.setType(IdMImplementationType.PULL_CORRELATION_RULE);
                 corrRule.setBody(IOUtils.toString(
-                        getClass().getResourceAsStream("/TestPullRule.groovy"), StandardCharsets.UTF_8));
+                    getClass().getResourceAsStream("/TestPullRule.groovy"), StandardCharsets.UTF_8));
                 Response response = implementationService.create(corrRule);
                 corrRule = implementationService.read(
-                        corrRule.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
+                    corrRule.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
                 assertNotNull(corrRule);
             }
         }
@@ -166,10 +163,10 @@ public class PolicyITCase extends AbstractITCase {
                 corrRule.setEngine(ImplementationEngine.GROOVY);
                 corrRule.setType(IdMImplementationType.PUSH_CORRELATION_RULE);
                 corrRule.setBody(IOUtils.toString(
-                        getClass().getResourceAsStream("/TestPushRule.groovy"), StandardCharsets.UTF_8));
+                    getClass().getResourceAsStream("/TestPushRule.groovy"), StandardCharsets.UTF_8));
                 Response response = implementationService.create(corrRule);
                 corrRule = implementationService.read(
-                        corrRule.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
+                    corrRule.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
                 assertNotNull(corrRule);
             }
         }
@@ -219,7 +216,7 @@ public class PolicyITCase extends AbstractITCase {
     @Test
     public void getAuthenticationPolicy() {
         AuthenticationPolicyTO policyTO =
-                policyService.read(PolicyType.AUTHENTICATION, "659b9906-4b6e-4bc0-aca0-6809dff346d4");
+            policyService.read(PolicyType.AUTHENTICATION, "659b9906-4b6e-4bc0-aca0-6809dff346d4");
 
         assertNotNull(policyTO);
         assertTrue(policyTO.getUsedByRealms().isEmpty());
@@ -228,7 +225,7 @@ public class PolicyITCase extends AbstractITCase {
     @Test
     public void getAccessPolicy() {
         AccessPolicyTO policyTO =
-                policyService.read(PolicyType.ACCESS, "419935c7-deb3-40b3-8a9a-683037e523a2");
+            policyService.read(PolicyType.ACCESS, "419935c7-deb3-40b3-8a9a-683037e523a2");
 
         assertNotNull(policyTO);
         assertTrue(policyTO.getUsedByRealms().isEmpty());
@@ -245,7 +242,7 @@ public class PolicyITCase extends AbstractITCase {
         assertEquals("TestPushRule", pushPolicyTO.getCorrelationRules().get(AnyTypeKind.USER.name()));
 
         AuthenticationPolicyTO authenticationPolicyTO = createPolicy(PolicyType.AUTHENTICATION,
-                buildAuthenticationPolicyTO());
+            buildAuthenticationPolicyTO());
         assertNotNull(authenticationPolicyTO);
         assertEquals("Test Authentication policy", authenticationPolicyTO.getDescription());
 
@@ -256,7 +253,7 @@ public class PolicyITCase extends AbstractITCase {
 
     @Test
     public void update() {
-        // 1. Password policy
+//         1. Password policy
         PasswordPolicyTO globalPolicy = policyService.read(PolicyType.PASSWORD, "ce93fcda-dc3a-4369-a7b0-a6108c261c85");
 
         PasswordPolicyTO policy = SerializationUtils.clone(globalPolicy);
@@ -268,7 +265,7 @@ public class PolicyITCase extends AbstractITCase {
         assertNotEquals("ce93fcda-dc3a-4369-a7b0-a6108c261c85", policy.getKey());
 
         ImplementationTO rule = implementationService.read(
-                IdRepoImplementationType.PASSWORD_RULE, policy.getRules().get(0));
+            IdRepoImplementationType.PASSWORD_RULE, policy.getRules().get(0));
         assertNotNull(rule);
 
         DefaultPasswordRuleConf ruleConf = POJOHelper.deserialize(rule.getBody(), DefaultPasswordRuleConf.class);
@@ -285,25 +282,18 @@ public class PolicyITCase extends AbstractITCase {
         assertEquals(8, ruleConf.getMinLength());
 
         // 2. Authentication policy
-        AuthenticationPolicyTO globalAuthPolicyTO =
-                policyService.read(PolicyType.AUTHENTICATION, "659b9906-4b6e-4bc0-aca0-6809dff346d4");
 
-        AuthenticationPolicyTO newAuthPolicyTO = SerializationUtils.clone(globalAuthPolicyTO);
-        newAuthPolicyTO.setKey("NewAuthPolicyConf");
-        newAuthPolicyTO.setDescription("Another simple authentication policy");
-
-        // create a new authentication policy using the former as a template
-        newAuthPolicyTO = createPolicy(PolicyType.AUTHENTICATION, newAuthPolicyTO);
+        AuthenticationPolicyTO newAuthPolicyTO = buildAuthenticationPolicyTO();
         assertNotNull(newAuthPolicyTO);
-        assertNotEquals(globalAuthPolicyTO.getKey(), newAuthPolicyTO.getKey());
+        newAuthPolicyTO = createPolicy(PolicyType.AUTHENTICATION, newAuthPolicyTO);
 
         ImplementationTO authPolicyImplementationTO = implementationService.read(
-                AMImplementationType.AUTH_POLICY_CONFIGURATIONS, "MyDefaultAuthenticationPolicyConf");
+            AMImplementationType.AUTH_POLICY_CONFIGURATIONS, "MyDefaultAuthenticationPolicyConf");
         assertNotNull(authPolicyImplementationTO);
         assertFalse(StringUtils.isBlank(authPolicyImplementationTO.getBody()));
 
         DefaultAuthenticationPolicyConf authPolicyConf =
-                POJOHelper.deserialize(authPolicyImplementationTO.getBody(), DefaultAuthenticationPolicyConf.class);
+            POJOHelper.deserialize(authPolicyImplementationTO.getBody(), DefaultAuthenticationPolicyConf.class);
         assertNotNull(authPolicyConf);
         authPolicyConf.getAuthenticationModules().add("LdapAuthentication");
         authPolicyImplementationTO.setBody(POJOHelper.serialize(authPolicyConf));
@@ -313,32 +303,27 @@ public class PolicyITCase extends AbstractITCase {
         newAuthPolicyTO = policyService.read(PolicyType.AUTHENTICATION, newAuthPolicyTO.getKey());
         assertNotNull(newAuthPolicyTO);
 
-        authPolicyConf =
-                POJOHelper.deserialize(authPolicyImplementationTO.getBody(), DefaultAuthenticationPolicyConf.class);
+        authPolicyConf = POJOHelper.deserialize(authPolicyImplementationTO.getBody(), DefaultAuthenticationPolicyConf.class);
         assertNotNull(authPolicyConf);
         assertEquals(2, authPolicyConf.getAuthenticationModules().size());
         assertTrue(authPolicyConf.getAuthenticationModules().contains("LdapAuthentication"));
 
         // 3. Access policy
         AccessPolicyTO globalAccessPolicyTO =
-                policyService.read(PolicyType.ACCESS, "419935c7-deb3-40b3-8a9a-683037e523a2");
-
-        AccessPolicyTO newAccessPolicyTO = SerializationUtils.clone(globalAccessPolicyTO);
-        newAccessPolicyTO.setKey("NewAccessPolicyConf");
-        newAccessPolicyTO.setDescription("Another simple access policy");
+            policyService.read(PolicyType.ACCESS, "419935c7-deb3-40b3-8a9a-683037e523a2");
+        assertNotNull(globalAccessPolicyTO);
 
-        // create a new access policy using the former as a template
+        AccessPolicyTO newAccessPolicyTO = buildAccessPolicyTO();
         newAccessPolicyTO = createPolicy(PolicyType.ACCESS, newAccessPolicyTO);
         assertNotNull(newAccessPolicyTO);
-        assertNotEquals(globalAccessPolicyTO.getKey(), newAccessPolicyTO.getKey());
 
         ImplementationTO accessPolicyImplementationTO = implementationService.read(
-                AMImplementationType.ACCESS_POLICY_CONFIGURATIONS, "MyDefaultAccessPolicyConf");
+            AMImplementationType.ACCESS_POLICY_CONFIGURATIONS, "MyDefaultAccessPolicyConf");
         assertNotNull(accessPolicyImplementationTO);
         assertFalse(StringUtils.isBlank(accessPolicyImplementationTO.getBody()));
 
         DefaultAccessPolicyConf accessPolicyConf =
-                POJOHelper.deserialize(accessPolicyImplementationTO.getBody(), DefaultAccessPolicyConf.class);
+            POJOHelper.deserialize(accessPolicyImplementationTO.getBody(), DefaultAccessPolicyConf.class);
         assertNotNull(accessPolicyConf);
         accessPolicyConf.getRequiredAttributes().put("ou", List.of("test"));
         accessPolicyConf.getRequiredAttributes().put("cn", List.of("admin", "Admin"));
@@ -349,8 +334,7 @@ public class PolicyITCase extends AbstractITCase {
         newAccessPolicyTO = policyService.read(PolicyType.ACCESS, newAccessPolicyTO.getKey());
         assertNotNull(newAccessPolicyTO);
 
-        accessPolicyConf =
-                POJOHelper.deserialize(accessPolicyImplementationTO.getBody(), DefaultAccessPolicyConf.class);
+        accessPolicyConf = POJOHelper.deserialize(accessPolicyImplementationTO.getBody(), DefaultAccessPolicyConf.class);
         assertEquals(2, accessPolicyConf.getRequiredAttributes().size());
         assertNotNull(accessPolicyConf.getRequiredAttributes().get("cn"));
         assertNotNull(accessPolicyConf.getRequiredAttributes().get("ou"));
@@ -405,7 +389,7 @@ public class PolicyITCase extends AbstractITCase {
     @Test
     public void getPullCorrelationRuleJavaClasses() {
         Set<String> classes = syncopeService.platform().
-                getJavaImplInfo(IdMImplementationType.PULL_CORRELATION_RULE).get().getClasses();
+            getJavaImplInfo(IdMImplementationType.PULL_CORRELATION_RULE).get().getClasses();
         assertEquals(1, classes.size());
         assertEquals(DummyPullCorrelationRule.class.getName(), classes.iterator().next());
     }
@@ -413,7 +397,7 @@ public class PolicyITCase extends AbstractITCase {
     @Test
     public void getPushCorrelationRuleJavaClasses() {
         Set<String> classes = syncopeService.platform().
-                getJavaImplInfo(IdMImplementationType.PUSH_CORRELATION_RULE).get().getClasses();
+            getJavaImplInfo(IdMImplementationType.PUSH_CORRELATION_RULE).get().getClasses();
         assertEquals(1, classes.size());
         assertEquals(DummyPushCorrelationRule.class.getName(), classes.iterator().next());
     }