Search in sources :

Example 26 with ImplementationTO

use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.

the class ImplementationITCase method delete.

@Test
public void delete() {
    ImplementationTO implementationTO = new ImplementationTO();
    implementationTO.setKey(UUID.randomUUID().toString());
    implementationTO.setEngine(ImplementationEngine.JAVA);
    implementationTO.setType(ImplementationType.PULL_ACTIONS);
    implementationTO.setBody(TestPullActions.class.getName());
    implementationService.create(implementationTO);
    PullTaskTO pullTask = taskService.read(TaskType.PULL, AbstractTaskITCase.PULL_TASK_KEY, false);
    assertNotNull(pullTask);
    int before = pullTask.getActions().size();
    pullTask.getActions().add(implementationTO.getKey());
    taskService.update(TaskType.PULL, pullTask);
    pullTask = taskService.read(TaskType.PULL, AbstractTaskITCase.PULL_TASK_KEY, false);
    assertNotNull(pullTask);
    int after = pullTask.getActions().size();
    assertEquals(before + 1, after);
    // fails because the implementation is used
    try {
        implementationService.delete(implementationTO.getType(), implementationTO.getKey());
        fail("Unexpected");
    } catch (SyncopeClientException e) {
        assertEquals(e.getType(), ClientExceptionType.InUse);
    }
    pullTask.getActions().remove(implementationTO.getKey());
    taskService.update(TaskType.PULL, pullTask);
    implementationService.delete(implementationTO.getType(), implementationTO.getKey());
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TestPullActions(org.apache.syncope.fit.core.reference.TestPullActions) Test(org.junit.jupiter.api.Test)

Example 27 with ImplementationTO

use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.

the class ImplementationITCase method create.

@Test
public void create() {
    ImplementationTO implementationTO = new ImplementationTO();
    implementationTO.setKey(UUID.randomUUID().toString());
    implementationTO.setEngine(ImplementationEngine.JAVA);
    implementationTO.setType(ImplementationType.PUSH_ACTIONS);
    implementationTO.setBody(TestPullActions.class.getName());
    // fail because type is wrong
    try {
        implementationService.create(implementationTO);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidImplementation, e.getType());
    }
    implementationTO.setType(ImplementationType.PULL_ACTIONS);
    Response response = implementationService.create(implementationTO);
    if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
        Exception ex = clientFactory.getExceptionMapper().fromResponse(response);
        if (ex != null) {
            throw (RuntimeException) ex;
        }
    }
    ImplementationTO actual = implementationService.read(implementationTO.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    assertNotNull(actual);
    assertEquals(actual, implementationTO);
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TestPullActions(org.apache.syncope.fit.core.reference.TestPullActions) Test(org.junit.jupiter.api.Test)

Example 28 with ImplementationTO

use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.

the class ImplementationServiceImpl method create.

@Override
public Response create(final ImplementationTO implementationTO) {
    ImplementationTO created = logic.create(implementationTO);
    URI location = uriInfo.getAbsolutePathBuilder().path(String.valueOf(created.getKey())).build();
    return Response.created(location).header(RESTHeaders.RESOURCE_KEY, created.getKey()).build();
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) URI(java.net.URI)

Example 29 with ImplementationTO

use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE420.

@Test
public void issueSYNCOPE420() throws IOException {
    ImplementationTO logicActions = new ImplementationTO();
    logicActions.setKey("DoubleValueLogicActions");
    logicActions.setEngine(ImplementationEngine.GROOVY);
    logicActions.setType(ImplementationType.LOGIC_ACTIONS);
    logicActions.setBody(org.apache.commons.io.IOUtils.toString(getClass().getResourceAsStream("/DoubleValueLogicActions.groovy"), StandardCharsets.UTF_8));
    Response response = implementationService.create(logicActions);
    logicActions = implementationService.read(logicActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    assertNotNull(logicActions);
    RealmTO realm = realmService.list("/even/two").iterator().next();
    assertNotNull(realm);
    realm.getActions().add(logicActions.getKey());
    realmService.update(realm);
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope420@syncope.apache.org");
    userTO.setRealm(realm.getFullPath());
    userTO.getPlainAttrs().add(attrTO("makeItDouble", "3"));
    userTO = createUser(userTO).getEntity();
    assertEquals("6", userTO.getPlainAttr("makeItDouble").get().getValues().get(0));
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("makeItDouble", "7"));
    userTO = updateUser(userPatch).getEntity();
    assertEquals("14", userTO.getPlainAttr("makeItDouble").get().getValues().get(0));
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) UserTO(org.apache.syncope.common.lib.to.UserTO) RealmTO(org.apache.syncope.common.lib.to.RealmTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 30 with ImplementationTO

use of org.apache.syncope.common.lib.to.ImplementationTO in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE505LDAP.

@Test
public void issueSYNCOPE505LDAP() throws Exception {
    // 1. create user
    UserTO user = UserITCase.getUniqueSampleTO("syncope505-ldap@syncope.apache.org");
    user.setPassword("security123");
    user = createUser(user).getEntity();
    assertNotNull(user);
    assertTrue(user.getResources().isEmpty());
    // 2. Add LDAPPasswordPropagationActions
    ImplementationTO propagationActions = new ImplementationTO();
    propagationActions.setKey(LDAPPasswordPropagationActions.class.getSimpleName());
    propagationActions.setEngine(ImplementationEngine.JAVA);
    propagationActions.setType(ImplementationType.PROPAGATION_ACTIONS);
    propagationActions.setBody(LDAPPasswordPropagationActions.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_LDAP);
    assertNotNull(resourceTO);
    resourceTO.getPropagationActions().add(propagationActions.getKey());
    resourceTO.setRandomPwdIfNotProvided(false);
    resourceService.update(resourceTO);
    // 3. Add a 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_LDAP).build());
    userPatch.setPassword(new PasswordPatch.Builder().onSyncope(false).resource(RESOURCE_NAME_LDAP).build());
    user = updateUser(userPatch).getEntity();
    assertNotNull(user);
    assertEquals(1, user.getResources().size());
    // 4. Check that the LDAP resource has the correct password
    ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
    assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), "security123", connObject.getAttr(Name.NAME).get().getValues().get(0)));
    // 5. Remove LDAPPasswordPropagationActions
    resourceTO = resourceService.read(RESOURCE_NAME_LDAP);
    assertNotNull(resourceTO);
    resourceTO.getPropagationActions().remove(propagationActions.getKey());
    resourceTO.setRandomPwdIfNotProvided(true);
    resourceService.update(resourceTO);
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) LDAPPasswordPropagationActions(org.apache.syncope.core.provisioning.java.propagation.LDAPPasswordPropagationActions) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) 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