syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [syncope] branch master updated: [SYNCOPE-1441] Adjusting jpa-json
Date Tue, 16 Apr 2019 13:05:00 GMT
This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/master by this push:
     new 92fbcc9  [SYNCOPE-1441] Adjusting jpa-json
92fbcc9 is described below

commit 92fbcc952720d900cfada1410fb3c9028931843a
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
AuthorDate: Tue Apr 16 15:02:57 2019 +0200

    [SYNCOPE-1441] Adjusting jpa-json
---
 .../persistence/jpa/dao/JPAJSONAnyObjectDAO.java   | 19 ++++++++++++
 .../core/persistence/jpa/dao/JPAJSONUserDAO.java   | 35 ++++++++++++++++++++++
 .../jpa/entity/anyobject/JPAJSONAnyObject.java     | 19 ++++++------
 .../persistence/jpa/entity/conf/JPAJSONConf.java   |  2 +-
 .../persistence/jpa/entity/group/JPAJSONGroup.java |  2 +-
 .../persistence/jpa/entity/user/JPAJSONUser.java   | 19 ++++++------
 .../core/persistence/jpa/dao/JPAAnyObjectDAO.java  | 10 +++----
 .../core/persistence/jpa/dao/JPAUserDAO.java       | 22 +++++++-------
 8 files changed, 90 insertions(+), 38 deletions(-)

diff --git a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONAnyObjectDAO.java
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONAnyObjectDAO.java
index a6906bd..473d6f1 100644
--- a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONAnyObjectDAO.java
+++ b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONAnyObjectDAO.java
@@ -19,6 +19,8 @@
 package org.apache.syncope.core.persistence.jpa.dao;
 
 import java.util.List;
+import java.util.Set;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
 import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAJSONAnyObject;
@@ -26,6 +28,8 @@ import org.apache.syncope.core.spring.ApplicationContextProvider;
 import org.apache.syncope.core.persistence.api.dao.JPAJSONAnyDAO;
 import org.apache.syncope.core.persistence.api.entity.DerSchema;
 import org.apache.syncope.core.persistence.api.entity.PlainSchema;
