Search in sources :

Example 31 with ExternalResource

use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.

the class PolicyDataBinderImpl method getPolicyTO.

@SuppressWarnings("unchecked")
@Override
public <T extends PolicyTO> T getPolicyTO(final Policy policy) {
    T policyTO = null;
    if (policy instanceof PasswordPolicy) {
        PasswordPolicy passwordPolicy = PasswordPolicy.class.cast(policy);
        PasswordPolicyTO passwordPolicyTO = new PasswordPolicyTO();
        policyTO = (T) passwordPolicyTO;
        passwordPolicyTO.setAllowNullPassword(passwordPolicy.isAllowNullPassword());
        passwordPolicyTO.setHistoryLength(passwordPolicy.getHistoryLength());
        passwordPolicyTO.getRules().addAll(passwordPolicy.getRules().stream().map(Entity::getKey).collect(Collectors.toList()));
    } else if (policy instanceof AccountPolicy) {
        AccountPolicy accountPolicy = AccountPolicy.class.cast(policy);
        AccountPolicyTO accountPolicyTO = new AccountPolicyTO();
        policyTO = (T) accountPolicyTO;
        accountPolicyTO.setMaxAuthenticationAttempts(accountPolicy.getMaxAuthenticationAttempts());
        accountPolicyTO.setPropagateSuspension(accountPolicy.isPropagateSuspension());
        accountPolicyTO.getRules().addAll(accountPolicy.getRules().stream().map(Entity::getKey).collect(Collectors.toList()));
        accountPolicyTO.getPassthroughResources().addAll(accountPolicy.getResources().stream().map(Entity::getKey).collect(Collectors.toList()));
    } else if (policy instanceof PullPolicy) {
        PullPolicy pullPolicy = PullPolicy.class.cast(policy);
        PullPolicyTO pullPolicyTO = new PullPolicyTO();
        policyTO = (T) pullPolicyTO;
        pullPolicyTO.setConflictResolutionAction(((PullPolicy) policy).getConflictResolutionAction());
        pullPolicy.getCorrelationRules().forEach(rule -> {
            pullPolicyTO.getCorrelationRules().put(rule.getAnyType().getKey(), rule.getImplementation().getKey());
        });
    }
    if (policyTO != null) {
        policyTO.setKey(policy.getKey());
        policyTO.setDescription(policy.getDescription());
        for (ExternalResource resource : resourceDAO.findByPolicy(policy)) {
            policyTO.getUsedByResources().add(resource.getKey());
        }
        for (Realm realm : realmDAO.findByPolicy(policy)) {
            policyTO.getUsedByRealms().add(realm.getFullPath());
        }
    }
    return policyTO;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) AccountPolicyTO(org.apache.syncope.common.lib.policy.AccountPolicyTO) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PasswordPolicyTO(org.apache.syncope.common.lib.policy.PasswordPolicyTO)

Example 32 with ExternalResource

use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.

the class ConnInstanceTest method deleteCascade.

@Test
public void deleteCascade() {
    ConnInstance connInstance = connInstanceDAO.find("fcf9f2b0-f7d6-42c9-84a6-61b28255a42b");
    assertNotNull(connInstance);
    List<? extends ExternalResource> resources = connInstance.getResources();
    assertNotNull(resources);
    assertFalse(resources.isEmpty());
    connInstanceDAO.delete(connInstance.getKey());
    connInstanceDAO.flush();
    ConnInstance actual = connInstanceDAO.find("fcf9f2b0-f7d6-42c9-84a6-61b28255a42b");
    assertNull(actual);
    for (ExternalResource resource : resources) {
        assertNull(resourceDAO.find(resource.getKey()));
    }
}
Also used : 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 33 with ExternalResource

use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.

the class PlainSchemaTest method deleteSurname.

@Test
public void deleteSurname() {
    // search for user schema fullname
    PlainSchema schema = plainSchemaDAO.find("surname");
    assertNotNull(schema);
    // check for associated mappings
    Set<MappingItem> mappings = new HashSet<>();
    for (ExternalResource resource : resourceDAO.findAll()) {
        if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if (schema.getKey().equals(mapItem.getIntAttrName())) {
                    mappings.add(mapItem);
                }
            }
        }
    }
    assertFalse(mappings.isEmpty());
    // delete user schema fullname
    plainSchemaDAO.delete("surname");
    plainSchemaDAO.flush();
    // check for schema deletion
    schema = plainSchemaDAO.find("surname");
    assertNull(schema);
}
Also used : MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 34 with ExternalResource

