use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class NotificationTaskITCase method issueSYNCOPE446.
@Test
public void issueSYNCOPE446() throws Exception {
// 1. Create notification
ImplementationTO recipientsProvider = new ImplementationTO();
recipientsProvider.setKey(TestNotificationRecipientsProvider.class.getSimpleName());
recipientsProvider.setEngine(ImplementationEngine.JAVA);
recipientsProvider.setType(ImplementationType.RECIPIENTS_PROVIDER);
recipientsProvider.setBody(TestNotificationRecipientsProvider.class.getName());
Response response = implementationService.create(recipientsProvider);
recipientsProvider = implementationService.read(recipientsProvider.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(recipientsProvider);
NotificationTO notification = new NotificationTO();
notification.setTraceLevel(TraceLevel.ALL);
notification.getEvents().add("[LOGIC]:[GroupLogic]:[]:[create]:[SUCCESS]");
String groupName = "group" + getUUIDString();
notification.getAbouts().put(AnyTypeKind.GROUP.name(), SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo(groupName).query());
notification.setRecipientsFIQL(SyncopeClient.getUserSearchConditionBuilder().inGroups("f779c0d4-633b-4be5-8f57-32eb478a3ca5").query());
notification.setSelfAsRecipient(false);
notification.setRecipientAttrName("email");
notification.getStaticRecipients().add("notificationtest@syncope.apache.org");
notification.setRecipientsProvider(recipientsProvider.getKey());
String sender = "syncopetest-" + getUUIDString() + "@syncope.apache.org";
notification.setSender(sender);
String subject = "Test notification " + getUUIDString();
notification.setSubject(subject);
notification.setTemplate("optin");
notification.setActive(true);
response = notificationService.create(notification);
notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
assertNotNull(notification);
assertEquals(recipientsProvider.getKey(), notification.getRecipientsProvider());
// 2. create group
GroupTO groupTO = new GroupTO();
groupTO.setName(groupName);
groupTO.setRealm("/even/two");
groupTO = createGroup(groupTO).getEntity();
assertNotNull(groupTO);
// 3. verify
NotificationTaskTO taskTO = findNotificationTask(notification.getKey(), 50);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
assertTrue(taskTO.getRecipients().containsAll(new TestNotificationRecipientsProvider().provideRecipients(null)));
NotificationTaskTO foundViaList = taskService.<NotificationTaskTO>search(new TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification.getKey()).build()).getResult().get(0);
assertEquals(taskTO, foundViaList);
execNotificationTask(taskService, taskTO.getKey(), 50);
assertTrue(verifyMail(sender, subject, "notificationtest@syncope.apache.org"));
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class PolicyITCase method buildPullPolicyTO.
private PullPolicyTO buildPullPolicyTO() throws IOException {
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 policy = new PullPolicyTO();
policy.getCorrelationRules().put(AnyTypeKind.USER.name(), corrRule.getKey());
policy.setDescription("Pull policy");
return policy;
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class PolicyITCase method update.
@Test
public void update() {
PasswordPolicyTO globalPolicy = policyService.read(PolicyType.PASSWORD, "ce93fcda-dc3a-4369-a7b0-a6108c261c85");
PasswordPolicyTO policy = SerializationUtils.clone(globalPolicy);
policy.setDescription("A simple password policy");
// create a new password policy using the former as a template
policy = createPolicy(PolicyType.PASSWORD, policy);
assertNotNull(policy);
assertNotEquals("ce93fcda-dc3a-4369-a7b0-a6108c261c85", policy.getKey());
ImplementationTO rule = implementationService.read(ImplementationType.PASSWORD_RULE, policy.getRules().get(0));
assertNotNull(rule);
DefaultPasswordRuleConf ruleConf = POJOHelper.deserialize(rule.getBody(), DefaultPasswordRuleConf.class);
ruleConf.setMaxLength(22);
rule.setBody(POJOHelper.serialize(ruleConf));
// update new password policy
policyService.update(PolicyType.PASSWORD, policy);
policy = policyService.read(PolicyType.PASSWORD, policy.getKey());
assertNotNull(policy);
ruleConf = POJOHelper.deserialize(rule.getBody(), DefaultPasswordRuleConf.class);
assertEquals(22, ruleConf.getMaxLength());
assertEquals(8, ruleConf.getMinLength());
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class PullTaskITCase method issueSYNCOPE313LDAP.
@Test
public void issueSYNCOPE313LDAP() throws Exception {
// First of all, clear any potential conflict with existing user / group
ldapCleanup();
UserTO user = null;
PullTaskTO pullTask = null;
ConnInstanceTO resourceConnector = null;
ConnConfProperty property = null;
try {
// 1. create user in LDAP
String oldCleanPassword = "security123";
user = UserITCase.getUniqueSampleTO("syncope313-ldap@syncope.apache.org");
user.setPassword(oldCleanPassword);
user.getResources().add(RESOURCE_NAME_LDAP);
user = createUser(user).getEntity();
assertNotNull(user);
assertFalse(user.getResources().isEmpty());
// 2. request to change password only on Syncope and not on LDAP
String newCleanPassword = "new-security123";
UserPatch userPatch = new UserPatch();
userPatch.setKey(user.getKey());
userPatch.setPassword(new PasswordPatch.Builder().value(newCleanPassword).build());
user = updateUser(userPatch).getEntity();
// 3. Check that the Syncope user now has the changed password
Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(user.getUsername(), newCleanPassword).self();
assertNotNull(self);
// 4. Check that the LDAP resource has the old password
ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), oldCleanPassword, connObject.getAttr(Name.NAME).get().getValues().get(0)));
// 5. Update the LDAP Connector to retrieve passwords
ResourceTO ldapResource = resourceService.read(RESOURCE_NAME_LDAP);
resourceConnector = connectorService.read(ldapResource.getConnector(), Locale.ENGLISH.getLanguage());
property = resourceConnector.getConf("retrievePasswordsWithSearch").get();
property.getValues().clear();
property.getValues().add(Boolean.TRUE);
connectorService.update(resourceConnector);
// 6. Pull the user from the resource
ImplementationTO pullActions = new ImplementationTO();
pullActions.setKey(LDAPPasswordPullActions.class.getSimpleName());
pullActions.setEngine(ImplementationEngine.JAVA);
pullActions.setType(ImplementationType.PULL_ACTIONS);
pullActions.setBody(LDAPPasswordPullActions.class.getName());
Response response = implementationService.create(pullActions);
pullActions = implementationService.read(pullActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(pullActions);
pullTask = new PullTaskTO();
pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
pullTask.setName("LDAP Pull Task");
pullTask.setActive(true);
pullTask.setPerformCreate(true);
pullTask.setPerformUpdate(true);
pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
pullTask.setResource(RESOURCE_NAME_LDAP);
pullTask.getActions().add(pullActions.getKey());
Response taskResponse = taskService.create(TaskType.PULL, pullTask);
pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
assertNotNull(pullTask);
ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// 7. Test the pulled user
self = clientFactory.create(user.getUsername(), oldCleanPassword).self();
assertNotNull(self);
} catch (Exception e) {
fail(e.getMessage());
} finally {
// Delete PullTask + user + reset the connector
if (pullTask != null) {
taskService.delete(TaskType.PULL, pullTask.getKey());
}
if (resourceConnector != null && property != null) {
property.getValues().clear();
property.getValues().add(Boolean.FALSE);
connectorService.update(resourceConnector);
}
if (user != null) {
deleteUser(user.getKey());
}
}
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class PullTaskITCase method testPullActionsSetup.
@BeforeAll
public static void testPullActionsSetup() {
ImplementationTO pullActions = null;
try {
pullActions = implementationService.read(ImplementationType.PULL_ACTIONS, TestPullActions.class.getSimpleName());
} catch (SyncopeClientException e) {
if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
pullActions = new ImplementationTO();
pullActions.setKey(TestPullActions.class.getSimpleName());
pullActions.setEngine(ImplementationEngine.JAVA);
pullActions.setType(ImplementationType.PULL_ACTIONS);
pullActions.setBody(TestPullActions.class.getName());
Response response = implementationService.create(pullActions);
pullActions = implementationService.read(pullActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(pullActions);
}
}
assertNotNull(pullActions);
PullTaskTO pullTask = taskService.read(TaskType.PULL, PULL_TASK_KEY, true);
pullTask.getActions().add(pullActions.getKey());
taskService.update(TaskType.PULL, pullTask);
}
Aggregations