@Test public void testBasicWrapping() { Map<String, Object> properties = new HashMap<String, Object>(){{ put("a", 1); put("b", 2); put(ResourceResolver.PROPERTY_RESOURCE_TYPE, "a/b/c"); }}; Resource wrappedResource = new ImageResourceWrapper(prepareResourceToBeWrapped(properties), "d/e/f"); ArrayList<Map.Entry> keyValuePairs = new ArrayList<>(); keyValuePairs.add(new DefaultMapEntry("a", 1)); keyValuePairs.add(new DefaultMapEntry("b", 2)); keyValuePairs.add(new DefaultMapEntry(ResourceResolver.PROPERTY_RESOURCE_TYPE, "d/e/f")); testValueMap(keyValuePairs, wrappedResource.adaptTo(ValueMap.class)); testValueMap(keyValuePairs, wrappedResource.getValueMap()); assertEquals("d/e/f", wrappedResource.getResourceType()); }
@Test public void testWrappingWithHiddenProperties() { Map<String, Object> properties = new HashMap<String, Object>(){{ put("a", 1); put("b", 2); put(ResourceResolver.PROPERTY_RESOURCE_TYPE, "a/b/c"); }}; Resource wrappedResource = new ImageResourceWrapper(prepareResourceToBeWrapped(properties), "d/e/f", new ArrayList<String>() {{ add("b"); }}); ArrayList<Map.Entry> keyValuePairs = new ArrayList<>(); keyValuePairs.add(new DefaultMapEntry("a", 1)); keyValuePairs.add(new DefaultMapEntry(ResourceResolver.PROPERTY_RESOURCE_TYPE, "d/e/f")); testValueMap(keyValuePairs, wrappedResource.adaptTo(ValueMap.class)); testValueMap(keyValuePairs, wrappedResource.getValueMap()); assertFalse(wrappedResource.getValueMap().containsKey("b")); assertEquals("d/e/f", wrappedResource.getResourceType()); }
public Object[] toArray(Object[] arr) { // special implementation to handle disappearing entries ArrayList list = new ArrayList(); Iterator iterator = iterator(); while (iterator.hasNext()) { Entry e = (Entry) iterator.next(); list.add(new DefaultMapEntry(e.getKey(), e.getValue())); } return list.toArray(arr); }
@Override public WorkflowResult<Map.Entry<Long, Boolean>> create( final UserTO userTO, final boolean disablePwdPolicyCheck, final Boolean enabled) throws WorkflowException { SyncopeUser user = new SyncopeUser(); dataBinder.create(user, userTO); // this will make SyncopeUserValidator not to consider // password policies at all if (disablePwdPolicyCheck) { user.removeClearPassword(); } String status; boolean propagate_enable; if (enabled == null) { status = "created"; propagate_enable = true; } else { status = enabled ? "active" : "suspended"; propagate_enable = enabled; } user.setStatus(status); user = userDAO.save(user); final PropagationByResource propByRes = new PropagationByResource(); propByRes.set(PropagationOperation.CREATE, user.getResourceNames()); return new WorkflowResult<Map.Entry<Long, Boolean>>( new DefaultMapEntry(user.getId(), propagate_enable), propByRes, "create"); }
@Override public WorkflowResult<Map.Entry<Long, Boolean>> create( final UserTO userTO, final boolean disablePwdPolicyCheck, final Boolean enabled) throws WorkflowException { final Map<String, Object> variables = new HashMap<String, Object>(); variables.put(USER_TO, userTO); variables.put(ENABLED, enabled); final ProcessInstance processInstance; try { processInstance = runtimeService.startProcessInstanceByKey( "userWorkflow", variables); } catch (ActivitiException e) { throw new WorkflowException(e); } SyncopeUser user = (SyncopeUser) runtimeService.getVariable( processInstance.getProcessInstanceId(), SYNCOPE_USER); // this will make SyncopeUserValidator not to consider // password policies at all if (disablePwdPolicyCheck) { user.removeClearPassword(); } updateStatus(user); user = userDAO.save(user); Boolean propagate_enable = (Boolean) runtimeService.getVariable( processInstance.getProcessInstanceId(), PROPAGATE_ENABLE); if (propagate_enable == null) { propagate_enable = enabled; } // save resources to be propagated and password for later - // after form submission - propagation PropagationByResource propByRes = new PropagationByResource(); propByRes.set(PropagationOperation.CREATE, user.getResourceNames()); if (waitingForForm(user)) { runtimeService.setVariable(processInstance.getProcessInstanceId(), PROP_BY_RESOURCE, propByRes); propByRes = null; if (StringUtils.isNotBlank(userTO.getPassword())) { runtimeService.setVariable( processInstance.getProcessInstanceId(), ENCRYPTED_PWD, encrypt(userTO.getPassword())); } } return new WorkflowResult<Map.Entry<Long, Boolean>>( new DefaultMapEntry(user.getId(), propagate_enable), propByRes, getPerformedTasks(user)); }
@Override public WorkflowResult<Map.Entry<Long, String>> submitForm( final WorkflowFormTO form, final String username) throws NotFoundException, WorkflowException { Map.Entry<Task, TaskFormData> checked = checkTask(form.getTaskId(), username); if (!checked.getKey().getOwner().equals(username)) { throw new WorkflowException(new RuntimeException( "Task " + form.getTaskId() + " assigned to " + checked.getKey().getOwner() + " but submited by " + username)); } SyncopeUser user = userDAO.findByWorkflowId( checked.getKey().getProcessInstanceId()); if (user == null) { throw new NotFoundException("User with workflow id " + checked.getKey().getProcessInstanceId()); } Set<String> preTasks = getPerformedTasks(user); try { formService.submitTaskFormData(form.getTaskId(), form.getPropertiesForSubmit()); } catch (ActivitiException e) { throw new WorkflowException(e); } Set<String> postTasks = getPerformedTasks(user); postTasks.removeAll(preTasks); postTasks.add(form.getTaskId()); updateStatus(user); SyncopeUser updated = userDAO.save(user); // see if there is any propagation to be done PropagationByResource propByRes = (PropagationByResource) runtimeService.getVariable( user.getWorkflowId(), PROP_BY_RESOURCE); // fetch - if available - the encrpted password String clearPassword = null; String encryptedPwd = (String) runtimeService.getVariable( user.getWorkflowId(), ENCRYPTED_PWD); if (StringUtils.isNotBlank(encryptedPwd)) { clearPassword = decrypt(encryptedPwd); } return new WorkflowResult<Map.Entry<Long, String>>( new DefaultMapEntry(updated.getId(), clearPassword), propByRes, postTasks); }