syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [14/20] syncope git commit: [SYNCOPE-870] Using username and group's name everywhere instead of keys
Date Wed, 08 Jun 2016 15:58:50 GMT
[SYNCOPE-870] Using username and group's name everywhere instead of keys


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

Branch: refs/heads/SYNCOPE-862
Commit: d067c2c31fb9e5a577c7d4d01fa75de51e0a5b3d
Parents: e53e6d9
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Tue Jun 7 17:12:44 2016 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Tue Jun 7 17:12:44 2016 +0200

----------------------------------------------------------------------
 .../syncope/core/persistence/api/dao/UserDAO.java     |  2 ++
 .../syncope/core/persistence/jpa/dao/JPAUserDAO.java  | 12 ++++++++++++
 .../activiti/ActivitiUserWorkflowAdapter.java         |  4 ++--
 .../syncope/core/workflow/activiti/ActivitiUtils.java |  4 ++--
 .../core/workflow/activiti/SyncopeGroupManager.java   |  4 ++--
 .../core/workflow/activiti/SyncopeUserManager.java    | 14 +++++++-------
 .../core/workflow/activiti/SyncopeUserQueryImpl.java  |  2 +-
 .../src/main/resources/userWorkflow.bpmn20.xml        |  8 ++++----
 .../apache/syncope/fit/core/AuthenticationITCase.java |  3 ++-
 9 files changed, 34 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/d067c2c3/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/UserDAO.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/UserDAO.java
