Search in sources :

Example 76 with User

use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.

the class DBPasswordPropagationActions method before.

@Transactional(readOnly = true)
@Override
public void before(final PropagationTask task, final ConnectorObject beforeObj) {
    if (AnyTypeKind.USER == task.getAnyTypeKind()) {
        User user = userDAO.find(task.getEntityKey());
        if (user != null && user.getPassword() != null) {
            Attribute missing = AttributeUtil.find(PropagationTaskExecutor.MANDATORY_MISSING_ATTR_NAME, task.getAttributes());
            ConnInstance connInstance = task.getResource().getConnector();
            if (missing != null && missing.getValue() != null && missing.getValue().size() == 1 && missing.getValue().get(0).equals(OperationalAttributes.PASSWORD_NAME) && cipherAlgorithmMatches(getCipherAlgorithm(connInstance), user.getCipherAlgorithm())) {
                Attribute passwordAttribute = AttributeBuilder.buildPassword(new GuardedString(user.getPassword().toCharArray()));
                Set<Attribute> attributes = new HashSet<>(task.getAttributes());
                attributes.add(passwordAttribute);
                attributes.remove(missing);
                Attribute hashedPasswordAttribute = AttributeBuilder.build(AttributeUtil.createSpecialName("HASHED_PASSWORD"), Boolean.TRUE);
                attributes.add(hashedPasswordAttribute);
                task.setAttributes(attributes);
            }
        }
    }
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) Attribute(org.identityconnectors.framework.common.objects.Attribute) GuardedString(org.identityconnectors.common.security.GuardedString) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 77 with User

use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.

the class LDAPMembershipPropagationActions method before.

@Transactional(readOnly = true)
@Override
public void before(final PropagationTask task, final ConnectorObject beforeObj) {
    Optional<? extends Provision> provision = task.getResource().getProvision(anyTypeDAO.findGroup());
    if (AnyTypeKind.USER == task.getAnyTypeKind() && provision.isPresent() && provision.get().getMapping() != null && StringUtils.isNotBlank(provision.get().getMapping().getConnObjectLink())) {
        User user = userDAO.find(task.getEntityKey());
        if (user != null) {
            List<String> groupConnObjectLinks = new ArrayList<>();
            userDAO.findAllGroupKeys(user).forEach(groupKey -> {
                Group group = groupDAO.find(groupKey);
                if (group != null && groupDAO.findAllResourceKeys(groupKey).contains(task.getResource().getKey())) {
                    LOG.debug("Evaluating connObjectLink for {}", group);
                    JexlContext jexlContext = new MapContext();
                    JexlUtils.addFieldsToContext(group, jexlContext);
                    JexlUtils.addPlainAttrsToContext(group.getPlainAttrs(), jexlContext);
                    JexlUtils.addDerAttrsToContext(group, jexlContext);
                    String groupConnObjectLinkLink = JexlUtils.evaluate(provision.get().getMapping().getConnObjectLink(), jexlContext);
                    LOG.debug("ConnObjectLink for {} is '{}'", group, groupConnObjectLinkLink);
                    if (StringUtils.isNotBlank(groupConnObjectLinkLink)) {
                        groupConnObjectLinks.add(groupConnObjectLinkLink);
                    }
                }
            });
            LOG.debug("Group connObjectLinks to propagate for membership: {}", groupConnObjectLinks);
            Set<Attribute> attributes = new HashSet<>(task.getAttributes());
            Set<String> groups = new HashSet<>(groupConnObjectLinks);
            Attribute ldapGroups = AttributeUtil.find(getGroupMembershipAttrName(), attributes);
            if (ldapGroups != null) {
                ldapGroups.getValue().forEach(obj -> {
                    groups.add(obj.toString());
                });
                attributes.remove(ldapGroups);
            }
            attributes.add(AttributeBuilder.build(getGroupMembershipAttrName(), groups));
            task.setAttributes(attributes);
        }
    } else {
        LOG.debug("Not about user, or group mapping missing for resource: not doing anything");
    }
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) User(org.apache.syncope.core.persistence.api.entity.user.User) Attribute(org.identityconnectors.framework.common.objects.Attribute) ArrayList(java.util.ArrayList) JexlContext(org.apache.commons.jexl3.JexlContext) MapContext(org.apache.commons.jexl3.MapContext) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 78 with User

use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.

the class GroupTest method saveWithTwoOwners.

@Test
public void saveWithTwoOwners() {
    assertThrows(InvalidEntityException.class, () -> {
        Group root = groupDAO.findByName("root");
        assertNotNull(root);
        User user = userDAO.findByUsername("rossini");
        assertNotNull(user);
        Group group = entityFactory.newEntity(Group.class);
        group.setRealm(realmDAO.getRoot());
        group.setName("error");
        group.setUserOwner(user);
        group.setGroupOwner(root);
        groupDAO.save(group);
    });
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) User(org.apache.syncope.core.persistence.api.entity.user.User) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 79 with User

use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.

the class ResourceTest method save.

