WorkflowManagerBean implements IWorkflowManagerLocal { @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override public WorkflowModel updateACLForWorkflow(String pWorkspaceId, String workflowModelId, Map<String, String> userEntries, Map<String, String> groupEntries) throws UserNotFoundException, UserNotActiveException, WorkspaceNotFoundException, WorkflowModelNotFoundException, AccessRightException, WorkspaceNotEnabledException { User user = userManager.checkWorkspaceReadAccess(pWorkspaceId); WorkflowModelKey workflowModelKey = new WorkflowModelKey(pWorkspaceId, workflowModelId); WorkflowModel workflowModel = workflowModelDAO.loadWorkflowModel(workflowModelKey); checkWorkflowWriteAccess(workflowModel, user); if (workflowModel.getAcl() == null) { ACL acl = aclFactory.createACL(pWorkspaceId, userEntries, groupEntries); workflowModel.setAcl(acl); } else { ACL acl = aclFactory.updateACL(pWorkspaceId, workflowModel.getAcl(), userEntries, groupEntries); workflowModel.setAcl(acl); } return workflowModel; }  @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void deleteWorkflowModel(WorkflowModelKey pKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override WorkflowModel createWorkflowModel(String pWorkspaceId, String pId, String pFinalLifeCycleState, ActivityModel[] pActivityModels); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override WorkflowModel updateWorkflowModel(WorkflowModelKey workflowModelKey, String pFinalLifeCycleState, ActivityModel[] pActivityModels); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override WorkflowModel[] getWorkflowModels(String pWorkspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override WorkflowModel getWorkflowModel(WorkflowModelKey pKey); @Override @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) Role[] getRoles(String pWorkspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override Role[] getRolesInUse(String pWorkspaceId); @Override @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) Role createRole(String roleName, String workspaceId, List<String> userLogins, List<String> userGroupIds); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override Role updateRole(RoleKey roleKey, List<String> userLogins, List<String> userGroupIds); @Override @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) void deleteRole(RoleKey roleKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void removeUserFromAllRoleMappings(User pUser); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void removeUserGroupFromAllRoleMappings(UserGroup pUserGroup); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void removeACLFromWorkflow(String pWorkspaceId, String workflowModelId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override WorkflowModel updateACLForWorkflow(String pWorkspaceId, String workflowModelId, Map<String, String> userEntries, Map<String, String> groupEntries); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override WorkspaceWorkflow instantiateWorkflow(String workspaceId, String id, String workflowModelId, Map<String, Collection<String>> userRoleMapping, Map<String, Collection<String>> groupRoleMapping); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override Workflow getWorkflow(String workspaceId, int workflowId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override WorkspaceWorkflow getWorkspaceWorkflow(String workspaceId, String workspaceWorkflowId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override Workflow[] getWorkflowAbortedWorkflowList(String workspaceId, int workflowId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void approveTaskOnWorkspaceWorkflow(String workspaceId, TaskKey taskKey, String comment, String signature); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void rejectTaskOnWorkspaceWorkflow(String workspaceId, TaskKey taskKey, String comment, String signature); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override WorkspaceWorkflow[] getWorkspaceWorkflowList(String workspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void deleteWorkspaceWorkflow(String workspaceId, String workspaceWorkflowId);  }
@Test public void testUpdateACLForWorkflowWithNoACL() throws Exception { WorkflowModel workflowModel = new WorkflowModel(workspace, WorkflowUtil.WORKSPACE_ID, user, ""); Map<String, String> userEntries = new HashMap<>(); User user2 = new User(workspace,new Account(WorkflowUtil.USER2_LOGIN , WorkflowUtil.USER2_NAME,WorkflowUtil.USER2_MAIL, "en", new Date(), null)); User user3 = new User(workspace,new Account(WorkflowUtil.USER3_LOGIN , WorkflowUtil.USER3_NAME,WorkflowUtil.USER3_MAIL, "en", new Date(), null)); userEntries.put(user.getLogin(), ACLPermission.FORBIDDEN.name()); userEntries.put(user2.getLogin(), ACLPermission.READ_ONLY.name()); userEntries.put(user3.getLogin(), ACLPermission.FULL_ACCESS.name()); ACL acl = new ACL(); acl.addEntry(user, ACLPermission.FORBIDDEN); acl.addEntry(user2, ACLPermission.READ_ONLY); acl.addEntry(user3, ACLPermission.FULL_ACCESS); Mockito.when(userManager.checkWorkspaceReadAccess(WorkflowUtil.WORKSPACE_ID)).thenReturn(user); Mockito.when(workflowModelDAO.loadWorkflowModel(workflowModelKey)).thenReturn(workflowModel); Mockito.when(aclFactory.createACL(workspace.getId(), userEntries, null)).thenReturn(acl); WorkflowModel workflow= workflowManagerBean.updateACLForWorkflow(WorkflowUtil.WORKSPACE_ID, WorkflowUtil.WORKFLOW_MODEL_ID, userEntries, null); Assert.assertEquals(0, workflow.getAcl().getGroupEntries().size()); Assert.assertEquals(3, workflow.getAcl().getUserEntries().size()); Assert.assertEquals(ACLPermission.FORBIDDEN, workflow.getAcl().getUserEntries().get(user).getPermission()); Assert.assertEquals(ACLPermission.READ_ONLY, workflow.getAcl().getUserEntries().get(user2).getPermission()); Assert.assertEquals(ACLPermission.FULL_ACCESS, workflow.getAcl().getUserEntries().get(user3).getPermission()); }
@Test public void testUpdateACLForWorkflowWithAnExistingACL() throws Exception { Map<String, String> userEntries = new HashMap<>(); Map<String, String> grpEntries = new HashMap<>(); User user2 = new User(workspace,new Account(WorkflowUtil.USER2_LOGIN , WorkflowUtil.USER2_NAME,WorkflowUtil.USER2_MAIL, "en", new Date(), null)); User user3 = new User(workspace,new Account(WorkflowUtil.USER3_LOGIN , WorkflowUtil.USER3_NAME,WorkflowUtil.USER3_MAIL, "en", new Date(), null)); UserGroup group1 = new UserGroup(workspace,WorkflowUtil.GRP1_ID); WorkflowModel workflowModel = new WorkflowModel(workspace, WorkflowUtil.WORKSPACE_ID, user, ""); ACL acl = new ACL(); acl.addEntry(user2, ACLPermission.READ_ONLY); acl.addEntry(group1, ACLPermission.FULL_ACCESS); ACL expectedAcl = new ACL(); expectedAcl.addEntry(user, ACLPermission.FORBIDDEN); expectedAcl.addEntry(user2, ACLPermission.FORBIDDEN); expectedAcl.addEntry(user3, ACLPermission.FULL_ACCESS); expectedAcl.addEntry(group1, ACLPermission.FULL_ACCESS); workflowModel.setAcl(acl); userEntries.put(user.getLogin(), ACLPermission.FORBIDDEN.name()); userEntries.put(user2.getLogin(), ACLPermission.FORBIDDEN.name()); userEntries.put(user3.getLogin(), ACLPermission.FULL_ACCESS.name()); group1.addUser(user2); group1.addUser(user); grpEntries.put(group1.getId(),ACLPermission.FULL_ACCESS.name()); Mockito.when(userManager.checkWorkspaceReadAccess(workspace.getId())).thenReturn(user); Mockito.when(workflowModelDAO.loadWorkflowModel(workflowModelKey)).thenReturn(workflowModel); Mockito.when(aclTypedQuery.setParameter(Matchers.anyString(),Matchers.any())).thenReturn(aclTypedQuery); Mockito.when(aclFactory.updateACL(workspace.getId(), acl, userEntries, grpEntries)).thenReturn(expectedAcl); WorkflowModel workflow= workflowManagerBean.updateACLForWorkflow(WorkflowUtil.WORKSPACE_ID, WorkflowUtil.WORKFLOW_MODEL_ID, userEntries, grpEntries); Assert.assertEquals(1, workflow.getAcl().getGroupEntries().size()); Assert.assertEquals(3, workflow.getAcl().getUserEntries().size()); Assert.assertEquals(ACLPermission.FORBIDDEN, workflow.getAcl().getUserEntries().get(user).getPermission()); Assert.assertEquals(ACLPermission.FORBIDDEN, workflow.getAcl().getUserEntries().get(user2).getPermission()); Assert.assertEquals(ACLPermission.FULL_ACCESS, workflow.getAcl().getUserEntries().get(user3).getPermission()); }