b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/UserDAO.java
index dce9a1e..00921ee 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/UserDAO.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/UserDAO.java
@@ -54,6 +54,8 @@ public interface UserDAO extends AnyDAO<User> {
 
     Collection<String> findAllGroupKeys(User user);
 
+    Collection<String> findAllGroupNames(User user);
+
     Collection<ExternalResource> findAllResources(User user);
 
     Collection<String> findAllResourceNames(User user);

http://git-wip-us.apache.org/repos/asf/syncope/blob/d067c2c3/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
----------------------------------------------------------------------
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 5c3b241..0624190 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
@@ -465,6 +465,18 @@ public class JPAUserDAO extends AbstractAnyDAO<User> implements
UserDAO {
 
     @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
     @Override
+    public Collection<String> findAllGroupNames(final User user) {
+        return CollectionUtils.collect(findAllGroups(user), new Transformer<Group, String>()
{
+
+            @Override
+            public String transform(final Group input) {
+                return input.getName();
+            }
+        });
+    }
+
+    @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
+    @Override
     public Collection<ExternalResource> findAllResources(final User user) {
         Set<ExternalResource> result = new HashSet<>();
         result.addAll(user.getResources());

http://git-wip-us.apache.org/repos/asf/syncope/blob/d067c2c3/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUserWorkflowAdapter.java
----------------------------------------------------------------------
diff --git a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUserWorkflowAdapter.java
b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUserWorkflowAdapter.java
index bbfa9ad..1c1e75c 100644
--- a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUserWorkflowAdapter.java
+++ b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUserWorkflowAdapter.java
@@ -688,8 +688,8 @@ public class ActivitiUserWorkflowAdapter extends AbstractUserWorkflowAdapter
{
                     taskCandidateOrAssigned(user.getKey())));
 
             List<String> candidateGroups = new ArrayList<>();
-            for (String groupKey : userDAO.findAllGroupKeys(user)) {
-                candidateGroups.add(groupKey);
+            for (String groupName : userDAO.findAllGroupNames(user)) {
+                candidateGroups.add(groupName);
             }
             if (!candidateGroups.isEmpty()) {
                 forms.addAll(getForms(engine.getTaskService().createTaskQuery().

http://git-wip-us.apache.org/repos/asf/syncope/blob/d067c2c3/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUtils.java
----------------------------------------------------------------------
diff --git a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUtils.java
b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUtils.java
index 963a7d1..a259bc8 100644
--- a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUtils.java
+++ b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/ActivitiUtils.java
@@ -27,12 +27,12 @@ import org.springframework.transaction.annotation.Transactional;
 public class ActivitiUtils {
 
     @Transactional(readOnly = true)
-    public boolean isUserIngroup(final User user, final String groupKey) {
+    public boolean isUserIngroup(final User user, final String groupName) {
         return IterableUtils.matchesAny(user.getMemberships(), new Predicate<UMembership>()
{
 
             @Override
             public boolean evaluate(final UMembership membership) {
-                return groupKey != null && groupKey.equals(membership.getRightEnd().getKey());
+                return groupName != null && groupName.equals(membership.getRightEnd().getName());
             }
         });
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/d067c2c3/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeGroupManager.java
----------------------------------------------------------------------
diff --git a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeGroupManager.java
b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeGroupManager.java
index 9293dae..5725b6e 100644
--- a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeGroupManager.java
+++ b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeGroupManager.java
@@ -67,8 +67,8 @@ public class SyncopeGroupManager implements GroupIdentityManager, SyncopeSession
         User user = userDAO.findByUsername(userId);
         if (user != null) {
             result = new ArrayList<>();
-            for (String groupKey : userDAO.findAllGroupKeys(user)) {
-                result.add(new GroupEntity(groupKey));
+            for (String groupName : userDAO.findAllGroupNames(user)) {
+                result.add(new GroupEntity(groupName));
             }
         }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/d067c2c3/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeUserManager.java
----------------------------------------------------------------------
diff --git a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeUserManager.java
b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeUserManager.java
index 260639a..dbab82a 100644
--- a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeUserManager.java
+++ b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeUserManager.java
@@ -70,13 +70,13 @@ public class SyncopeUserManager implements UserIdentityManager, SyncopeSession
{
     }
 
     @Override
-    public List<Group> findGroupsByUser(final String userKey) {
+    public List<Group> findGroupsByUser(final String username) {
         List<Group> result = Collections.emptyList();
-        org.apache.syncope.core.persistence.api.entity.user.User user = userDAO.find(userKey);
+        org.apache.syncope.core.persistence.api.entity.user.User user = userDAO.findByUsername(username);
         if (user != null) {
             result = new ArrayList<>();
-            for (String groupKey : userDAO.findAllGroupKeys(user)) {
-                result.add(new GroupEntity(groupKey.toString()));
+            for (String groupName : userDAO.findAllGroupNames(user)) {
+                result.add(new GroupEntity(groupName));
             }
         }
 
@@ -84,11 +84,11 @@ public class SyncopeUserManager implements UserIdentityManager, SyncopeSession
{
     }
 
     @Override
-    public UserEntity findUserById(final String userKey) {
+    public UserEntity findUserById(final String username) {
         UserEntity result = null;
-        org.apache.syncope.core.persistence.api.entity.user.User user = userDAO.find(userKey);
+        org.apache.syncope.core.persistence.api.entity.user.User user = userDAO.findByUsername(username);
         if (user != null) {
-            result = new UserEntity(userKey);
+            result = new UserEntity(username);
         }
 
         return result;

http://git-wip-us.apache.org/repos/asf/syncope/blob/d067c2c3/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeUserQueryImpl.java
----------------------------------------------------------------------
diff --git a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeUserQueryImpl.java
b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeUserQueryImpl.java
index 2950b1f..dd10566 100644
--- a/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeUserQueryImpl.java
+++ b/core/workflow-activiti/src/main/java/org/apache/syncope/core/workflow/activiti/SyncopeUserQueryImpl.java
@@ -135,7 +135,7 @@ public class SyncopeUserQueryImpl implements UserQuery {
             org.apache.syncope.core.persistence.api.entity.user.User user = userDAO.findByUsername(username);
             if (user == null) {
                 result = Collections.<User>emptyList();
-            } else if (memberOf == null || userDAO.findAllGroupKeys(user).contains(memberOf))
{
+            } else if (memberOf == null || userDAO.findAllGroupNames(user).contains(memberOf))
{
                 result = Collections.singletonList(fromSyncopeUser(user));
             }
         }

http://git-wip-us.apache.org/repos/asf/syncope/blob/d067c2c3/fit/core-reference/src/main/resources/userWorkflow.bpmn20.xml
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/main/resources/userWorkflow.bpmn20.xml b/fit/core-reference/src/main/resources/userWorkflow.bpmn20.xml
index 1af0f14..398e4bc 100644
--- a/fit/core-reference/src/main/resources/userWorkflow.bpmn20.xml
+++ b/fit/core-reference/src/main/resources/userWorkflow.bpmn20.xml
@@ -35,16 +35,16 @@ under the License.
     <exclusiveGateway id="createGW"/>
     <sequenceFlow id="createAsAnonymous2Approval" sourceRef="createGW" targetRef="createApproval">
       <conditionExpression xsi:type="tFormalExpression">
-        <![CDATA[${wfExecutor == 'anonymous' || activitiUtils.isUserIngroup(user, '0cbcabd2-4410-4b6b-8f05-a052b451d18f')}]]>
+        <![CDATA[${wfExecutor == 'anonymous' || activitiUtils.isUserIngroup(user, 'groupForWorkflowApproval')}]]>
       </conditionExpression>
     </sequenceFlow>
     <sequenceFlow id="create2Activate" sourceRef="createGW" targetRef="enableGW">
       <conditionExpression xsi:type="tFormalExpression">
-        <![CDATA[${!activitiUtils.isUserIngroup(user, '0cbcabd2-4410-4b6b-8f05-a052b451d18f')}]]>
+        <![CDATA[${!activitiUtils.isUserIngroup(user, 'groupForWorkflowApproval')}]]>
       </conditionExpression>
     </sequenceFlow>
     <userTask id="createApproval" name="Create approval"
-              activiti:candidateGroups="bf825fe1-7320-4a54-bd64-143b5c18ab97" activiti:formKey="createApproval">
+              activiti:candidateGroups="managingDirector" activiti:formKey="createApproval">
       <extensionElements>
         <activiti:formProperty id="username" name="Username" type="string" expression="${user.username}"
writable="false"/>
         <activiti:formProperty id="approve" name="Approve?" type="boolean" variable="approve"
required="true"/>
@@ -62,7 +62,7 @@ under the License.
     <exclusiveGateway id="enableGW"/>
     <sequenceFlow id="createApprovalGW2OptIn" sourceRef="enableGW" targetRef="generateToken">
       <conditionExpression xsi:type="tFormalExpression">
-        <![CDATA[${activitiUtils.isUserIngroup(user, '268fed79-f440-4390-9435-b273768eb5d6')}]]>
+        <![CDATA[${activitiUtils.isUserIngroup(user, 'groupForWorkflowOptIn')}]]>
       </conditionExpression>
     </sequenceFlow>
     <sequenceFlow id="createApprovalGW2Activate" sourceRef="enableGW" targetRef="activate">

http://git-wip-us.apache.org/repos/asf/syncope/blob/d067c2c3/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
index 781f89b..79f3bd9 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
@@ -468,7 +468,8 @@ public class AuthenticationITCase extends AbstractITCase {
     public void issueSYNCOPE434() {
         Assume.assumeTrue(ActivitiDetector.isActivitiEnabledForUsers(syncopeService));
 
-        // 1. create user with group 9 (users with group 9 are defined in workflow as subject
to approval)
+        // 1. create user with group 'groupForWorkflowApproval' 
+        // (users with group groupForWorkflowApproval are defined in workflow as subject
to approval)
         UserTO userTO = UserITCase.getUniqueSampleTO("createWithReject@syncope.apache.org");
         userTO.getMemberships().add(
                 new MembershipTO.Builder().group("0cbcabd2-4410-4b6b-8f05-a052b451d18f").build());


Mime
View raw message