Search in sources :

Example 6 with DuplicateException

use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.

the class ResourceLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_CREATE + "')")
public ResourceTO create(final ResourceTO resourceTO) {
    if (StringUtils.isBlank(resourceTO.getKey())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
        sce.getElements().add("Resource key");
        throw sce;
    }
    ConnInstance connInstance = connInstanceDAO.authFind(resourceTO.getConnector());
    if (connInstance == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidExternalResource);
        sce.getElements().add("Connector " + resourceTO.getConnector());
        throw sce;
    }
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.RESOURCE_CREATE), connInstance.getAdminRealm().getFullPath());
    securityChecks(effectiveRealms, connInstance.getAdminRealm().getFullPath(), null);
    if (resourceDAO.authFind(resourceTO.getKey()) != null) {
        throw new DuplicateException(resourceTO.getKey());
    }
    return binder.getResourceTO(resourceDAO.save(binder.create(resourceTO)));
}
Also used : DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with DuplicateException

use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.

the class SchemaLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_CREATE + "')")
@SuppressWarnings("unchecked")
public <T extends SchemaTO> T create(final SchemaType schemaType, final T schemaTO) {
    if (StringUtils.isBlank(schemaTO.getKey())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
        sce.getElements().add("Schema key");
        throw sce;
    }
    if (doesSchemaExist(schemaType, schemaTO.getKey())) {
        throw new DuplicateException(schemaType + "/" + schemaTO.getKey());
    }
    T created;
    switch(schemaType) {
        case VIRTUAL:
            VirSchema virSchema = virSchemaDAO.save(binder.create((VirSchemaTO) schemaTO));
            created = (T) binder.getVirSchemaTO(virSchema);
            break;
        case DERIVED:
            DerSchema derSchema = derSchemaDAO.save(binder.create((DerSchemaTO) schemaTO));
            created = (T) binder.getDerSchemaTO(derSchema);
            break;
        case PLAIN:
        default:
            PlainSchema plainSchema = plainSchemaDAO.save(binder.create((PlainSchemaTO) schemaTO));
            created = (T) binder.getPlainSchemaTO(plainSchema);
    }
    return created;
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 8 with DuplicateException

use of org.apache.syncope.core.persistence.api.dao.DuplicateException 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 9 with DuplicateException

use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.

the class MailTemplateLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.MAIL_TEMPLATE_CREATE + "')")
public MailTemplateTO create(final String key) {
    if (mailTemplateDAO.find(key) != null) {
        throw new DuplicateException(key);
    }
    MailTemplate mailTemplate = entityFactory.newEntity(MailTemplate.class);
    mailTemplate.setKey(key);
    mailTemplateDAO.save(mailTemplate);
    return getMailTemplateTO(key);
}
Also used : DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) MailTemplate(org.apache.syncope.core.persistence.api.entity.MailTemplate) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 10 with DuplicateException

use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.

the class RealmLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.REALM_CREATE + "')")
public ProvisioningResult<RealmTO> create(final String parentPath, final RealmTO realmTO) {
    Realm parent;
    if (StringUtils.isBlank(realmTO.getParent())) {
        parent = realmDAO.findByFullPath(parentPath);
        if (parent == null) {
            LOG.error("Could not find parent realm " + parentPath);
            throw new NotFoundException(parentPath);
        }
        realmTO.setParent(parent.getFullPath());
    } else {
        parent = realmDAO.find(realmTO.getParent());
        if (parent == null) {
            LOG.error("Could not find parent realm " + realmTO.getParent());
            throw new NotFoundException(realmTO.getParent());
        }
        if (!parent.getFullPath().equals(parentPath)) {
            SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPath);
            sce.getElements().add("Mismatching parent realm: " + parentPath + " Vs " + parent.getFullPath());
            throw sce;
        }
    }
    String fullPath = StringUtils.appendIfMissing(parent.getFullPath(), "/") + realmTO.getName();
    if (realmDAO.findByFullPath(fullPath) != null) {
        throw new DuplicateException(fullPath);
    }
    Realm realm = realmDAO.save(binder.create(parent, realmTO));
    PropagationByResource propByRes = new PropagationByResource();
    realm.getResourceKeys().forEach(resource -> {
        propByRes.add(ResourceOperation.CREATE, resource);
    });
    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
    ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getRealmTO(realm, true));
    result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
    return result;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RealmTO(org.apache.syncope.common.lib.to.RealmTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)10 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 ValidationException (javax.validation.ValidationException)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 ParsingValidationException (org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException)2 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 EntityExistsException (javax.persistence.EntityExistsException)1 PersistenceException (javax.persistence.PersistenceException)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)1 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)1 ErrorTO (org.apache.syncope.common.lib.to.ErrorTO)1 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)1 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)1 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)1 RealmTO (org.apache.syncope.common.lib.to.RealmTO)1