use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.

the class PlainSchemaTest method deleteFullname.

@Test
public void deleteFullname() {
    // fullname is mapped as ConnObjectKey for ws-target-resource-2, need to swap it otherwise validation errors
    // will be raised
    resourceDAO.find("ws-target-resource-2").getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().forEach(item -> {
        if ("fullname".equals(item.getIntAttrName())) {
            item.setConnObjectKey(false);
        } else if ("surname".equals(item.getIntAttrName())) {
            item.setConnObjectKey(true);
        }
    });
    // search for user schema fullname
    PlainSchema schema = plainSchemaDAO.find("fullname");
    assertNotNull(schema);
    // check for associated mappings
    Set<MappingItem> mapItems = new HashSet<>();
    for (ExternalResource resource : resourceDAO.findAll()) {
        if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if (schema.getKey().equals(mapItem.getIntAttrName())) {
                    mapItems.add(mapItem);
                }
            }
        }
    }
    assertFalse(mapItems.isEmpty());
    // delete user schema fullname
    plainSchemaDAO.delete("fullname");
    plainSchemaDAO.flush();
    // check for schema deletion
    schema = plainSchemaDAO.find("fullname");
    assertNull(schema);
    plainSchemaDAO.clear();
    // check for mappings deletion
    mapItems = new HashSet<>();
    for (ExternalResource resource : resourceDAO.findAll()) {
        if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if ("fullname".equals(mapItem.getIntAttrName())) {
                    mapItems.add(mapItem);
                }
            }
        }
    }
    assertTrue(mapItems.isEmpty());
    assertNull(plainAttrDAO.find("01f22fbd-b672-40af-b528-686d9b27ebc4", UPlainAttr.class));
    assertNull(plainAttrDAO.find(UUID.randomUUID().toString(), UPlainAttr.class));
    assertFalse(userDAO.findByUsername("rossini").getPlainAttr("fullname").isPresent());
    assertFalse(userDAO.findByUsername("vivaldi").getPlainAttr("fullname").isPresent());
}
Also used : MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 35 with ExternalResource

use of org.apache.syncope.core.persistence.api.entity.resource.ExternalResource in project syncope by apache.

the class ResourceTest method emptyMapping.

@Test
public void emptyMapping() {
    ExternalResource ldap = resourceDAO.find("resource-ldap");
    assertNotNull(ldap);
    assertNotNull(ldap.getProvision(anyTypeDAO.findUser()).get().getMapping());
    assertNotNull(ldap.getProvision(anyTypeDAO.findGroup()).get().getMapping());
    // need to avoid any class not defined in this Maven module
    ldap.getPropagationActions().clear();
    List<? extends MappingItem> items = ldap.getProvision(anyTypeDAO.findGroup()).get().getMapping().getItems();
    assertNotNull(items);
    assertFalse(items.isEmpty());
    List<String> itemKeys = items.stream().map(Entity::getKey).collect(Collectors.toList());
    Provision groupProvision = ldap.getProvision(anyTypeDAO.findGroup()).get();
    virSchemaDAO.findByProvision(groupProvision).forEach(schema -> virSchemaDAO.delete(schema.getKey()));
    ldap.getProvisions().remove(groupProvision);
    resourceDAO.save(ldap);
    resourceDAO.flush();
    itemKeys.forEach(itemKey -> assertNull(entityManager().find(JPAMappingItem.class, itemKey)));
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)59 Test (org.junit.jupiter.api.Test)30 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)28 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)23 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)21 ConnInstance (org.apache.syncope.core.persistence.api.entity.ConnInstance)15 List (java.util.List)14 Collectors (java.util.stream.Collectors)14 HashSet (java.util.HashSet)13 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 Set (java.util.Set)12 Transactional (org.springframework.transaction.annotation.Transactional)12 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)10 ExternalResourceDAO (org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO)10 Collections (java.util.Collections)9 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)9 Realm (org.apache.syncope.core.persistence.api.entity.Realm)9 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)9 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)8