@Test
public void save() {
    ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
    resource.setKey("ws-target-resource-save");
    // specify the connector
    ConnInstance connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
    assertNotNull(connector);
    resource.setConnector(connector);
    Provision provision = entityFactory.newEntity(Provision.class);
    provision.setAnyType(anyTypeDAO.findUser());
    provision.setObjectClass(ObjectClass.ACCOUNT);
    provision.setResource(resource);
    resource.add(provision);
    Mapping mapping = entityFactory.newEntity(Mapping.class);
    mapping.setProvision(provision);
    provision.setMapping(mapping);
    // specify mappings
    for (int i = 0; i < 3; i++) {
        MappingItem item = entityFactory.newEntity(MappingItem.class);
        item.setExtAttrName("test" + i);
        item.setIntAttrName("nonexistent" + i);
        item.setMandatoryCondition("false");
        item.setPurpose(MappingPurpose.PULL);
        mapping.add(item);
        item.setMapping(mapping);
    }
    MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
    connObjectKey.setExtAttrName("username");
    connObjectKey.setIntAttrName("username");
    connObjectKey.setPurpose(MappingPurpose.PROPAGATION);
    mapping.setConnObjectKeyItem(connObjectKey);
    connObjectKey.setMapping(mapping);
    // map a derived attribute
    MappingItem derived = entityFactory.newEntity(MappingItem.class);
    derived.setConnObjectKey(false);
    derived.setExtAttrName("fullname");
    derived.setIntAttrName("cn");
    derived.setPurpose(MappingPurpose.PROPAGATION);
    mapping.add(derived);
    derived.setMapping(mapping);
    // save the resource
    ExternalResource actual = resourceDAO.save(resource);
    assertNotNull(actual);
    assertNotNull(actual.getProvision(anyTypeDAO.findUser()).get().getMapping());
    resourceDAO.flush();
    resourceDAO.detach(actual);
    connInstanceDAO.detach(connector);
    // assign the new resource to an user
    User user = userDAO.findByUsername("rossini");
    assertNotNull(user);
    user.add(actual);
    resourceDAO.flush();
    // retrieve resource
    resource = resourceDAO.find(actual.getKey());
    assertNotNull(resource);
    resourceDAO.refresh(resource);
    // check connector
    connector = connInstanceDAO.find("88a7a819-dab5-46b4-9b90-0b9769eabdb8");
    assertNotNull(connector);
    assertNotNull(connector.getResources());
    assertNotNull(resource.getConnector());
    assertTrue(resource.getConnector().equals(connector));
    // check mappings
    List<? extends MappingItem> items = resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems();
    assertNotNull(items);
    assertEquals(5, items.size());
    // check user
    user = userDAO.findByUsername("rossini");
    assertNotNull(user);
    assertNotNull(user.getResources());
    assertTrue(user.getResources().contains(actual));
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) JPAMappingItem(org.apache.syncope.core.persistence.jpa.entity.resource.JPAMappingItem) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) User(org.apache.syncope.core.persistence.api.entity.user.User) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 80 with User

use of org.apache.syncope.core.persistence.api.entity.user.User in project syncope by apache.

the class ResourceTest method delete.

@Test
public void delete() {
    ExternalResource resource = resourceDAO.find("resource-testdb");
    assertNotNull(resource);
    // -------------------------------------
    // Get originally associated connector
    // -------------------------------------
    ConnInstance connector = resource.getConnector();
    assertNotNull(connector);
    // -------------------------------------
    // -------------------------------------
    // Get originally associated users
    // -------------------------------------
    List<User> users = userDAO.findByResource(resource);
    assertNotNull(users);
    Set<String> userKeys = users.stream().map(Entity::getKey).collect(Collectors.toSet());
    // -------------------------------------
    // Get tasks
    List<PropagationTask> propagationTasks = taskDAO.findAll(TaskType.PROPAGATION, resource, null, null, null, -1, -1, Collections.<OrderByClause>emptyList());
    assertFalse(propagationTasks.isEmpty());
    // delete resource
    resourceDAO.delete(resource.getKey());
    // close the transaction
    resourceDAO.flush();
    // resource must be removed
    ExternalResource actual = resourceDAO.find("resource-testdb");
    assertNull(actual);
    // resource must be not referenced any more from users
    userKeys.stream().map(key -> userDAO.find(key)).map(actualUser -> {
        assertNotNull(actualUser);
        return actualUser;
    }).forEachOrdered((actualUser) -> {
        userDAO.findAllResources(actualUser).forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
    });
    // resource must be not referenced any more from the connector
    ConnInstance actualConnector = connInstanceDAO.find(connector.getKey());
    assertNotNull(actualConnector);
    actualConnector.getResources().forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
    // there must be no tasks
    propagationTasks.forEach(task -> assertNull(taskDAO.find(task.getKey())));
}
Also used : JPAMappingItem(org.apache.syncope.core.persistence.jpa.entity.resource.JPAMappingItem) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) TaskDAO(org.apache.syncope.core.persistence.api.dao.TaskDAO) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) JPAOrgUnit(org.apache.syncope.core.persistence.jpa.entity.resource.JPAOrgUnit) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Set(java.util.Set) User(org.apache.syncope.core.persistence.api.entity.user.User) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Test(org.junit.jupiter.api.Test) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest) Collections(java.util.Collections) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) TaskType(org.apache.syncope.common.lib.types.TaskType) Transactional(org.springframework.transaction.annotation.Transactional) User(org.apache.syncope.core.persistence.api.entity.user.User) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

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