Search in sources :

Example 21 with Implementation

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

the class ImplementationLogic method read.

@PreAuthorize("hasRole('" + StandardEntitlement.IMPLEMENTATION_READ + "')")
@Transactional(readOnly = true)
public ImplementationTO read(final ImplementationType type, final String key) {
    Implementation implementation = implementationDAO.find(key);
    if (implementation == null) {
        LOG.error("Could not find implementation '" + key + "'");
        throw new NotFoundException(key);
    }
    if (implementation.getType() != type) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + type + ", expected " + implementation.getType());
        throw sce;
    }
    return binder.getImplementationTO(implementation);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) 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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with Implementation

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

the class ImplementationLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.IMPLEMENTATION_CREATE + "')")
public ImplementationTO create(final ImplementationTO implementationTO) {
    if (StringUtils.isBlank(implementationTO.getKey())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
        sce.getElements().add("Implementation key");
        throw sce;
    }
    Implementation implementation = implementationDAO.find(implementationTO.getKey());
    if (implementation != null) {
        throw new DuplicateException(implementationTO.getKey());
    }
    return binder.getImplementationTO(implementationDAO.save(binder.create(implementationTO)));
}
Also used : DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 23 with Implementation

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

the class ImplementationLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.IMPLEMENTATION_DELETE + "')")
public void delete(final ImplementationType type, final String key) {
    Implementation implementation = implementationDAO.find(key);
    if (implementation == null) {
        LOG.error("Could not find implementation '" + key + "'");
        throw new NotFoundException(key);
    }
    if (implementation.getType() != type) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + type + ", expected " + implementation.getType());
        throw sce;
    }
    boolean inUse = false;
    switch(implementation.getType()) {
        case REPORTLET:
            inUse = !reportDAO.findByReportlet(implementation).isEmpty();
            break;
        case ACCOUNT_RULE:
            inUse = !policyDAO.findByAccountRule(implementation).isEmpty();
            break;
        case PASSWORD_RULE:
            inUse = !policyDAO.findByPasswordRule(implementation).isEmpty();
            break;
        case ITEM_TRANSFORMER:
            inUse = !resourceDAO.findByTransformer(implementation).isEmpty();
            break;
        case TASKJOB_DELEGATE:
            inUse = !taskDAO.findByDelegate(implementation).isEmpty();
            break;
        case RECON_FILTER_BUILDER:
            inUse = !taskDAO.findByReconFilterBuilder(implementation).isEmpty();
            break;
        case LOGIC_ACTIONS:
            inUse = !realmDAO.findByLogicActions(implementation).isEmpty();
            break;
        case PROPAGATION_ACTIONS:
            inUse = !resourceDAO.findByPropagationActions(implementation).isEmpty();
            break;
        case PULL_ACTIONS:
            inUse = !taskDAO.findByPullActions(implementation).isEmpty();
            break;
        case PUSH_ACTIONS:
            inUse = !taskDAO.findByPushActions(implementation).isEmpty();
            break;
        case PULL_CORRELATION_RULE:
            inUse = !policyDAO.findByCorrelationRule(implementation).isEmpty();
            break;
        case VALIDATOR:
            inUse = !plainSchemaDAO.findByValidator(implementation).isEmpty();
            break;
        case RECIPIENTS_PROVIDER:
            inUse = !notificationDAO.findByRecipientsProvider(implementation).isEmpty();
            break;
        default:
    }
    if (inUse) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InUse);
        sce.getElements().add("This implementation is in use");
        throw sce;
    }
    implementationDAO.delete(key);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) 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 24 with Implementation

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

the class JPAImplementationDAO method delete.

@Override
public void delete(final String key) {
    Implementation implementation = find(key);
    if (implementation == null) {
        return;
    }
    entityManager().remove(implementation);
    ImplementationManager.purge(key);
}
Also used : JPAImplementation(org.apache.syncope.core.persistence.jpa.entity.JPAImplementation) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

Example 25 with Implementation

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

the class PolicyTest method create.

@Test
public void create() {
    PullPolicy policy = entityFactory.newEntity(PullPolicy.class);
    policy.setConflictResolutionAction(ConflictResolutionAction.IGNORE);
    policy.setDescription("Pull policy");
    final String pullURuleName = "net.tirasa.pull.correlation.TirasaURule";
    final String pullGRuleName = "net.tirasa.pull.correlation.TirasaGRule";
    Implementation impl1 = entityFactory.newEntity(Implementation.class);
    impl1.setKey(pullURuleName);
    impl1.setEngine(ImplementationEngine.JAVA);
    impl1.setType(ImplementationType.PULL_CORRELATION_RULE);
    impl1.setBody(PullCorrelationRule.class.getName());
    impl1 = implementationDAO.save(impl1);
    CorrelationRule rule1 = entityFactory.newEntity(CorrelationRule.class);
    rule1.setAnyType(anyTypeDAO.findUser());
    rule1.setPullPolicy(policy);
    rule1.setImplementation(impl1);
    policy.add(rule1);
    Implementation impl2 = entityFactory.newEntity(Implementation.class);
    impl2.setKey(pullGRuleName);
    impl2.setEngine(ImplementationEngine.JAVA);
    impl2.setType(ImplementationType.PULL_CORRELATION_RULE);
    impl2.setBody(PullCorrelationRule.class.getName());
    impl2 = implementationDAO.save(impl2);
    CorrelationRule rule2 = entityFactory.newEntity(CorrelationRule.class);
    rule2.setAnyType(anyTypeDAO.findGroup());
    rule2.setPullPolicy(policy);
    rule2.setImplementation(impl2);
    policy.add(rule2);
    policy = policyDAO.save(policy);
    assertNotNull(policy);
    assertEquals(pullURuleName, policy.getCorrelationRule(anyTypeDAO.findUser()).get().getImplementation().getKey());
    assertEquals(pullGRuleName, policy.getCorrelationRule(anyTypeDAO.findGroup()).get().getImplementation().getKey());
}
Also used : PullCorrelationRule(org.apache.syncope.core.persistence.api.dao.PullCorrelationRule) PullPolicy(org.apache.syncope.core.persistence.api.entity.policy.PullPolicy) PullCorrelationRule(org.apache.syncope.core.persistence.api.dao.PullCorrelationRule) CorrelationRule(org.apache.syncope.core.persistence.api.entity.policy.CorrelationRule) 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