Search in sources :

Example 1 with ImplementationTO

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);
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) DBPasswordPropagationActions(org.apache.syncope.core.provisioning.java.propagation.DBPasswordPropagationActions) Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 2 with ImplementationTO

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());
    }
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf) UserTO(org.apache.syncope.common.lib.to.UserTO) RealmTO(org.apache.syncope.common.lib.to.RealmTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PasswordPolicyTO(org.apache.syncope.common.lib.policy.PasswordPolicyTO) Test(org.junit.jupiter.api.Test)

Example 3 with ImplementationTO

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());
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) TestSampleJobDelegate(org.apache.syncope.fit.core.reference.TestSampleJobDelegate) JobTO(org.apache.syncope.common.lib.to.JobTO) Test(org.junit.jupiter.api.Test)

Example 4 with ImplementationTO

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());
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) TestSampleJobDelegate(org.apache.syncope.fit.core.reference.TestSampleJobDelegate) Test(org.junit.jupiter.api.Test)

Example 5 with ImplementationTO

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());
    }
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) TestPasswordRuleConf(org.apache.syncope.fit.core.reference.TestPasswordRuleConf) UserTO(org.apache.syncope.common.lib.to.UserTO) RealmTO(org.apache.syncope.common.lib.to.RealmTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AccountPolicyTO(org.apache.syncope.common.lib.policy.AccountPolicyTO) TestAccountRuleConf(org.apache.syncope.fit.core.reference.TestAccountRuleConf) PasswordPolicyTO(org.apache.syncope.common.lib.policy.PasswordPolicyTO) Test(org.junit.jupiter.api.Test)

Aggregations

ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)30 Response (javax.ws.rs.core.Response)24 Test (org.junit.jupiter.api.Test)24 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)10 UserTO (org.apache.syncope.common.lib.to.UserTO)9 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)7 TaskService (org.apache.syncope.common.rest.api.service.TaskService)6 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)5 ReportTO (org.apache.syncope.common.lib.to.ReportTO)5 AccountPolicyTO (org.apache.syncope.common.lib.policy.AccountPolicyTO)4 ExecTO (org.apache.syncope.common.lib.to.ExecTO)4 RealmTO (org.apache.syncope.common.lib.to.RealmTO)4 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)4 DefaultAccountRuleConf (org.apache.syncope.common.lib.policy.DefaultAccountRuleConf)3 PasswordPolicyTO (org.apache.syncope.common.lib.policy.PasswordPolicyTO)3 UserReportletConf (org.apache.syncope.common.lib.report.UserReportletConf)3 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)3 SchedTaskTO (org.apache.syncope.common.lib.to.SchedTaskTO)3 TestSampleJobDelegate (org.apache.syncope.fit.core.reference.TestSampleJobDelegate)3 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)3