+import org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent;
+import org.apache.syncope.core.spring.security.AuthContextUtils;
 
 public class JPAJSONAnyObjectDAO extends JPAAnyObjectDAO {
 
@@ -68,6 +72,21 @@ public class JPAJSONAnyObjectDAO extends JPAAnyObjectDAO {
     }
 
     @Override
+    protected Pair<AnyObject, Pair<Set<String>, Set<String>>> doSave(final
AnyObject anyObject) {
+        AnyObject merged = entityManager().merge(anyObject);
+
+        // ensure that entity listeners are invoked at this point
+        entityManager().flush();
+
+        publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, merged, AuthContextUtils.getDomain()));
+
+        Pair<Set<String>, Set<String>> dynGroupMembs = groupDAO.refreshDynMemberships(merged);
+        dynRealmDAO.refreshDynMemberships(merged);
+
+        return Pair.of(merged, dynGroupMembs);
+    }
+
+    @Override
     public AnyObject save(final AnyObject anyObject) {
         anyDAO().checkBeforeSave(JPAJSONAnyObject.TABLE, anyUtils(), anyObject);
         return super.save(anyObject);
diff --git a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONUserDAO.java
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONUserDAO.java
index c2c43be..a995a38 100644
--- a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONUserDAO.java
+++ b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAJSONUserDAO.java
@@ -21,6 +21,7 @@ package org.apache.syncope.core.persistence.jpa.dao;
 import java.util.List;
 import java.util.Set;
 import org.apache.commons.lang3.tuple.Pair;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
 import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
 import org.apache.syncope.core.persistence.api.entity.user.User;
 import org.apache.syncope.core.persistence.jpa.entity.user.JPAJSONUser;
@@ -28,6 +29,9 @@ import org.apache.syncope.core.spring.ApplicationContextProvider;
 import org.apache.syncope.core.persistence.api.dao.JPAJSONAnyDAO;
 import org.apache.syncope.core.persistence.api.entity.DerSchema;
 import org.apache.syncope.core.persistence.api.entity.PlainSchema;
+import org.apache.syncope.core.persistence.jpa.entity.user.JPAUser;
+import org.apache.syncope.core.provisioning.api.event.AnyCreatedUpdatedEvent;
+import org.apache.syncope.core.spring.security.AuthContextUtils;
 
 public class JPAJSONUserDAO extends JPAUserDAO {
 
@@ -70,6 +74,37 @@ public class JPAJSONUserDAO extends JPAUserDAO {
     }
 
     @Override
+    protected Pair<User, Pair<Set<String>, Set<String>>> doSave(final
User user) {
+        // 1. save clear password value before save
+        String clearPwd = user.getClearPassword();
+
+        // 2. save
+        User merged = entityManager().merge(user);
+
+        // 3. set back the sole clear password value
+        JPAUser.class.cast(merged).setClearPassword(clearPwd);
+
+        // 4. enforce password and account policies
+        try {
+            enforcePolicies(merged);
+        } catch (InvalidEntityException e) {
+            entityManager().remove(merged);
+            throw e;
+        }
+
+        // ensure that entity listeners are invoked at this point
+        entityManager().flush();
+
+        publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, merged, AuthContextUtils.getDomain()));
+
+        roleDAO.refreshDynMemberships(merged);
+        Pair<Set<String>, Set<String>> dynGroupMembs = groupDAO.refreshDynMemberships(merged);
+        dynRealmDAO.refreshDynMemberships(merged);
+
+        return Pair.of(merged, dynGroupMembs);
+    }
+
+    @Override
     public User save(final User user) {
         anyDAO().checkBeforeSave(JPAJSONUser.TABLE, anyUtils(), user);
         return super.save(user);
diff --git a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/anyobject/JPAJSONAnyObject.java
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/anyobject/JPAJSONAnyObject.java
index df8bb8a..0c7c371 100644
--- a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/anyobject/JPAJSONAnyObject.java
+++ b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/anyobject/JPAJSONAnyObject.java
@@ -76,9 +76,8 @@ public class JPAJSONAnyObject extends JPAAnyObject implements JSONAny<AnyObject>
 
     @Override
     public boolean remove(final APlainAttr attr) {
-        return plainAttrList.removeIf(pgattr
-                -> pgattr.getSchemaKey().equals(attr.getSchema().getKey())
-                && Objects.equals(pgattr.getMembershipKey(), ((JPAJSONAPlainAttr)
attr).getMembershipKey()));
+        return plainAttrList.removeIf(jsonAttr -> jsonAttr.getSchemaKey().equals(attr.getSchema().getKey())
+                && Objects.equals(jsonAttr.getMembershipKey(), ((JPAJSONAPlainAttr)
attr).getMembershipKey()));
     }
 
     @Override
@@ -89,30 +88,30 @@ public class JPAJSONAnyObject extends JPAAnyObject implements JSONAny<AnyObject>
     @Override
     public List<? extends APlainAttr> getPlainAttrs() {
         return plainAttrList.stream().
-                filter(pgattr -> pgattr.getMembershipKey() == null).
+                filter(attr -> attr.getMembershipKey() == null).
                 collect(Collectors.toList());
     }
 
     @Override
     public Optional<? extends APlainAttr> getPlainAttr(final String plainSchema) {
         return plainAttrList.stream().
-                filter(pgattr -> pgattr.getSchemaKey() != null && pgattr.getSchemaKey().equals(plainSchema)
-                && pgattr.getMembershipKey() == null).
+                filter(attr -> attr.getSchemaKey() != null && attr.getSchemaKey().equals(plainSchema)
+                && attr.getMembershipKey() == null).
                 findFirst();
     }
 
     @Override
     public Optional<? extends APlainAttr> getPlainAttr(final String plainSchema, final
Membership<?> membership) {
         return plainAttrList.stream().
-                filter(pgattr -> pgattr.getSchemaKey() != null && pgattr.getSchemaKey().equals(plainSchema)
-                && pgattr.getMembershipKey() != null && pgattr.getMembershipKey().equals(membership.getKey())).
+                filter(attr -> attr.getSchemaKey() != null && attr.getSchemaKey().equals(plainSchema)
+                && attr.getMembershipKey() != null && attr.getMembershipKey().equals(membership.getKey())).
                 findFirst();
     }
 
     @Override
     public boolean remove(final AMembership membership) {
-        plainAttrList.removeIf(pgattr
-                -> pgattr.getMembershipKey() != null && pgattr.getMembershipKey().equals(membership.getKey()));
+        plainAttrList.removeIf(attr -> attr.getMembershipKey() != null
+                && attr.getMembershipKey().equals(membership.getKey()));
         return super.remove(membership);
     }
 }
