use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class UserIssuesITCase method issueSYNCOPE505DB.
@Test
public void issueSYNCOPE505DB() throws Exception {
// 1. create user
UserTO user = UserITCase.getUniqueSampleTO("syncope505-db@syncope.apache.org");
user.setPassword("security123");
user = createUser(user).getEntity();
assertNotNull(user);
assertTrue(user.getResources().isEmpty());
// 2. Add DBPasswordPropagationActions
ImplementationTO propagationActions = new ImplementationTO();
propagationActions.setKey(DBPasswordPropagationActions.class.getSimpleName());
propagationActions.setEngine(ImplementationEngine.JAVA);
propagationActions.setType(ImplementationType.PROPAGATION_ACTIONS);
propagationActions.setBody(DBPasswordPropagationActions.class.getName());
Response response = implementationService.create(propagationActions);
propagationActions = implementationService.read(propagationActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(propagationActions);
ResourceTO resourceTO = resourceService.read(RESOURCE_NAME_TESTDB);
assertNotNull(resourceTO);
resourceTO.getPropagationActions().add(propagationActions.getKey());
resourceService.update(resourceTO);
// 3. Add a db resource to the User
UserPatch userPatch = new UserPatch();
userPatch.setKey(user.getKey());
userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_TESTDB).build());
userPatch.setPassword(new PasswordPatch.Builder().onSyncope(false).resource(RESOURCE_NAME_TESTDB).build());
user = updateUser(userPatch).getEntity();
assertNotNull(user);
assertEquals(1, user.getResources().size());
// 4. Check that the DB resource has the correct password
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
String value = jdbcTemplate.queryForObject("SELECT PASSWORD FROM test WHERE ID=?", String.class, user.getUsername());
assertEquals(Encryptor.getInstance().encode("security123", CipherAlgorithm.SHA1), value.toUpperCase());
// 5. Remove DBPasswordPropagationActions
resourceTO = resourceService.read(RESOURCE_NAME_TESTDB);
assertNotNull(resourceTO);
resourceTO.getPropagationActions().remove(propagationActions.getKey());
resourceService.update(resourceTO);
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class UserIssuesITCase method issueSYNCOPE626.
@Test
public void issueSYNCOPE626() {
DefaultPasswordRuleConf ruleConf = new DefaultPasswordRuleConf();
ruleConf.setUsernameAllowed(false);
ImplementationTO rule = new ImplementationTO();
rule.setKey("DefaultPasswordRuleConf" + getUUIDString());
rule.setEngine(ImplementationEngine.JAVA);
rule.setType(ImplementationType.PASSWORD_RULE);
rule.setBody(POJOHelper.serialize(ruleConf));
Response response = implementationService.create(rule);
rule.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
PasswordPolicyTO passwordPolicy = new PasswordPolicyTO();
passwordPolicy.setDescription("Password Policy for SYNCOPE-626");
passwordPolicy.getRules().add(rule.getKey());
passwordPolicy = createPolicy(PolicyType.PASSWORD, passwordPolicy);
assertNotNull(passwordPolicy);
RealmTO realm = realmService.list("/even/two").get(0);
String oldPasswordPolicy = realm.getPasswordPolicy();
realm.setPasswordPolicy(passwordPolicy.getKey());
realmService.update(realm);
try {
UserTO user = UserITCase.getUniqueSampleTO("syncope626@syncope.apache.org");
user.setRealm(realm.getFullPath());
user.setPassword(user.getUsername());
try {
createUser(user);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidUser, e.getType());
assertTrue(e.getElements().iterator().next().startsWith("InvalidPassword"));
}
user.setPassword("password123");
user = createUser(user).getEntity();
assertNotNull(user);
} finally {
realm.setPasswordPolicy(oldPasswordPolicy);
realmService.update(realm);
policyService.delete(PolicyType.PASSWORD, passwordPolicy.getKey());
}
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class SchedTaskITCase method issueSYNCOPE660.
@Test
public void issueSYNCOPE660() {
List<JobTO> jobs = taskService.listJobs();
int old_size = jobs.size();
ImplementationTO taskJobDelegate = implementationService.read(ImplementationType.TASKJOB_DELEGATE, TestSampleJobDelegate.class.getSimpleName());
assertNotNull(taskJobDelegate);
SchedTaskTO task = new SchedTaskTO();
task.setName("issueSYNCOPE660");
task.setDescription("issueSYNCOPE660 Description");
task.setJobDelegate(taskJobDelegate.getKey());
Response response = taskService.create(TaskType.SCHEDULED, task);
task = getObject(response.getLocation(), TaskService.class, SchedTaskTO.class);
jobs = taskService.listJobs();
assertEquals(old_size + 1, jobs.size());
taskService.actionJob(task.getKey(), JobAction.START);
int i = 0, maxit = 50;
do {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
jobs = taskService.listJobs().stream().filter(job -> job.isRunning()).collect(Collectors.toList());
i++;
} while (jobs.size() < 1 && i < maxit);
assertEquals(1, jobs.size());
assertEquals(task.getKey(), jobs.get(0).getRefKey());
taskService.actionJob(task.getKey(), JobAction.STOP);
i = 0;
do {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
jobs = taskService.listJobs().stream().filter(job -> job.isRunning()).collect(Collectors.toList());
i++;
} while (jobs.size() >= 1 && i < maxit);
assertTrue(jobs.isEmpty());
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class SchedTaskITCase method issueSYNCOPE144.
@Test
public void issueSYNCOPE144() {
ImplementationTO taskJobDelegate = implementationService.read(ImplementationType.TASKJOB_DELEGATE, TestSampleJobDelegate.class.getSimpleName());
assertNotNull(taskJobDelegate);
SchedTaskTO task = new SchedTaskTO();
task.setName("issueSYNCOPE144");
task.setDescription("issueSYNCOPE144 Description");
task.setJobDelegate(taskJobDelegate.getKey());
Response response = taskService.create(TaskType.SCHEDULED, task);
task = getObject(response.getLocation(), TaskService.class, SchedTaskTO.class);
assertNotNull(task);
assertEquals("issueSYNCOPE144", task.getName());
assertEquals("issueSYNCOPE144 Description", task.getDescription());
task = taskService.read(TaskType.SCHEDULED, task.getKey(), true);
assertNotNull(task);
assertEquals("issueSYNCOPE144", task.getName());
assertEquals("issueSYNCOPE144 Description", task.getDescription());
task.setName("issueSYNCOPE144_2");
task.setDescription("issueSYNCOPE144 Description_2");
response = taskService.create(TaskType.SCHEDULED, task);
task = getObject(response.getLocation(), TaskService.class, SchedTaskTO.class);
assertNotNull(task);
assertEquals("issueSYNCOPE144_2", task.getName());
assertEquals("issueSYNCOPE144 Description_2", task.getDescription());
}
use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.
the class UserITCase method customPolicyRules.
@Test
public void customPolicyRules() {
// Using custom policy rules with application/xml requires to overwrite
// org.apache.syncope.common.lib.policy.AbstractAccountRuleConf's and / or
// org.apache.syncope.common.lib.policy.AbstractPasswordRuleConf's
// @XmlSeeAlso - the power of JAXB :-/
assumeTrue(MediaType.APPLICATION_JSON_TYPE.equals(clientFactory.getContentType().getMediaType()));
ImplementationTO implementationTO = new ImplementationTO();
implementationTO.setKey("TestAccountRuleConf" + UUID.randomUUID().toString());
implementationTO.setEngine(ImplementationEngine.JAVA);
implementationTO.setType(ImplementationType.ACCOUNT_RULE);
implementationTO.setBody(POJOHelper.serialize(new TestAccountRuleConf()));
Response response = implementationService.create(implementationTO);
implementationTO.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
AccountPolicyTO accountPolicy = new AccountPolicyTO();
accountPolicy.setDescription("Account Policy with custom rules");
accountPolicy.getRules().add(implementationTO.getKey());
accountPolicy = createPolicy(PolicyType.ACCOUNT, accountPolicy);
assertNotNull(accountPolicy);
implementationTO = new ImplementationTO();
implementationTO.setKey("TestPasswordRuleConf" + UUID.randomUUID().toString());
implementationTO.setEngine(ImplementationEngine.JAVA);
implementationTO.setType(ImplementationType.PASSWORD_RULE);
implementationTO.setBody(POJOHelper.serialize(new TestPasswordRuleConf()));
response = implementationService.create(implementationTO);
implementationTO.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
PasswordPolicyTO passwordPolicy = new PasswordPolicyTO();
passwordPolicy.setDescription("Password Policy with custom rules");
passwordPolicy.getRules().add(implementationTO.getKey());
passwordPolicy = createPolicy(PolicyType.PASSWORD, passwordPolicy);
assertNotNull(passwordPolicy);
RealmTO realm = realmService.list("/even/two").get(0);
String oldAccountPolicy = realm.getAccountPolicy();
realm.setAccountPolicy(accountPolicy.getKey());
String oldPasswordPolicy = realm.getPasswordPolicy();
realm.setPasswordPolicy(passwordPolicy.getKey());
realmService.update(realm);
try {
UserTO user = getUniqueSampleTO("custompolicyrules@syncope.apache.org");
user.setRealm(realm.getFullPath());
try {
createUser(user);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidUser, e.getType());
assertTrue(e.getElements().iterator().next().startsWith("InvalidPassword"));
}
user.setPassword(user.getPassword() + "XXX");
try {
createUser(user);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidUser, e.getType());
assertTrue(e.getElements().iterator().next().startsWith("InvalidUsername"));
}
user.setUsername("YYY" + user.getUsername());
user = createUser(user).getEntity();
assertNotNull(user);
} finally {
realm.setAccountPolicy(oldAccountPolicy);
realm.setPasswordPolicy(oldPasswordPolicy);
realmService.update(realm);
policyService.delete(PolicyType.PASSWORD, passwordPolicy.getKey());
policyService.delete(PolicyType.ACCOUNT, accountPolicy.getKey());
}
}
Aggregations