Search in sources :

Example 31 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class ExceptionMapperITCase method invalidRequests.

@Test
public void invalidRequests() {
    try {
        taskService.search(new TaskQuery.Builder(TaskType.NOTIFICATION).resource(RESOURCE_NAME_LDAP).build());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidRequest, e.getType());
    }
    try {
        taskService.search(new TaskQuery.Builder(TaskType.PULL).anyTypeKind(AnyTypeKind.ANY_OBJECT).build());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidRequest, e.getType());
    }
    try {
        taskService.search(new TaskQuery.Builder(TaskType.PULL).notification("e00945b5-1184-4d43-8e45-4318a8dcdfd4").build());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidRequest, e.getType());
    }
    try {
        anyTypeService.delete(AnyTypeKind.USER.name());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidRequest, e.getType());
    }
    try {
        clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).getService(AccessTokenService.class).login();
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidRequest, e.getType());
    }
    try {
        ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
        ItemTO mapping = ldap.getProvisions().get(0).getMapping().getItems().get(0);
        mapping.setIntAttrName("memberships.cn");
        resourceService.update(ldap);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidMapping, e.getType());
    }
}
Also used : AccessTokenService(org.apache.syncope.common.rest.api.service.AccessTokenService) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Example 32 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class GroupITCase method selfRead.

