Search in sources :

Example 41 with ExternalResource

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

the class MappingTest method anyConnObjectLink.

@Test
public void anyConnObjectLink() {
    ExternalResource ldap = resourceDAO.find("resource-ldap");
    assertNotNull(ldap);
    Provision provision = ldap.getProvision(anyTypeDAO.findUser()).get();
    assertNotNull(provision);
    assertNotNull(provision.getMapping());
    assertNotNull(provision.getMapping().getConnObjectLink());
    User user = userDAO.findByUsername("rossini");
    assertNotNull(user);
    Name name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
    assertEquals("uid=rossini,ou=people,o=isp", name.getNameValue());
    provision.getMapping().setConnObjectLink("'uid=' + username + realm.replaceAll('/', ',o=') + ',ou=people,o=isp'");
    name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
    assertEquals("uid=rossini,o=even,ou=people,o=isp", name.getNameValue());
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) User(org.apache.syncope.core.persistence.api.entity.user.User) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Name(org.identityconnectors.framework.common.objects.Name) Test(org.junit.jupiter.api.Test)

Example 42 with ExternalResource

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

the class TaskDataBinderImpl method createSchedTask.

@Override
public SchedTask createSchedTask(final SchedTaskTO taskTO, final TaskUtils taskUtils) {
    Class<? extends TaskTO> taskTOClass = taskUtils.taskTOClass();
    if (taskTOClass == null || !taskTOClass.equals(taskTO.getClass())) {
        throw new IllegalArgumentException(String.format("Expected %s, found %s", taskTOClass, taskTO.getClass()));
    }
    SchedTask task = taskUtils.newTask();
    task.setStartAt(taskTO.getStartAt());
    task.setCronExpression(taskTO.getCronExpression());
    task.setName(taskTO.getName());
    task.setDescription(taskTO.getDescription());
    task.setActive(taskTO.isActive());
    if (taskUtils.getType() == TaskType.SCHEDULED) {
        Implementation implementation = implementationDAO.find(taskTO.getJobDelegate());
        if (implementation == null) {
            throw new NotFoundException("Implementation " + taskTO.getJobDelegate());
        }
        task.setJobDelegate(implementation);
    } else if (taskTO instanceof ProvisioningTaskTO) {
        ProvisioningTaskTO provisioningTaskTO = (ProvisioningTaskTO) taskTO;
        ExternalResource resource = resourceDAO.find(provisioningTaskTO.getResource());
        if (resource == null) {
            throw new NotFoundException("Resource " + provisioningTaskTO.getResource());
        }
        ((ProvisioningTask) task).setResource(resource);
        fill((ProvisioningTask) task, provisioningTaskTO);
    }
    return task;
}
Also used : SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) ProvisioningTaskTO(org.apache.syncope.common.lib.to.ProvisioningTaskTO) ProvisioningTask(org.apache.syncope.core.persistence.api.entity.task.ProvisioningTask) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Example 43 with ExternalResource

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

the class AuthDataAccessor method authenticate.

protected boolean authenticate(final User user, final String password) {
    boolean authenticated = ENCRYPTOR.verify(password, user.getCipherAlgorithm(), user.getPassword());
    LOG.debug("{} authenticated on internal storage: {}", user.getUsername(), authenticated);
    for (Iterator<? extends ExternalResource> itor = getPassthroughResources(user).iterator(); itor.hasNext() && !authenticated; ) {
        ExternalResource resource = itor.next();
        String connObjectKey = null;
        try {
            connObjectKey = mappingManager.getConnObjectKeyValue(user, resource.getProvision(anyTypeDAO.findUser()).get()).get();
            Uid uid = connFactory.getConnector(resource).authenticate(connObjectKey, password, null);
            if (uid != null) {
                authenticated = true;
            }
        } catch (Exception e) {
            LOG.debug("Could not authenticate {} on {}", user.getUsername(), resource.getKey(), e);
        }
        LOG.debug("{} authenticated on {} as {}: {}", user.getUsername(), resource.getKey(), connObjectKey, authenticated);
    }
    return authenticated;
}
Also used : Uid(org.identityconnectors.framework.common.objects.Uid) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) DisabledException(org.springframework.security.authentication.DisabledException) AuthenticationCredentialsNotFoundException(org.springframework.security.authentication.AuthenticationCredentialsNotFoundException) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException)

Example 44 with ExternalResource

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

the class ResourceLogic method connObjectInit.

private Triple<ExternalResource, AnyType, Provision> connObjectInit(final String resourceKey, final String anyTypeKey) {
    ExternalResource resource = resourceDAO.authFind(resourceKey);
    if (resource == null) {
        throw new NotFoundException("Resource '" + resourceKey + "'");
    }
    AnyType anyType = anyTypeDAO.find(anyTypeKey);
    if (anyType == null) {
        throw new NotFoundException("AnyType '" + anyTypeKey + "'");
    }
    Optional<? extends Provision> provision = resource.getProvision(anyType);
    if (!provision.isPresent()) {
        throw new NotFoundException("Provision on resource '" + resourceKey + "' for type '" + anyTypeKey + "'");
    }
    return ImmutableTriple.of(resource, anyType, provision.get());
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType)

Example 45 with ExternalResource

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

the class ConnectorLogic method readByResource.

@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_READ + "')")
@Transactional(readOnly = true)
public ConnInstanceTO readByResource(final String resourceName, final String lang) {
    CurrentLocale.set(StringUtils.isBlank(lang) ? Locale.ENGLISH : new Locale(lang));
    ExternalResource resource = resourceDAO.find(resourceName);
    if (resource == null) {
        throw new NotFoundException("Resource '" + resourceName + "'");
    }
    ConnInstanceTO connInstance = binder.getConnInstanceTO(connFactory.getConnector(resource).getConnInstance());
    connInstance.setKey(resource.getConnector().getKey());
    return connInstance;
}
Also used : Locale(java.util.Locale) CurrentLocale(org.identityconnectors.common.l10n.CurrentLocale) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

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