Search in sources :

Example 96 with User

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;
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) UserTO(org.apache.syncope.common.lib.to.UserTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 97 with User

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;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SecurityQuestionDAO(org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO) Date(java.util.Date) Realm(org.apache.syncope.core.persistence.api.entity.Realm) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Entity(org.apache.syncope.core.persistence.api.entity.Entity) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) UserDataBinder(org.apache.syncope.core.provisioning.api.data.UserDataBinder) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Role(org.apache.syncope.core.persistence.api.entity.Role) Collection(java.util.Collection) Resource(javax.annotation.Resource) Set(java.util.Set) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Group(org.apache.syncope.core.persistence.api.entity.group.Group) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Optional(java.util.Optional) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AccessToken(org.apache.syncope.core.persistence.api.entity.AccessToken) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) BeanUtils(org.apache.syncope.core.spring.BeanUtils) URelationship(org.apache.syncope.core.persistence.api.entity.user.URelationship) HashSet(java.util.HashSet) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) CipherAlgorithm(org.apache.syncope.common.lib.types.CipherAlgorithm) Encryptor(org.apache.syncope.core.spring.security.Encryptor) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) User(org.apache.syncope.core.persistence.api.entity.user.User) AccessTokenDAO(org.apache.syncope.core.persistence.api.dao.AccessTokenDAO) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Component(org.springframework.stereotype.Component) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) RelationshipType(org.apache.syncope.core.persistence.api.entity.RelationshipType) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) SecurityQuestion(org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion) Transactional(org.springframework.transaction.annotation.Transactional) Entity(org.apache.syncope.core.persistence.api.entity.Entity) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) UserTO(org.apache.syncope.common.lib.to.UserTO) List(java.util.List) Transactional(org.springframework.transaction.annotation.Transactional)

Example 98 with User

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);
}
Also used : Task(org.flowable.task.api.Task) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) User(org.apache.syncope.core.persistence.api.entity.user.User) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) TaskFormData(org.flowable.engine.form.TaskFormData) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) FlowableException(org.flowable.engine.common.api.FlowableException)

Example 99 with User

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);
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) User(org.apache.syncope.core.persistence.api.entity.user.User) HashMap(java.util.HashMap) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource)

Example 100 with User

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;
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) ArrayList(java.util.ArrayList) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (org.apache.syncope.core.persistence.api.entity.user.User)135 Test (org.junit.jupiter.api.Test)58 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)56 Transactional (org.springframework.transaction.annotation.Transactional)39 Group (org.apache.syncope.core.persistence.api.entity.group.Group)24 ArrayList (java.util.ArrayList)20 UserTO (org.apache.syncope.common.lib.to.UserTO)20 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)20 HashSet (java.util.HashSet)18 AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)17 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)17 List (java.util.List)16 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)16 UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 Set (java.util.Set)14 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)14 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)14 Collections (java.util.Collections)11 Collectors (java.util.stream.Collectors)11