Search in sources :

Example 6 with SyncopeClientException

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

the class UserITCase method createWithRequiredValueMissing.

@Test
public void createWithRequiredValueMissing() {
    UserTO userTO = getUniqueSampleTO("a.b@c.it");
    AttrTO type = userTO.getPlainAttr("ctype").get();
    userTO.getPlainAttrs().remove(type);
    userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
    // 1. create user without type (mandatory by UserSchema)
    try {
        createUser(userTO);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
    }
    userTO.getPlainAttrs().add(attrTO("ctype", "F"));
    AttrTO surname = userTO.getPlainAttr("surname").get();
    userTO.getPlainAttrs().remove(surname);
    // 2. create user without surname (mandatory when type == 'F')
    try {
        createUser(userTO);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 7 with SyncopeClientException

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

the class UserITCase method create.

@Test
public void create() {
    // get task list
    PagedResult<PropagationTaskTO> tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    assertNotNull(tasks);
    assertFalse(tasks.getResult().isEmpty());
    String maxKey = tasks.getResult().iterator().next().getKey();
    PropagationTaskTO taskTO = taskService.read(TaskType.PROPAGATION, maxKey, true);
    assertNotNull(taskTO);
    int maxTaskExecutions = taskTO.getExecutions().size();
    UserTO userTO = getUniqueSampleTO("a.b@c.com");
    // add a membership
    userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
    // add an attribute with a non-existing schema: must be ignored
    AttrTO attrWithInvalidSchemaTO = attrTO("invalid schema", "a value");
    userTO.getPlainAttrs().add(attrWithInvalidSchemaTO);
    // add an attribute with null value: must be ignored
    userTO.getPlainAttrs().add(attrTO("activationDate", null));
    // 1. create user
    UserTO newUserTO = createUser(userTO).getEntity();
    assertNotNull(newUserTO);
    // issue SYNCOPE-15
    assertNotNull(newUserTO.getCreationDate());
    assertNotNull(newUserTO.getCreator());
    assertNotNull(newUserTO.getLastChangeDate());
    assertNotNull(newUserTO.getLastModifier());
    assertEquals(newUserTO.getCreationDate(), newUserTO.getLastChangeDate());
    assertFalse(newUserTO.getPlainAttrs().contains(attrWithInvalidSchemaTO));
    // check for changePwdDate
    assertNotNull(newUserTO.getCreationDate());
    // get the new task list
    tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
    assertNotNull(tasks);
    assertFalse(tasks.getResult().isEmpty());
    String newMaxKey = tasks.getResult().iterator().next().getKey();
    // default configuration for ws-target-resource2:
    // only failed executions have to be registered
    // --> no more tasks/executions should be added
    assertEquals(newMaxKey, maxKey);
    // get last task
    taskTO = taskService.read(TaskType.PROPAGATION, newMaxKey, true);
    assertNotNull(taskTO);
    assertEquals(maxTaskExecutions, taskTO.getExecutions().size());
    // 3. verify password
    try {
        Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(newUserTO.getUsername(), "password123").self();
        assertNotNull(self);
    } catch (AccessControlException e) {
        fail("Credentials should be valid and not cause AccessControlException");
    }
    try {
        clientFactory.create(newUserTO.getUsername(), "passwordXX").getService(UserSelfService.class);
        fail("Credentials are invalid, thus request should raise AccessControlException");
    } catch (AccessControlException e) {
        assertNotNull(e);
    }
    // 4. try (and fail) to create another user with same (unique) values
    userTO = getSampleTO(userTO.getUsername());
    AttrTO userIdAttr = userTO.getPlainAttr("userId").get();
    userIdAttr.getValues().clear();
    userIdAttr.getValues().add("a.b@c.com");
    try {
        createUser(userTO);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.EntityExists, e.getType());
    }
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AccessControlException(java.security.AccessControlException) UserTO(org.apache.syncope.common.lib.to.UserTO) TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 8 with SyncopeClientException

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

the class UserIssuesITCase method issue288.

@Test
public void issue288() {
    UserTO userTO = UserITCase.getSampleTO("issue288@syncope.apache.org");
    userTO.getPlainAttrs().add(attrTO("aLong", "STRING"));
    try {
        createUser(userTO);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidValues, e.getType());
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 9 with SyncopeClientException

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

the class UserIssuesITCase method issueSYNCOPE357.

@Test
public void issueSYNCOPE357() throws IOException {
    // 1. create group with LDAP resource
    GroupTO groupTO = new GroupTO();
    groupTO.setName("SYNCOPE357-" + getUUIDString());
    groupTO.setRealm("/");
    groupTO.getResources().add(RESOURCE_NAME_LDAP);
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    // 2. create user with membership of the above group
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope357@syncope.apache.org");
    userTO.getPlainAttrs().add(attrTO("obscure", "valueToBeObscured"));
    userTO.getPlainAttrs().add(attrTO("photo", Base64.getEncoder().encodeToString(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/favicon.jpg")))));
    userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
    userTO = createUser(userTO).getEntity();
    assertTrue(userTO.getResources().contains(RESOURCE_NAME_LDAP));
    assertNotNull(userTO.getPlainAttr("obscure"));
    assertNotNull(userTO.getPlainAttr("photo"));
    // 3. read user on resource
    ConnObjectTO connObj = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(connObj);
    AttrTO registeredAddress = connObj.getAttr("registeredAddress").get();
    assertNotNull(registeredAddress);
    assertEquals(userTO.getPlainAttr("obscure").get().getValues(), registeredAddress.getValues());
    Optional<AttrTO> jpegPhoto = connObj.getAttr("jpegPhoto");
    assertTrue(jpegPhoto.isPresent());
    assertEquals(userTO.getPlainAttr("photo").get().getValues().get(0), jpegPhoto.get().getValues().get(0));
    // 4. remove group
    groupService.delete(groupTO.getKey());
    // 5. try to read user on resource: fail
    try {
        resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 10 with SyncopeClientException

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

the class UserIssuesITCase method issueSYNCOPE185.

@Test
public void issueSYNCOPE185() {
    // 1. create user with LDAP resource, succesfully propagated
    UserTO userTO = UserITCase.getSampleTO("syncope185@syncope.apache.org");
    userTO.getVirAttrs().clear();
    userTO.getResources().add(RESOURCE_NAME_LDAP);
    ProvisioningResult<UserTO> result = createUser(userTO);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_LDAP, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    // 2. delete this user
    userService.delete(userTO.getKey());
    // 3. try (and fail) to find this user on the external LDAP resource
    try {
        resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
        fail("This entry should not be present on this resource");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) 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