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