use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.
the class UserDataBinderImpl method getAuthenticatedUserTO.
@Transactional(readOnly = true)
@Override
public UserTO getAuthenticatedUserTO() {
final UserTO authUserTO;
String authUsername = AuthContextUtils.getUsername();
if (anonymousUser.equals(authUsername)) {
authUserTO = new UserTO();
authUserTO.setKey(null);
authUserTO.setUsername(anonymousUser);
} else if (adminUser.equals(authUsername)) {
authUserTO = new UserTO();
authUserTO.setKey(null);
authUserTO.setUsername(adminUser);
} else {
User authUser = userDAO.findByUsername(authUsername);
authUserTO = getUserTO(authUser, true);
}
return authUserTO;
}
use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.
the class UserDataBinderImpl method getUserTO.
@Transactional(readOnly = true)
@Override
public UserTO getUserTO(final User user, final boolean details) {
UserTO userTO = new UserTO();
BeanUtils.copyProperties(user, userTO, IGNORE_PROPERTIES);
userTO.setSuspended(BooleanUtils.isTrue(user.isSuspended()));
if (user.getSecurityQuestion() != null) {
userTO.setSecurityQuestion(user.getSecurityQuestion().getKey());
}
Map<VirSchema, List<String>> virAttrValues = details ? virAttrHandler.getValues(user) : Collections.<VirSchema, List<String>>emptyMap();
fillTO(userTO, user.getRealm().getFullPath(), user.getAuxClasses(), user.getPlainAttrs(), derAttrHandler.getValues(user), virAttrValues, userDAO.findAllResources(user), details);
if (details) {
// dynamic realms
userTO.getDynRealms().addAll(userDAO.findDynRealms(user.getKey()));
// roles
userTO.getRoles().addAll(user.getRoles().stream().map(Entity::getKey).collect(Collectors.toList()));
// dynamic roles
userTO.getDynRoles().addAll(userDAO.findDynRoles(user.getKey()).stream().map(Entity::getKey).collect(Collectors.toList()));
// privileges
userTO.getPrivileges().addAll(userDAO.findAllRoles(user).stream().flatMap(role -> role.getPrivileges().stream()).map(Entity::getKey).collect(Collectors.toSet()));
// relationships
userTO.getRelationships().addAll(user.getRelationships().stream().map(relationship -> getRelationshipTO(relationship.getType().getKey(), relationship.getRightEnd())).collect(Collectors.toList()));
// memberships
userTO.getMemberships().addAll(user.getMemberships().stream().map(membership -> {
return getMembershipTO(user.getPlainAttrs(membership), derAttrHandler.getValues(user, membership), virAttrHandler.getValues(user, membership), membership);
}).collect(Collectors.toList()));
// dynamic memberships
userTO.getDynMemberships().addAll(userDAO.findDynGroups(user.getKey()).stream().map(group -> {
return new MembershipTO.Builder().group(group.getKey(), group.getName()).build();
}).collect(Collectors.toList()));
}
return userTO;
}
use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.
the class FlowableUserWorkflowAdapter method submitForm.
@Override
public WorkflowResult<UserPatch> submitForm(final WorkflowFormTO form) {
String authUser = AuthContextUtils.getUsername();
Pair<Task, TaskFormData> checked = checkTask(form.getTaskId(), authUser);
if (!checked.getKey().getOwner().equals(authUser)) {
throw new WorkflowException(new IllegalArgumentException("Task " + form.getTaskId() + " assigned to " + checked.getKey().getOwner() + " but submitted by " + authUser));
}
User 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 {
engine.getFormService().submitTaskFormData(form.getTaskId(), getPropertiesForSubmit(form));
engine.getRuntimeService().setVariable(user.getWorkflowId(), FORM_SUBMITTER, authUser);
} catch (FlowableException e) {
throwException(e, "While submitting form for task " + form.getTaskId());
}
Set<String> postTasks = getPerformedTasks(user);
postTasks.removeAll(preTasks);
postTasks.add(form.getTaskId());
updateStatus(user);
User updated = userDAO.save(user);
// see if there is any propagation to be done
PropagationByResource propByRes = engine.getRuntimeService().getVariable(user.getWorkflowId(), PROP_BY_RESOURCE, PropagationByResource.class);
// fetch - if available - the encrypted password
String clearPassword = null;
String encryptedPwd = engine.getRuntimeService().getVariable(user.getWorkflowId(), ENCRYPTED_PWD, String.class);
if (StringUtils.isNotBlank(encryptedPwd)) {
clearPassword = decrypt(encryptedPwd);
}
// supports approval chains
saveForFormSubmit(user, clearPassword, propByRes);
UserPatch userPatch = engine.getRuntimeService().getVariable(user.getWorkflowId(), USER_PATCH, UserPatch.class);
if (userPatch == null) {
userPatch = new UserPatch();
userPatch.setKey(updated.getKey());
userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).value(clearPassword).build());
if (propByRes != null) {
userPatch.getPassword().getResources().addAll(propByRes.get(ResourceOperation.CREATE));
}
}
return new WorkflowResult<>(userPatch, propByRes, postTasks);
}
use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.
the class FlowableUserWorkflowAdapter method execute.
@Override
public WorkflowResult<String> execute(final UserTO userTO, final String taskId) {
User user = userDAO.authFind(userTO.getKey());
Map<String, Object> variables = new HashMap<>();
variables.put(USER_TO, userTO);
Set<String> performedTasks = doExecuteTask(user, taskId, variables);
updateStatus(user);
User updated = userDAO.save(user);
PropagationByResource propByRes = engine.getRuntimeService().getVariable(user.getWorkflowId(), PROP_BY_RESOURCE, PropagationByResource.class);
saveForFormSubmit(updated, userTO.getPassword(), propByRes);
return new WorkflowResult<>(updated.getKey(), null, performedTasks);
}
use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.
the class FlowableUserWorkflowAdapter method getForms.
@Transactional(readOnly = true)
@Override
public List<WorkflowFormTO> getForms() {
List<WorkflowFormTO> forms = new ArrayList<>();
String authUser = AuthContextUtils.getUsername();
if (adminUser.equals(authUser)) {
forms.addAll(getForms(engine.getTaskService().createTaskQuery().taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE)));
} else {
User user = userDAO.findByUsername(authUser);
if (user == null) {
throw new NotFoundException("Syncope User " + authUser);
}
forms.addAll(getForms(engine.getTaskService().createTaskQuery().taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE).taskCandidateOrAssigned(user.getKey())));
List<String> candidateGroups = new ArrayList<>();
userDAO.findAllGroupNames(user).forEach(group -> {
candidateGroups.add(group);
});
if (!candidateGroups.isEmpty()) {
forms.addAll(getForms(engine.getTaskService().createTaskQuery().taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE).taskCandidateGroupIn(candidateGroups)));
}
}
return forms;
}
Aggregations