Search in sources :

Example 6 with Implementation

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

the class RealmDataBinderImpl method create.

@Override
public Realm create(final Realm parent, final RealmTO realmTO) {
    Realm realm = entityFactory.newEntity(Realm.class);
    realm.setName(realmTO.getName());
    realm.setParent(parent);
    if (realmTO.getPasswordPolicy() != null) {
        Policy policy = policyDAO.find(realmTO.getPasswordPolicy());
        if (policy instanceof PasswordPolicy) {
            realm.setPasswordPolicy((PasswordPolicy) policy);
        } else {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
            sce.getElements().add("Expected " + PasswordPolicy.class.getSimpleName() + ", found " + policy.getClass().getSimpleName());
            throw sce;
        }
    }
    if (realmTO.getAccountPolicy() != null) {
        Policy policy = policyDAO.find(realmTO.getAccountPolicy());
        if (policy instanceof AccountPolicy) {
            realm.setAccountPolicy((AccountPolicy) policy);
        } else {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
            sce.getElements().add("Expected " + AccountPolicy.class.getSimpleName() + ", found " + policy.getClass().getSimpleName());
            throw sce;
        }
    }
    realmTO.getActions().forEach(logicActionsKey -> {
        Implementation logicAction = implementationDAO.find(logicActionsKey);
        if (logicAction == null) {
            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", logicActionsKey);
        } else {
            realm.add(logicAction);
        }
    });
    setTemplates(realmTO, realm);
    realmTO.getResources().forEach(resourceKey -> {
        ExternalResource resource = resourceDAO.find(resourceKey);
        if (resource == null) {
            LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey);
        } else {
            realm.add(resource);
        }
    });
    return realm;
}
Also used : PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) Policy(org.apache.syncope.core.persistence.api.entity.policy.Policy) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyTemplateRealm(org.apache.syncope.core.persistence.api.entity.AnyTemplateRealm) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Example 7 with Implementation

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

the class RealmDataBinderImpl method update.

@Override
public PropagationByResource update(final Realm realm, final RealmTO realmTO) {
    realm.setName(realmTO.getName());
    realm.setParent(realmTO.getParent() == null ? null : realmDAO.find(realmTO.getParent()));
    if (realmTO.getAccountPolicy() == null) {
        realm.setAccountPolicy(null);
    } else {
        Policy policy = policyDAO.find(realmTO.getAccountPolicy());
        if (policy instanceof AccountPolicy) {
            realm.setAccountPolicy((AccountPolicy) policy);
        } else {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
            sce.getElements().add("Expected " + AccountPolicy.class.getSimpleName() + ", found " + policy.getClass().getSimpleName());
            throw sce;
        }
    }
    if (realmTO.getPasswordPolicy() == null) {
        realm.setPasswordPolicy(null);
    } else {
        Policy policy = policyDAO.find(realmTO.getPasswordPolicy());
        if (policy instanceof PasswordPolicy) {
            realm.setPasswordPolicy((PasswordPolicy) policy);
        } else {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
            sce.getElements().add("Expected " + PasswordPolicy.class.getSimpleName() + ", found " + policy.getClass().getSimpleName());
            throw sce;
        }
    }
    realmTO.getActions().forEach(logicActionsKey -> {
        Implementation logicActions = implementationDAO.find(logicActionsKey);
        if (logicActions == null) {
            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", logicActionsKey);
        } else {
            realm.add(logicActions);
        }
    });
    // remove all implementations not contained in the TO
    realm.getActions().removeIf(implementation -> !realmTO.getActions().contains(implementation.getKey()));
    setTemplates(realmTO, realm);
    PropagationByResource propByRes = new PropagationByResource();
    realmTO.getResources().forEach(resourceKey -> {
        ExternalResource resource = resourceDAO.find(resourceKey);
        if (resource == null) {
            LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey);
        } else {
            realm.add(resource);
            propByRes.add(ResourceOperation.CREATE, resource.getKey());
        }
    });
    // remove all resources not contained in the TO
    realm.getResources().removeIf(resource -> {
        boolean contained = realmTO.getResources().contains(resource.getKey());
        if (!contained) {
            propByRes.add(ResourceOperation.DELETE, resource.getKey());
        }
        return !contained;
    });
    return propByRes;
}
Also used : PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) Policy(org.apache.syncope.core.persistence.api.entity.policy.Policy) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Example 8 with Implementation

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

the class TaskJob method execute.

@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
    try {
        AuthContextUtils.execWithAuthContext(context.getMergedJobDataMap().getString(JobManager.DOMAIN_KEY), () -> {
            try {
                ImplementationDAO implementationDAO = ApplicationContextProvider.getApplicationContext().getBean(ImplementationDAO.class);
                Implementation implementation = implementationDAO.find(context.getMergedJobDataMap().getString(DELEGATE_IMPLEMENTATION));
                if (implementation == null) {
                    LOG.error("Could not find Implementation '{}', aborting", context.getMergedJobDataMap().getString(DELEGATE_IMPLEMENTATION));
                } else {
                    delegate = ImplementationManager.<SchedTaskJobDelegate>build(implementation);
                    delegate.execute(taskKey, context.getMergedJobDataMap().getBoolean(DRY_RUN_JOBDETAIL_KEY), context);
                }
            } catch (Exception e) {
                LOG.error("While executing task {}", taskKey, e);
                throw new RuntimeException(e);
            }
            return null;
        });
    } catch (RuntimeException e) {
        LOG.error("While executing task {}", taskKey, e);
        throw new JobExecutionException("While executing task " + taskKey, e);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) JobExecutionException(org.quartz.JobExecutionException)

Example 9 with Implementation

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

the class ImplementationLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.IMPLEMENTATION_UPDATE + "')")
public ImplementationTO update(final ImplementationTO implementationTO) {
    Implementation implementation = implementationDAO.find(implementationTO.getKey());
    if (implementation == null) {
        LOG.error("Could not find implementation '" + implementationTO.getKey() + "'");
        throw new NotFoundException(implementationTO.getKey());
    }
    binder.update(implementation, implementationTO);
    implementation = implementationDAO.save(implementation);
    return binder.getImplementationTO(implementation);
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 10 with Implementation

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

the class ImplementationTest method create.

@Test
public void create() {
    Implementation impl = entityFactory.newEntity(Implementation.class);
    impl.setKey("new");
    impl.setEngine(ImplementationEngine.GROOVY);
    impl.setType(ImplementationType.VALIDATOR);
    impl.setBody("");
    Implementation actual = implementationDAO.save(impl);
    assertNotNull(actual);
    assertEquals(impl, actual);
}
Also used : Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

Implementation (org.apache.syncope.core.persistence.api.entity.Implementation)28 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)12 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)8 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)8 PasswordPolicy (org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy)7 ImplementationDAO (org.apache.syncope.core.persistence.api.dao.ImplementationDAO)6 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)6 Test (org.junit.jupiter.api.Test)6 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)5 Date (java.util.Date)4 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)4 EntityFactory (org.apache.syncope.core.persistence.api.entity.EntityFactory)4 AccountPolicy (org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy)4 PullPolicy (org.apache.syncope.core.persistence.api.entity.policy.PullPolicy)4 PullTask (org.apache.syncope.core.persistence.api.entity.task.PullTask)4 SchedTask (org.apache.syncope.core.persistence.api.entity.task.SchedTask)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4