syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdisabat...@apache.org
Subject [03/33] syncope git commit: [SYNCOPE-685] Pre: more cleanup
Date Thu, 27 Aug 2015 11:12:30 GMT
[SYNCOPE-685] Pre: more cleanup


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/2cf76197
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/2cf76197
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/2cf76197

Branch: refs/heads/SYNCOPE-156
Commit: 2cf761973049f874380d5ac054b4daf95360fc57
Parents: fc91e51
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Mon Aug 17 17:56:15 2015 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Mon Aug 17 17:56:15 2015 +0200

----------------------------------------------------------------------
 .../common/lib/types/PushPolicySpec.java        | 28 ++++++++++
 .../syncope/core/misc/ConnObjectUtils.java      |  8 +--
 .../core/misc/policy/PolicyEvaluator.java       |  6 +-
 .../core/misc/security/PasswordGenerator.java   |  8 +--
 .../persistence/api/entity/AccountPolicy.java   |  5 ++
 .../persistence/api/entity/PasswordPolicy.java  |  8 ++-
 .../core/persistence/api/entity/Policy.java     |  5 --
 .../core/persistence/api/entity/PushPolicy.java |  7 ++-
 .../core/persistence/api/entity/SyncPolicy.java |  8 ++-
 .../jpa/entity/JPAAccountPolicy.java            | 12 ++++
 .../jpa/entity/JPAPasswordPolicy.java           | 12 ++++
 .../core/persistence/jpa/entity/JPAPolicy.java  | 16 +-----
 .../persistence/jpa/entity/JPAPushPolicy.java   | 16 ++++--
 .../persistence/jpa/entity/JPASyncPolicy.java   | 12 ++++
 .../jpa/validation/entity/PolicyCheck.java      | 41 --------------
 .../jpa/validation/entity/PolicyValidator.java  | 59 --------------------
 .../core/persistence/jpa/inner/PolicyTest.java  | 31 +++-------
 .../java/data/PolicyDataBinderImpl.java         | 18 +++---
 .../provisioning/java/sync/SyncJobDelegate.java |  2 +-
 .../core/provisioning/java/sync/SyncUtils.java  |  2 +-
 20 files changed, 132 insertions(+), 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/common/lib/src/main/java/org/apache/syncope/common/lib/types/PushPolicySpec.java
