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());
}
}
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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations