use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class PullTaskITCase method issueSYNCOPE258.
@Test
public void issueSYNCOPE258() throws IOException {
// -----------------------------
// Add a custom correlation rule
// -----------------------------
ImplementationTO corrRule = null;
try {
corrRule = implementationService.read(ImplementationType.PULL_CORRELATION_RULE, "TestPullRule");
} catch (SyncopeClientException e) {
if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
corrRule = new ImplementationTO();
corrRule.setKey("TestPullRule");
corrRule.setEngine(ImplementationEngine.GROOVY);
corrRule.setType(ImplementationType.PULL_CORRELATION_RULE);
corrRule.setBody(IOUtils.toString(getClass().getResourceAsStream("/TestPullRule.groovy"), StandardCharsets.UTF_8));
Response response = implementationService.create(corrRule);
corrRule = implementationService.read(corrRule.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(corrRule);
}
}
assertNotNull(corrRule);
PullPolicyTO policyTO = policyService.read(PolicyType.PULL, "9454b0d7-2610-400a-be82-fc23cf553dd6");
policyTO.getCorrelationRules().put(AnyTypeKind.USER.name(), corrRule.getKey());
policyService.update(PolicyType.PULL, policyTO);
// -----------------------------
PullTaskTO task = new PullTaskTO();
task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
task.setName("Test Pull Rule");
task.setActive(true);
task.setResource(RESOURCE_NAME_WS2);
task.setPullMode(PullMode.FULL_RECONCILIATION);
task.setPerformCreate(true);
task.setPerformDelete(true);
task.setPerformUpdate(true);
Response response = taskService.create(TaskType.PULL, task);
task = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
UserTO userTO = UserITCase.getUniqueSampleTO("s258_1@apache.org");
userTO.getResources().clear();
userTO.getResources().add(RESOURCE_NAME_WS2);
createUser(userTO);
userTO = UserITCase.getUniqueSampleTO("s258_2@apache.org");
userTO.getResources().clear();
userTO.getResources().add(RESOURCE_NAME_WS2);
userTO = createUser(userTO).getEntity();
// change email in order to unmatch the second user
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getPlainAttrs().add(attrAddReplacePatch("email", "s258@apache.org"));
userService.update(userPatch);
execProvisioningTask(taskService, TaskType.PULL, task.getKey(), 50, false);
PullTaskTO executed = taskService.read(TaskType.PULL, task.getKey(), true);
assertEquals(1, executed.getExecutions().size());
// asser for just one match
assertTrue(executed.getExecutions().get(0).getMessage().contains("[updated/failures]: 1/0"), executed.getExecutions().get(0).getMessage().substring(0, 55) + "...");
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class RealmITCase method deletingAccountPolicy.
@Test
public void deletingAccountPolicy() {
// 1. create account policy
DefaultAccountRuleConf ruleConf = new DefaultAccountRuleConf();
ruleConf.setMinLength(3);
ruleConf.setMaxLength(8);
ImplementationTO rule = new ImplementationTO();
rule.setKey("DefaultAccountRuleConf" + UUID.randomUUID().toString());
rule.setEngine(ImplementationEngine.JAVA);
rule.setType(ImplementationType.ACCOUNT_RULE);
rule.setBody(POJOHelper.serialize(ruleConf));
Response response = implementationService.create(rule);
rule.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
AccountPolicyTO policy = new AccountPolicyTO();
policy.setDescription("deletingAccountPolicy");
policy.getRules().add(rule.getKey());
policy = createPolicy(PolicyType.ACCOUNT, policy);
assertNotNull(policy);
// 2. create realm with policy assigned
RealmTO realm = new RealmTO();
realm.setName("withppolicy");
response = realmService.create(SyncopeConstants.ROOT_REALM, realm);
RealmTO[] actuals = getObject(response.getLocation(), RealmService.class, RealmTO[].class);
assertNotNull(actuals);
assertTrue(actuals.length > 0);
realm = actuals[0];
String existingAccountPolicy = realm.getAccountPolicy();
realm.setAccountPolicy(policy.getKey());
realmService.update(realm);
actuals = getObject(response.getLocation(), RealmService.class, RealmTO[].class);
assertNotNull(actuals);
assertTrue(actuals.length > 0);
RealmTO actual = actuals[0];
assertEquals(policy.getKey(), actual.getAccountPolicy());
// 3. remove policy
policyService.delete(PolicyType.ACCOUNT, policy.getKey());
// 4. verify
actual = getRealm(actual.getFullPath()).get();
assertEquals(existingAccountPolicy, actual.getAccountPolicy());
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class ImplementationDataBinderImpl method getImplementationTO.
@Override
public ImplementationTO getImplementationTO(final Implementation implementation) {
ImplementationTO implementationTO = new ImplementationTO();
BeanUtils.copyProperties(implementation, implementationTO);
return implementationTO;
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class ReportletWizardBuilder method onApplyInternal.
@Override
protected Serializable onApplyInternal(final ReportletWrapper modelObject) {
if (modelObject.getImplementationEngine() == ImplementationEngine.JAVA) {
ImplementationTO reportlet = implementationClient.read(ImplementationType.REPORTLET, modelObject.getImplementationKey());
try {
reportlet.setBody(MAPPER.writeValueAsString(modelObject.getConf()));
implementationClient.update(reportlet);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
ReportTO reportTO = restClient.read(report);
if (modelObject.isNew()) {
reportTO.getReportlets().add(modelObject.getImplementationKey());
}
restClient.update(reportTO);
return modelObject;
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class PolicyRuleWizardBuilder method onApplyInternal.
@Override
protected Serializable onApplyInternal(final PolicyRuleWrapper modelObject) {
PolicyTO policyTO = restClient.getPolicy(type, policy);
ComposablePolicy composable;
if (policyTO instanceof ComposablePolicy) {
composable = (ComposablePolicy) policyTO;
} else {
throw new IllegalStateException("Non composable policy");
}
if (modelObject.getImplementationEngine() == ImplementationEngine.JAVA) {
ImplementationTO rule = implementationClient.read(implementationType, modelObject.getImplementationKey());
try {
rule.setBody(MAPPER.writeValueAsString(modelObject.getConf()));
implementationClient.update(rule);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
if (modelObject.isNew()) {
composable.getRules().add(modelObject.getImplementationKey());
}
restClient.updatePolicy(type, policyTO);
return modelObject;
}
Aggregations