----------------------------------------------------------------------
diff --git a/common/lib/src/main/java/org/apache/syncope/common/lib/types/PushPolicySpec.java
b/common/lib/src/main/java/org/apache/syncope/common/lib/types/PushPolicySpec.java
new file mode 100644
index 0000000..d7a5640
--- /dev/null
+++ b/common/lib/src/main/java/org/apache/syncope/common/lib/types/PushPolicySpec.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.common.lib.types;
+
+import javax.xml.bind.annotation.XmlType;
+
+@XmlType
+public class PushPolicySpec implements PolicySpec {
+
+    private static final long serialVersionUID = 3641030189482617497L;
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java
index 6257d59..de1bcfb 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java
@@ -123,9 +123,9 @@ public class ConnObjectUtils {
             if (realm != null) {
                 for (Realm ancestor : realmDAO.findAncestors(realm)) {
                     if (ancestor.getPasswordPolicy() != null
-                            && ancestor.getPasswordPolicy().getSpecification(PasswordPolicySpec.class)
!= null) {
+                            && ancestor.getPasswordPolicy().getSpecification() !=
null) {
 
-                        ppSpecs.add(ancestor.getPasswordPolicy().getSpecification(PasswordPolicySpec.class));
+                        ppSpecs.add(ancestor.getPasswordPolicy().getSpecification());
                     }
                 }
             }
@@ -133,9 +133,9 @@ public class ConnObjectUtils {
             for (String resName : userTO.getResources()) {
                 ExternalResource resource = resourceDAO.find(resName);
                 if (resource != null && resource.getPasswordPolicy() != null
-                        && resource.getPasswordPolicy().getSpecification(PasswordPolicySpec.class)
!= null) {
+                        && resource.getPasswordPolicy().getSpecification() != null)
{
 
-                    ppSpecs.add(resource.getPasswordPolicy().getSpecification(PasswordPolicySpec.class));
+                    ppSpecs.add(resource.getPasswordPolicy().getSpecification());
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEvaluator.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEvaluator.java
b/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEvaluator.java
index 425568d..f7d946c 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEvaluator.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/policy/PolicyEvaluator.java
@@ -22,7 +22,9 @@ import java.util.List;
 import org.apache.syncope.common.lib.types.AccountPolicySpec;
 import org.apache.syncope.common.lib.types.PasswordPolicySpec;
 import org.apache.syncope.common.lib.types.PolicySpec;
+import org.apache.syncope.core.persistence.api.entity.AccountPolicy;
 import org.apache.syncope.core.persistence.api.entity.Any;
+import org.apache.syncope.core.persistence.api.entity.PasswordPolicy;
 import org.apache.syncope.core.persistence.api.entity.PlainAttr;
 import org.apache.syncope.core.persistence.api.entity.Policy;
 import org.apache.syncope.core.persistence.api.entity.user.User;
@@ -41,7 +43,7 @@ public class PolicyEvaluator {
         T result;
         switch (policy.getType()) {
             case PASSWORD:
-                PasswordPolicySpec ppSpec = policy.getSpecification(PasswordPolicySpec.class);
+                PasswordPolicySpec ppSpec = ((PasswordPolicy) policy).getSpecification();
                 PasswordPolicySpec evaluatedPPSpec = new PasswordPolicySpec();
 
                 BeanUtils.copyProperties(ppSpec, evaluatedPPSpec, new String[] { "schemasNotPermitted"
});
@@ -71,7 +73,7 @@ public class PolicyEvaluator {
                 break;
 
             case ACCOUNT:
-                AccountPolicySpec spec = policy.getSpecification(AccountPolicySpec.class);
+                AccountPolicySpec spec = ((AccountPolicy) policy).getSpecification();
                 AccountPolicySpec accountPolicy = new AccountPolicySpec();
 
                 BeanUtils.copyProperties(spec, accountPolicy, new String[] { "schemasNotPermitted"
});

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/misc/src/main/java/org/apache/syncope/core/misc/security/PasswordGenerator.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/PasswordGenerator.java
b/core/misc/src/main/java/org/apache/syncope/core/misc/security/PasswordGenerator.java
index 9514f27..d5e2e14 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/PasswordGenerator.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/security/PasswordGenerator.java
@@ -71,17 +71,17 @@ public class PasswordGenerator {
 
         for (Realm ancestor : realmDAO.findAncestors(user.getRealm())) {
             if (ancestor.getPasswordPolicy() != null
-                    && ancestor.getPasswordPolicy().getSpecification(PasswordPolicySpec.class)
!= null) {
+                    && ancestor.getPasswordPolicy().getSpecification() != null) {
 
-                ppSpecs.add(ancestor.getPasswordPolicy().getSpecification(PasswordPolicySpec.class));
+                ppSpecs.add(ancestor.getPasswordPolicy().getSpecification());
             }
         }
 
         for (ExternalResource resource : userDAO.findAllResources(user)) {
             if (resource.getPasswordPolicy() != null
-                    && resource.getPasswordPolicy().getSpecification(PasswordPolicySpec.class)
!= null) {
+                    && resource.getPasswordPolicy().getSpecification() != null) {
 
-                ppSpecs.add(resource.getPasswordPolicy().getSpecification(PasswordPolicySpec.class));
+                ppSpecs.add(resource.getPasswordPolicy().getSpecification());
             }
         }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/AccountPolicy.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/AccountPolicy.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/AccountPolicy.java
index bafc554..72f8cac 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/AccountPolicy.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/AccountPolicy.java
@@ -20,9 +20,14 @@ package org.apache.syncope.core.persistence.api.entity;
 
 import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
 import java.util.Set;
+import org.apache.syncope.common.lib.types.AccountPolicySpec;
 
 public interface AccountPolicy extends Policy {
 
+    AccountPolicySpec getSpecification();
+
+    void setSpecification(AccountPolicySpec spec);
+    
     boolean add(ExternalResource resource);
 
     boolean remove(ExternalResource resource);

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PasswordPolicy.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PasswordPolicy.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PasswordPolicy.java
index 4981ff2..a4004ce 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PasswordPolicy.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PasswordPolicy.java
@@ -18,6 +18,12 @@
  */
 package org.apache.syncope.core.persistence.api.entity;
 
+import org.apache.syncope.common.lib.types.PasswordPolicySpec;
+
 public interface PasswordPolicy extends Policy {
-    
+
+    PasswordPolicySpec getSpecification();
+
+    void setSpecification(PasswordPolicySpec spec);
+
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/Policy.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/Policy.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/Policy.java
index 5edca88..d02de0a 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/Policy.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/Policy.java
@@ -18,18 +18,13 @@
  */
 package org.apache.syncope.core.persistence.api.entity;
 
-import org.apache.syncope.common.lib.types.PolicySpec;
 import org.apache.syncope.common.lib.types.PolicyType;
 
 public interface Policy extends Entity<Long> {
 
     String getDescription();
 
-    <T extends PolicySpec> T getSpecification(Class<T> reference);
-
     PolicyType getType();
 
     void setDescription(String description);
-
-    void setSpecification(PolicySpec policy);
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PushPolicy.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PushPolicy.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PushPolicy.java
index 761525d..e1c37df 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PushPolicy.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/PushPolicy.java
@@ -18,6 +18,11 @@
  */
 package org.apache.syncope.core.persistence.api.entity;
 
+import org.apache.syncope.common.lib.types.PushPolicySpec;
+
 public interface PushPolicy extends Policy {
-    
+
+    PushPolicySpec getSpecification();
+
+    void setSpecification(PushPolicySpec spec);
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/SyncPolicy.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/SyncPolicy.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/SyncPolicy.java
index 3acb092..1e389d7 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/SyncPolicy.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/SyncPolicy.java
@@ -18,6 +18,12 @@
  */
 package org.apache.syncope.core.persistence.api.entity;
 
+import org.apache.syncope.common.lib.types.SyncPolicySpec;
+
 public interface SyncPolicy extends Policy {
-    
+
+    SyncPolicySpec getSpecification();
+
+    void setSpecification(SyncPolicySpec spec);
+
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAccountPolicy.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAccountPolicy.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAccountPolicy.java
index 64475aa..844b49a 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAccountPolicy.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAccountPolicy.java
@@ -28,7 +28,9 @@ import javax.persistence.JoinTable;
 import javax.persistence.ManyToMany;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.Transformer;
+import org.apache.syncope.common.lib.types.AccountPolicySpec;
 import org.apache.syncope.common.lib.types.PolicyType;
+import org.apache.syncope.core.misc.serialization.POJOHelper;
 import org.apache.syncope.core.persistence.api.entity.AccountPolicy;
 import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
 import org.apache.syncope.core.persistence.jpa.entity.resource.JPAExternalResource;
@@ -55,6 +57,16 @@ public class JPAAccountPolicy extends JPAPolicy implements AccountPolicy
{
     }
 
     @Override
+    public AccountPolicySpec getSpecification() {
+        return POJOHelper.deserialize(specification, AccountPolicySpec.class);
+    }
+
+    @Override
+    public void setSpecification(final AccountPolicySpec policy) {
+        this.specification = POJOHelper.serialize(policy);
+    }
+
+    @Override
     public boolean add(final ExternalResource resource) {
         checkType(resource, JPAExternalResource.class);
         return resources.add((JPAExternalResource) resource);

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPasswordPolicy.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPasswordPolicy.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPasswordPolicy.java
index 51f55a5..8a755f4 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPasswordPolicy.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPasswordPolicy.java
@@ -20,7 +20,9 @@ package org.apache.syncope.core.persistence.jpa.entity;
 
 import javax.persistence.DiscriminatorValue;
 import javax.persistence.Entity;
+import org.apache.syncope.common.lib.types.PasswordPolicySpec;
 import org.apache.syncope.common.lib.types.PolicyType;
+import org.apache.syncope.core.misc.serialization.POJOHelper;
 import org.apache.syncope.core.persistence.api.entity.PasswordPolicy;
 
 @Entity
@@ -33,4 +35,14 @@ public class JPAPasswordPolicy extends JPAPolicy implements PasswordPolicy
{
         super();
         this.type = PolicyType.PASSWORD;
     }
+
+    @Override
+    public PasswordPolicySpec getSpecification() {
+        return POJOHelper.deserialize(specification, PasswordPolicySpec.class);
+    }
+
+    @Override
+    public void setSpecification(final PasswordPolicySpec policy) {
+        this.specification = POJOHelper.serialize(policy);
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPolicy.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPolicy.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPolicy.java
index 3104c23..1dc5de6 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPolicy.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPolicy.java
@@ -28,17 +28,13 @@ import javax.persistence.InheritanceType;
 import javax.persistence.Lob;
 import javax.persistence.Table;
 import javax.validation.constraints.NotNull;
-import org.apache.syncope.common.lib.types.PolicySpec;
 import org.apache.syncope.common.lib.types.PolicyType;
 import org.apache.syncope.core.persistence.api.entity.Policy;
-import org.apache.syncope.core.persistence.jpa.validation.entity.PolicyCheck;
-import org.apache.syncope.core.misc.serialization.POJOHelper;
 
 @Entity
 @Table(name = JPAPolicy.TABLE)
 @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
 @DiscriminatorColumn(name = "DTYPE")
-@PolicyCheck
 public abstract class JPAPolicy extends AbstractEntity<Long> implements Policy {
 
     private static final long serialVersionUID = -5844833125843247458L;
@@ -56,7 +52,7 @@ public abstract class JPAPolicy extends AbstractEntity<Long> implements
Policy {
     protected PolicyType type;
 
     @Lob
-    private String specification;
+    protected String specification;
 
     @Override
     public Long getKey() {
@@ -77,14 +73,4 @@ public abstract class JPAPolicy extends AbstractEntity<Long> implements
Policy {
     public PolicyType getType() {
         return type;
     }
-
-    @Override
-    public <T extends PolicySpec> T getSpecification(final Class<T> reference)
{
-        return POJOHelper.deserialize(specification, reference);
-    }
-
-    @Override
-    public void setSpecification(final PolicySpec policy) {
-        this.specification = POJOHelper.serialize(policy);
-    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPushPolicy.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPushPolicy.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPushPolicy.java
index f4be722..c3440b2 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPushPolicy.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAPushPolicy.java
@@ -20,6 +20,8 @@ package org.apache.syncope.core.persistence.jpa.entity;
 
 import javax.persistence.Entity;
 import org.apache.syncope.common.lib.types.PolicyType;
+import org.apache.syncope.common.lib.types.PushPolicySpec;
+import org.apache.syncope.core.misc.serialization.POJOHelper;
 import org.apache.syncope.core.persistence.api.entity.PushPolicy;
 
 @Entity
@@ -28,12 +30,18 @@ public class JPAPushPolicy extends JPAPolicy implements PushPolicy {
     private static final long serialVersionUID = -5875589156893921113L;
 
     public JPAPushPolicy() {
-        this(false);
-    }
-
-    public JPAPushPolicy(final boolean global) {
         super();
         this.type = PolicyType.PUSH;
     }
 
+    @Override
+    public PushPolicySpec getSpecification() {
+        return POJOHelper.deserialize(specification, PushPolicySpec.class);
+    }
+
+    @Override
+    public void setSpecification(final PushPolicySpec policy) {
+        this.specification = POJOHelper.serialize(policy);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPASyncPolicy.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPASyncPolicy.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPASyncPolicy.java
index 39b7565..e244223 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPASyncPolicy.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPASyncPolicy.java
@@ -20,7 +20,9 @@ package org.apache.syncope.core.persistence.jpa.entity;
 
 import javax.persistence.DiscriminatorValue;
 import javax.persistence.Entity;
+import org.apache.syncope.common.lib.types.SyncPolicySpec;
 import org.apache.syncope.common.lib.types.PolicyType;
+import org.apache.syncope.core.misc.serialization.POJOHelper;
 import org.apache.syncope.core.persistence.api.entity.SyncPolicy;
 
 @Entity
@@ -33,4 +35,14 @@ public class JPASyncPolicy extends JPAPolicy implements SyncPolicy {
         super();
         this.type = PolicyType.SYNC;
     }
+
+    @Override
+    public SyncPolicySpec getSpecification() {
+        return POJOHelper.deserialize(specification, SyncPolicySpec.class);
+    }
+
+    @Override
+    public void setSpecification(final SyncPolicySpec policy) {
+        this.specification = POJOHelper.serialize(policy);
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/PolicyCheck.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/PolicyCheck.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/PolicyCheck.java
deleted file mode 100644
index 45873be..0000000
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/PolicyCheck.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.persistence.jpa.validation.entity;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import javax.validation.Constraint;
-import javax.validation.Payload;
-
-@Target({ ElementType.TYPE })
-@Retention(RetentionPolicy.RUNTIME)
-@Constraint(validatedBy = PolicyValidator.class)
-@Documented
-public @interface PolicyCheck {
-
-    String message() default "{org.apache.syncope.core.persistence.validation.policy}";
-
-    Class<?>[] groups() default {};
-
-    Class<? extends Payload>[] payload() default {};
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/PolicyValidator.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/PolicyValidator.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/PolicyValidator.java
deleted file mode 100644
index fd95c4c..0000000
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/validation/entity/PolicyValidator.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.persistence.jpa.validation.entity;
-
-import javax.validation.ConstraintValidatorContext;
-import org.apache.syncope.common.lib.types.AccountPolicySpec;
-import org.apache.syncope.common.lib.types.EntityViolationType;
-import org.apache.syncope.common.lib.types.PasswordPolicySpec;
-import org.apache.syncope.common.lib.types.SyncPolicySpec;
-import org.apache.syncope.core.persistence.api.entity.AccountPolicy;
-import org.apache.syncope.core.persistence.api.entity.PasswordPolicy;
-import org.apache.syncope.core.persistence.api.entity.Policy;
-import org.apache.syncope.core.persistence.api.entity.SyncPolicy;
-
-public class PolicyValidator extends AbstractValidator<PolicyCheck, Policy> {
-
-    @Override
-    public boolean isValid(final Policy object, final ConstraintValidatorContext context)
{
-        context.disableDefaultConstraintViolation();
-
-        EntityViolationType violationType =
-                object instanceof PasswordPolicy
-                && !(object.getSpecification(PasswordPolicySpec.class) instanceof
PasswordPolicySpec)
-                        ? EntityViolationType.InvalidPasswordPolicy
-                        : object instanceof AccountPolicy
-                        && !(object.getSpecification(AccountPolicySpec.class) instanceof
AccountPolicySpec)
-                                ? EntityViolationType.InvalidAccountPolicy
-                                : object instanceof SyncPolicy
-                                && !(object.getSpecification(SyncPolicySpec.class)
instanceof SyncPolicySpec)
-                                        ? EntityViolationType.InvalidSyncPolicy
-                                        : null;
-
-        if (violationType != null) {
-            context.buildConstraintViolationWithTemplate(getTemplate(violationType,
-                    "Invalid policy specification")).addPropertyNode("specification").
-                    addConstraintViolation();
-
-            return false;
-        }
-
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
index 603cd01..780d192 100644
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
@@ -31,9 +31,9 @@ import org.apache.syncope.common.lib.types.PasswordPolicySpec;
 import org.apache.syncope.common.lib.types.PolicyType;
 import org.apache.syncope.common.lib.types.SyncPolicySpec;
 import org.apache.syncope.core.misc.serialization.POJOHelper;
-import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
 import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
 import org.apache.syncope.core.persistence.api.dao.PolicyDAO;
+import org.apache.syncope.core.persistence.api.entity.PasswordPolicy;
 import org.apache.syncope.core.persistence.api.entity.Policy;
 import org.apache.syncope.core.persistence.api.entity.SyncPolicy;
 import org.apache.syncope.core.persistence.jpa.AbstractTest;
@@ -62,7 +62,7 @@ public class PolicyTest extends AbstractTest {
         SyncPolicy policy = policyDAO.find(3L);
         assertNotNull("findById did not work", policy);
 
-        SyncPolicySpec spec = policy.getSpecification(SyncPolicySpec.class);
+        SyncPolicySpec spec = policy.getSpecification();
         assertNotNull(spec);
 
         String rule = spec.getCorrelationRules().get(AnyTypeKind.USER.name());
@@ -81,19 +81,6 @@ public class PolicyTest extends AbstractTest {
         assertFalse(policies.isEmpty());
     }
 
-    @Test(expected = InvalidEntityException.class)
-    public void saveInvalidPolicy() {
-        PasswordPolicySpec passwordPolicy = new PasswordPolicySpec();
-        passwordPolicy.setMaxLength(8);
-        passwordPolicy.setMinLength(6);
-
-        SyncPolicy policy = entityFactory.newEntity(SyncPolicy.class);
-        policy.setSpecification(passwordPolicy);
-        policy.setDescription("sync policy");
-
-        policyDAO.save(policy);
-    }
-
     @Test
     public void create() {
         SyncPolicy policy = entityFactory.newEntity(SyncPolicy.class);
@@ -113,10 +100,10 @@ public class PolicyTest extends AbstractTest {
 
         assertNotNull(policy);
         assertEquals(PolicyType.SYNC, policy.getType());
-        assertEquals(syncURuleName, (policy.getSpecification(SyncPolicySpec.class)).
-                getCorrelationRules().get(anyTypeDAO.findUser().getKey()));
-        assertEquals(syncGRuleName, (policy.getSpecification(SyncPolicySpec.class)).
-                getCorrelationRules().get(anyTypeDAO.findGroup().getKey()));
+        assertEquals(syncURuleName,
+                policy.getSpecification().getCorrelationRules().get(anyTypeDAO.findUser().getKey()));
+        assertEquals(syncGRuleName,
+                policy.getSpecification().getCorrelationRules().get(anyTypeDAO.findGroup().getKey()));
     }
 
     @Test
@@ -125,7 +112,7 @@ public class PolicyTest extends AbstractTest {
         specification.setMaxLength(8);
         specification.setMinLength(6);
 
-        Policy policy = policyDAO.find(2L);
+        PasswordPolicy policy = policyDAO.find(2L);
         assertNotNull(policy);
         policy.setSpecification(specification);
 
@@ -133,8 +120,8 @@ public class PolicyTest extends AbstractTest {
 
         assertNotNull(policy);
         assertEquals(PolicyType.PASSWORD, policy.getType());
-        assertEquals((policy.getSpecification(PasswordPolicySpec.class)).getMaxLength(),
8);
-        assertEquals((policy.getSpecification(PasswordPolicySpec.class)).getMinLength(),
6);
+        assertEquals(policy.getSpecification().getMaxLength(), 8);
+        assertEquals(policy.getSpecification().getMinLength(), 6);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/PolicyDataBinderImpl.java
----------------------------------------------------------------------
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 fa53bbd..7180b6c 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
@@ -24,10 +24,7 @@ import org.apache.syncope.common.lib.to.AbstractPolicyTO;
 import org.apache.syncope.common.lib.to.AccountPolicyTO;
 import org.apache.syncope.common.lib.to.PasswordPolicyTO;
 import org.apache.syncope.common.lib.to.SyncPolicyTO;
-import org.apache.syncope.common.lib.types.AccountPolicySpec;
 import org.apache.syncope.common.lib.types.ClientExceptionType;
-import org.apache.syncope.common.lib.types.PasswordPolicySpec;
-import org.apache.syncope.common.lib.types.SyncPolicySpec;
 import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
 import org.apache.syncope.core.persistence.api.dao.RealmDAO;
 import org.apache.syncope.core.persistence.api.entity.AccountPolicy;
@@ -59,24 +56,23 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
     @SuppressWarnings("unchecked")
     @Override
     public <T extends AbstractPolicyTO> T getPolicyTO(final Policy policy) {
-        final T policyTO;
-
+        T policyTO;
         switch (policy.getType()) {
             case PASSWORD:
                 policyTO = (T) new PasswordPolicyTO();
-                ((PasswordPolicyTO) policyTO).setSpecification(policy.getSpecification(PasswordPolicySpec.class));
+                ((PasswordPolicyTO) policyTO).setSpecification(((PasswordPolicy) policy).getSpecification());
                 break;
 
             case ACCOUNT:
                 policyTO = (T) new AccountPolicyTO();
-                ((AccountPolicyTO) policyTO).setSpecification(policy.getSpecification(AccountPolicySpec.class));
+                ((AccountPolicyTO) policyTO).setSpecification(((AccountPolicy) policy).getSpecification());
                 ((AccountPolicyTO) policyTO).getResources().addAll(((AccountPolicy) policy).getResourceNames());
                 break;
 
             case SYNC:
             default:
                 policyTO = (T) new SyncPolicyTO();
-                ((SyncPolicyTO) policyTO).setSpecification(policy.getSpecification(SyncPolicySpec.class));
+                ((SyncPolicyTO) policyTO).setSpecification(((SyncPolicy) policy).getSpecification());
         }
 
         policyTO.setKey(policy.getKey());
@@ -120,7 +116,7 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
                 if (result == null) {
                     result = (T) entityFactory.newEntity(PasswordPolicy.class);
                 }
-                result.setSpecification(((PasswordPolicyTO) policyTO).getSpecification());
+                ((PasswordPolicy) result).setSpecification(((PasswordPolicyTO) policyTO).getSpecification());
                 break;
 
             case ACCOUNT:
@@ -131,7 +127,7 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
                 if (result == null) {
                     result = (T) entityFactory.newEntity(AccountPolicy.class);
                 }
-                result.setSpecification(((AccountPolicyTO) policyTO).getSpecification());
+                ((AccountPolicy) result).setSpecification(((AccountPolicyTO) policyTO).getSpecification());
 
                 if (((AccountPolicy) result).getResources() != null
                         && !((AccountPolicy) result).getResources().isEmpty()) {
@@ -155,7 +151,7 @@ public class PolicyDataBinderImpl implements PolicyDataBinder {
                 if (result == null) {
                     result = (T) entityFactory.newEntity(SyncPolicy.class);
                 }
-                result.setSpecification(((SyncPolicyTO) policyTO).getSpecification());
+                ((SyncPolicy) result).setSpecification(((SyncPolicyTO) policyTO).getSpecification());
         }
 
         result.setDescription(policyTO.getDescription());

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncJobDelegate.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncJobDelegate.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncJobDelegate.java
index 245a74a..2e70e80 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncJobDelegate.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncJobDelegate.java
@@ -210,7 +210,7 @@ public class SyncJobDelegate extends AbstractProvisioningJobDelegate<SyncTask>
{
         if (task instanceof SyncTask) {
             syncPolicySpec = task.getResource().getSyncPolicy() == null
                     ? null
-                    : task.getResource().getSyncPolicy().getSpecification(SyncPolicySpec.class);
+                    : task.getResource().getSyncPolicy().getSpecification();
         } else {
             syncPolicySpec = null;
         }

http://git-wip-us.apache.org/repos/asf/syncope/blob/2cf76197/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncUtils.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncUtils.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncUtils.java
index 7fd244b..4878362 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncUtils.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncUtils.java
@@ -279,7 +279,7 @@ public class SyncUtils {
 
         SyncPolicySpec syncPolicySpec = null;
         if (provision.getResource().getSyncPolicy() != null) {
-            syncPolicySpec = provision.getResource().getSyncPolicy().getSpecification(SyncPolicySpec.class);
+            syncPolicySpec = provision.getResource().getSyncPolicy().getSpecification();
         }
 
         SyncCorrelationRule syncRule = null;


Mime
View raw message