use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class TemplateUtils method check.
public void check(final Map<String, AnyTO> templates, final ClientExceptionType clientExceptionType) {
SyncopeClientException sce = SyncopeClientException.build(clientExceptionType);
templates.values().forEach(value -> {
value.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))).forEachOrdered(attrTO -> {
sce.getElements().add("Invalid JEXL: " + attrTO.getValues().get(0));
});
value.getVirAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))).forEachOrdered((attrTO) -> {
sce.getElements().add("Invalid JEXL: " + attrTO.getValues().get(0));
});
if (value instanceof UserTO) {
UserTO template = (UserTO) value;
if (StringUtils.isNotBlank(template.getUsername()) && !JexlUtils.isExpressionValid(template.getUsername())) {
sce.getElements().add("Invalid JEXL: " + template.getUsername());
}
if (StringUtils.isNotBlank(template.getPassword()) && !JexlUtils.isExpressionValid(template.getPassword())) {
sce.getElements().add("Invalid JEXL: " + template.getPassword());
}
} else if (value instanceof GroupTO) {
GroupTO template = (GroupTO) value;
if (StringUtils.isNotBlank(template.getName()) && !JexlUtils.isExpressionValid(template.getName())) {
sce.getElements().add("Invalid JEXL: " + template.getName());
}
}
});
if (!sce.isEmpty()) {
throw sce;
}
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class ExceptionMapperITCase method sameGroupName.
@Test
public void sameGroupName() {
String groupUUID = getUUIDString();
// Create the first group
GroupTO groupTO1 = new GroupTO();
groupTO1.setName("child1" + groupUUID);
groupTO1.setRealm(SyncopeConstants.ROOT_REALM);
createGroup(groupTO1);
// Create the second group, with the same name of groupTO1
GroupTO groupTO2 = new GroupTO();
groupTO2.setName("child1" + groupUUID);
groupTO2.setRealm(SyncopeConstants.ROOT_REALM);
try {
createGroup(groupTO2);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.EntityExists, e.getType());
String message = ERROR_MESSAGES.getProperty("errMessage.UniqueConstraintViolation");
assertEquals("EntityExists [" + message + "]", e.getMessage());
}
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class GroupITCase method read.
@Test
public void read() {
GroupTO groupTO = groupService.read("37d15e4c-cdc1-460b-a591-8505c8133806");
assertNotNull(groupTO);
assertNotNull(groupTO.getPlainAttrs());
assertFalse(groupTO.getPlainAttrs().isEmpty());
assertEquals(2, groupTO.getStaticUserMembershipCount());
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class GroupITCase method updateAsGroupOwner.
@Test
public void updateAsGroupOwner() {
// 1. read group as admin
GroupTO groupTO = groupService.read("ebf97068-aa4b-4a85-9f01-680e8c4cf227");
// issue SYNCOPE-15
assertNotNull(groupTO.getCreationDate());
assertNotNull(groupTO.getLastChangeDate());
assertEquals("admin", groupTO.getCreator());
assertEquals("admin", groupTO.getLastModifier());
// 2. prepare update
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(groupTO.getKey());
groupPatch.setName(new StringReplacePatchItem.Builder().value("Director").build());
// 3. try to update as verdi, not owner of group 6 - fail
GroupService groupService2 = clientFactory.create("verdi", ADMIN_PWD).getService(GroupService.class);
try {
groupService2.update(groupPatch);
fail("This should not happen");
} catch (ForbiddenException e) {
assertNotNull(e);
}
// 4. update as puccini, owner of group 6 - success
GroupService groupService3 = clientFactory.create("puccini", ADMIN_PWD).getService(GroupService.class);
groupTO = groupService3.update(groupPatch).readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
}).getEntity();
assertEquals("Director", groupTO.getName());
// issue SYNCOPE-15
assertNotNull(groupTO.getCreationDate());
assertNotNull(groupTO.getLastChangeDate());
assertEquals("admin", groupTO.getCreator());
assertEquals("puccini", groupTO.getLastModifier());
assertTrue(groupTO.getCreationDate().before(groupTO.getLastChangeDate()));
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class GroupITCase method issue178.
@Test
public void issue178() {
GroupTO groupTO = new GroupTO();
String groupName = "torename" + getUUIDString();
groupTO.setName(groupName);
groupTO.setRealm("/");
GroupTO actual = createGroup(groupTO).getEntity();
assertNotNull(actual);
assertEquals(groupName, actual.getName());
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(actual.getKey());
String renamedGroup = "renamed" + getUUIDString();
groupPatch.setName(new StringReplacePatchItem.Builder().value(renamedGroup).build());
actual = updateGroup(groupPatch).getEntity();
assertNotNull(actual);
assertEquals(renamedGroup, actual.getName());
}
Aggregations