diff --git a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPAJSONConf.java
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPAJSONConf.java
index ea97ed5..e29c210 100644
--- a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPAJSONConf.java
+++ b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPAJSONConf.java
@@ -75,7 +75,7 @@ public class JPAJSONConf extends JPAConf implements JSONAny<Conf>,
Conf {
 
     @Override
     public boolean remove(final CPlainAttr attr) {
-        return plainAttrList.removeIf(pgattr -> pgattr.getSchemaKey().equals(attr.getSchema().getKey()));
+        return plainAttrList.removeIf(jsonAttr -> jsonAttr.getSchemaKey().equals(attr.getSchema().getKey()));
     }
 
     @Override
diff --git a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/group/JPAJSONGroup.java
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/group/JPAJSONGroup.java
index b84169a..3fca4af 100644
--- a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/group/JPAJSONGroup.java
+++ b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/group/JPAJSONGroup.java
@@ -75,7 +75,7 @@ public class JPAJSONGroup extends JPAGroup implements JSONAny<Group>,
Group {
 
     @Override
     public boolean remove(final GPlainAttr attr) {
-        return plainAttrList.removeIf(pgattr -> pgattr.getSchemaKey().equals(attr.getSchema().getKey()));
+        return plainAttrList.removeIf(jsonAttr -> jsonAttr.getSchemaKey().equals(attr.getSchema().getKey()));
     }
 
     @Override
diff --git a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/user/JPAJSONUser.java
b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/user/JPAJSONUser.java
index 1591b9c..dc18c17 100644
--- a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/user/JPAJSONUser.java
+++ b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/entity/user/JPAJSONUser.java
@@ -80,9 +80,8 @@ public class JPAJSONUser extends JPAUser implements JSONAny<User>,
User {
 
     @Override
     public boolean remove(final UPlainAttr attr) {
-        return plainAttrList.removeIf(pgattr
-                -> pgattr.getSchemaKey().equals(attr.getSchema().getKey())
-                && Objects.equals(pgattr.getMembershipKey(), ((JPAJSONUPlainAttr)
attr).getMembershipKey()));
+        return plainAttrList.removeIf(jsonAttr -> jsonAttr.getSchemaKey().equals(attr.getSchema().getKey())
+                && Objects.equals(jsonAttr.getMembershipKey(), ((JPAJSONUPlainAttr)
attr).getMembershipKey()));
     }
 
     @Override
@@ -93,30 +92,30 @@ public class JPAJSONUser extends JPAUser implements JSONAny<User>,
User {
     @Override
     public List<? extends UPlainAttr> getPlainAttrs() {
         return plainAttrList.stream().
-                filter(pgattr -> pgattr.getMembershipKey() == null).
+                filter(attr -> attr.getMembershipKey() == null).
                 collect(Collectors.toList());
     }
 
     @Override
     public Optional<? extends UPlainAttr> getPlainAttr(final String plainSchema) {
         return plainAttrList.stream().
-                filter(pgattr -> pgattr.getSchemaKey() != null && pgattr.getSchemaKey().equals(plainSchema)
-                && pgattr.getMembershipKey() == null).
+                filter(attr -> attr.getSchemaKey() != null && attr.getSchemaKey().equals(plainSchema)
+                && attr.getMembershipKey() == null).
                 findFirst();
     }
 
     @Override
     public Optional<? extends UPlainAttr> getPlainAttr(final String plainSchema, final
Membership<?> membership) {
         return plainAttrList.stream().
-                filter(pgattr -> pgattr.getSchemaKey() != null && pgattr.getSchemaKey().equals(plainSchema)
-                && pgattr.getMembershipKey() != null && pgattr.getMembershipKey().equals(membership.getKey())).
+                filter(attr -> attr.getSchemaKey() != null && attr.getSchemaKey().equals(plainSchema)
+                && attr.getMembershipKey() != null && attr.getMembershipKey().equals(membership.getKey())).
                 findFirst();
     }
 
     @Override
     public boolean remove(final UMembership membership) {
-        plainAttrList.removeIf(pgattr
-                -> pgattr.getMembershipKey() != null && pgattr.getMembershipKey().equals(membership.getKey()));
+        plainAttrList.removeIf(attr -> attr.getMembershipKey() != null
+                && attr.getMembershipKey().equals(membership.getKey()));
         return super.remove(membership);
     }
 }
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
index 8035812..18eab7a 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java
@@ -63,10 +63,10 @@ import org.springframework.transaction.annotation.Transactional;
 public class JPAAnyObjectDAO extends AbstractAnyDAO<AnyObject> implements AnyObjectDAO
{
 
     @Autowired
-    private UserDAO userDAO;
+    protected UserDAO userDAO;
 
     @Autowired
-    private GroupDAO groupDAO;
+    protected GroupDAO groupDAO;
 
     @Override
     protected AnyUtils init() {
@@ -195,7 +195,7 @@ public class JPAAnyObjectDAO extends AbstractAnyDAO<AnyObject> implements
AnyObj
         return query.getResultList();
     }
 
-    private Pair<AnyObject, Pair<Set<String>, Set<String>>> doSave(final
AnyObject anyObject) {
+    protected Pair<AnyObject, Pair<Set<String>, Set<String>>> doSave(final
AnyObject anyObject) {
         AnyObject merged = super.save(anyObject);
         publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, merged, AuthContextUtils.getDomain()));
 
@@ -215,7 +215,7 @@ public class JPAAnyObjectDAO extends AbstractAnyDAO<AnyObject> implements
AnyObj
         return doSave(anyObject).getRight();
     }
 
-    private List<ARelationship> findARelationships(final AnyObject anyObject) {
+    protected List<ARelationship> findARelationships(final AnyObject anyObject) {
         TypedQuery<ARelationship> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAARelationship.class.getSimpleName()
                 + " e WHERE e.rightEnd=:anyObject", ARelationship.class);
@@ -224,7 +224,7 @@ public class JPAAnyObjectDAO extends AbstractAnyDAO<AnyObject> implements
AnyObj
         return query.getResultList();
     }
 
-    private List<URelationship> findURelationships(final AnyObject anyObject) {
+    protected List<URelationship> findURelationships(final AnyObject anyObject) {
         TypedQuery<URelationship> query = entityManager().createQuery(
                 "SELECT e FROM " + JPAURelationship.class.getSimpleName()
                 + " e WHERE e.rightEnd=:anyObject", URelationship.class);
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
index 45d4a76..0e8d474 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
@@ -76,28 +76,28 @@ import org.springframework.transaction.annotation.Transactional;
 
 public class JPAUserDAO extends AbstractAnyDAO<User> implements UserDAO {
 
-    private static final Pattern USERNAME_PATTERN =
+    protected static final Pattern USERNAME_PATTERN =
             Pattern.compile("^" + SyncopeConstants.NAME_PATTERN, Pattern.CASE_INSENSITIVE
| Pattern.UNICODE_CASE);
 
-    private static final Encryptor ENCRYPTOR = Encryptor.getInstance();
+    protected static final Encryptor ENCRYPTOR = Encryptor.getInstance();
 
     @Autowired
-    private RoleDAO roleDAO;
+    protected RoleDAO roleDAO;
 
     @Autowired
-    private AccessTokenDAO accessTokenDAO;
+    protected AccessTokenDAO accessTokenDAO;
 
     @Autowired
-    private RealmDAO realmDAO;
+    protected RealmDAO realmDAO;
 
     @Autowired
-    private GroupDAO groupDAO;
+    protected GroupDAO groupDAO;
 
     @Resource(name = "adminUser")
-    private String adminUser;
+    protected String adminUser;
 
     @Resource(name = "anonymousUser")
-    private String anonymousUser;
+    protected String anonymousUser;
 
     @Override
     protected AnyUtils init() {
@@ -221,7 +221,7 @@ public class JPAUserDAO extends AbstractAnyDAO<User> implements
UserDAO {
         return entityManager().find(JPAUMembership.class, key);
     }
 
-    private List<PasswordPolicy> getPasswordPolicies(final User user) {
+    protected List<PasswordPolicy> getPasswordPolicies(final User user) {
         List<PasswordPolicy> policies = new ArrayList<>();
 
         PasswordPolicy policy;
@@ -255,7 +255,7 @@ public class JPAUserDAO extends AbstractAnyDAO<User> implements
UserDAO {
         return query.getResultList();
     }
 
-    private List<AccountPolicy> getAccountPolicies(final User user) {
+    protected List<AccountPolicy> getAccountPolicies(final User user) {
         List<AccountPolicy> policies = new ArrayList<>();
 
         // add resource policies
@@ -374,7 +374,7 @@ public class JPAUserDAO extends AbstractAnyDAO<User> implements
UserDAO {
         return ImmutablePair.of(suspend, propagateSuspension);
     }
 
-    private Pair<User, Pair<Set<String>, Set<String>>> doSave(final
User user) {
+    protected Pair<User, Pair<Set<String>, Set<String>>> doSave(final
User user) {
         // 1. save clear password value before save
         String clearPwd = user.getClearPassword();
 


Mime
View raw message