@Test
public void selfRead() {
    UserTO userTO = userService.read("1417acbe-cbf6-4277-9372-e75e04f97000");
    assertNotNull(userTO);
    assertTrue(userTO.getMembership("37d15e4c-cdc1-460b-a591-8505c8133806").isPresent());
    assertFalse(userTO.getMembership("29f96485-729e-4d31-88a1-6fc60e4677f3").isPresent());
    GroupService groupService2 = clientFactory.create("rossini", ADMIN_PWD).getService(GroupService.class);
    try {
        groupService2.read("29f96485-729e-4d31-88a1-6fc60e4677f3");
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
    }
    List<GroupTO> groups = groupService2.own();
    assertNotNull(groups);
    assertTrue(groups.stream().anyMatch(group -> "37d15e4c-cdc1-460b-a591-8505c8133806".equals(group.getKey())));
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NamingException(javax.naming.NamingException) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ResourceDeassociationAction(org.apache.syncope.common.lib.types.ResourceDeassociationAction) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AttrSchemaType(org.apache.syncope.common.lib.types.AttrSchemaType) Map(java.util.Map) PagedResult(org.apache.syncope.common.lib.to.PagedResult) ExecTO(org.apache.syncope.common.lib.to.ExecTO) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) MappingTO(org.apache.syncope.common.lib.to.MappingTO) SchemaType(org.apache.syncope.common.lib.types.SchemaType) UUID(java.util.UUID) GroupTO(org.apache.syncope.common.lib.to.GroupTO) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) List(java.util.List) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) Response(javax.ws.rs.core.Response) DeassociationPatch(org.apache.syncope.common.lib.patch.DeassociationPatch) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AccessControlException(java.security.AccessControlException) NamingEnumeration(javax.naming.NamingEnumeration) TaskJob(org.apache.syncope.core.provisioning.java.job.TaskJob) SearchResult(javax.naming.directory.SearchResult) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AnonymousAuthenticationHandler(org.apache.syncope.client.lib.AnonymousAuthenticationHandler) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) AttrTO(org.apache.syncope.common.lib.to.AttrTO) GroupService(org.apache.syncope.common.rest.api.service.GroupService) SyncopeService(org.apache.syncope.common.rest.api.service.SyncopeService) BulkMembersActionType(org.apache.syncope.common.lib.types.BulkMembersActionType) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) EntityTOUtils(org.apache.syncope.common.lib.EntityTOUtils) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) SerializationUtils(org.apache.commons.lang3.SerializationUtils) SearchControls(javax.naming.directory.SearchControls) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AssociationPatch(org.apache.syncope.common.lib.patch.AssociationPatch) ItemTO(org.apache.syncope.common.lib.to.ItemTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AbstractITCase(org.apache.syncope.fit.AbstractITCase) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) ForbiddenException(javax.ws.rs.ForbiddenException) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ResourceAssociationAction(org.apache.syncope.common.lib.types.ResourceAssociationAction) DirContext(javax.naming.directory.DirContext) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ConnectorCapability(org.apache.syncope.common.lib.types.ConnectorCapability) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ConnInstanceTO(org.apache.syncope.common.lib.to.ConnInstanceTO) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) Collections(java.util.Collections) AnyOperations(org.apache.syncope.common.lib.AnyOperations) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) TaskType(org.apache.syncope.common.lib.types.TaskType) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) GroupService(org.apache.syncope.common.rest.api.service.GroupService) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 33 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException 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) + "...");
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) PullPolicyTO(org.apache.syncope.common.lib.policy.PullPolicyTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 34 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class RealmITCase method createUpdate.

@Test
public void createUpdate() {
    final RealmTO realm = new RealmTO();
    realm.setName("last");
    // 1. create
    Response response = realmService.create("/even/two", realm);
    RealmTO[] actuals = getObject(response.getLocation(), RealmService.class, RealmTO[].class);
    assertNotNull(actuals);
    assertTrue(actuals.length > 0);
    RealmTO actual = actuals[0];
    assertNotNull(actual.getKey());
    assertEquals("last", actual.getName());
    assertEquals("/even/two/last", actual.getFullPath());
    assertEquals(actual.getParent(), getRealm("/even/two").get().getKey());
    assertNull(realm.getAccountPolicy());
    assertNull(realm.getPasswordPolicy());
    // 2. update setting policies
    actual.setAccountPolicy("06e2ed52-6966-44aa-a177-a0ca7434201f");
    actual.setPasswordPolicy("986d1236-3ac5-4a19-810c-5ab21d79cba1");
    realmService.update(actual);
    actual = getRealm(actual.getFullPath()).get();
    assertNotNull(actual.getAccountPolicy());
    assertNotNull(actual.getPasswordPolicy());
    // 3. update changing parent
    actual.setParent(getRealm("/odd").get().getKey());
    realmService.update(actual);
    actual = getRealm("/odd/last").get();
    assertNotNull(actual);
    assertEquals("/odd/last", actual.getFullPath());
    assertEquals(1, realmService.list().stream().filter(object -> realm.getName().equals(object.getName())).count());
    // 4. create under invalid path
    try {
        realmService.create("a name", realm);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidPath, e.getType());
    }
    // 5. attempt to create duplicate
    try {
        realmService.create("/odd", realm);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.EntityExists, e.getType());
    }
}
Also used : Response(javax.ws.rs.core.Response) RealmTO(org.apache.syncope.common.lib.to.RealmTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 35 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class ReportITCase method executeAndExport.

@Test
public void executeAndExport() throws IOException {
    ReportTO reportTO = reportService.read("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
    reportTO.setKey(null);
    reportTO.setName("executeAndExport" + getUUIDString());
    reportTO.setActive(false);
    reportTO.getExecutions().clear();
    reportTO = createReport(reportTO);
    assertNotNull(reportTO);
    try {
        execReport(reportTO.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.Scheduling, e.getType());
        assertTrue(e.getElements().iterator().next().contains("active"));
    }
    reportTO.setActive(true);
    reportService.update(reportTO);
    String execKey = execReport(reportTO.getKey());
    checkExport(execKey, ReportExecExportFormat.XML);
    checkExport(execKey, ReportExecExportFormat.HTML);
    checkExport(execKey, ReportExecExportFormat.PDF);
    checkExport(execKey, ReportExecExportFormat.RTF);
    checkExport(execKey, ReportExecExportFormat.CSV);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ReportTO(org.apache.syncope.common.lib.to.ReportTO) Test(org.junit.jupiter.api.Test)

Aggregations

SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)240 Test (org.junit.jupiter.api.Test)105 UserTO (org.apache.syncope.common.lib.to.UserTO)50 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)40 Response (javax.ws.rs.core.Response)34 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)20 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)19 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)18 Realm (org.apache.syncope.core.persistence.api.entity.Realm)18 GroupTO (org.apache.syncope.common.lib.to.GroupTO)17 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)16 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 Map (java.util.Map)14 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 ItemTO (org.apache.syncope.common.lib.to.ItemTO)12 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)11