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)));
}
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;
}
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)));
}
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);
}
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;
}
Aggregations