use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class UserITCase method updateWithoutPassword.
@Test
public void updateWithoutPassword() {
UserTO userTO = getUniqueSampleTO("updatewithout@password.com");
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.DELETE).attrTO(new AttrTO.Builder().schema("ctype").build()).build());
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
assertFalse(userTO.getPlainAttr("ctype").isPresent());
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class UserITCase method update.
@Test
public void update() {
UserTO userTO = getUniqueSampleTO("g.h@t.com");
userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
userTO = createUser(userTO).getEntity();
assertFalse(userTO.getDerAttrs().isEmpty());
assertEquals(1, userTO.getMemberships().size());
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.setPassword(new PasswordPatch.Builder().value("new2Password").build());
String newUserId = getUUIDString() + "t.w@spre.net";
userPatch.getPlainAttrs().add(attrAddReplacePatch("userId", newUserId));
String newFullName = getUUIDString() + "g.h@t.com";
userPatch.getPlainAttrs().add(attrAddReplacePatch("fullname", newFullName));
userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(userTO.getMemberships().get(0).getGroupKey()).build());
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
// issue SYNCOPE-15
assertNotNull(userTO.getCreationDate());
assertNotNull(userTO.getCreator());
assertNotNull(userTO.getLastChangeDate());
assertNotNull(userTO.getLastModifier());
assertTrue(userTO.getCreationDate().before(userTO.getLastChangeDate()));
assertEquals(1, userTO.getMemberships().size());
assertFalse(userTO.getDerAttrs().isEmpty());
AttrTO userIdAttr = userTO.getPlainAttr("userId").get();
assertEquals(Collections.singletonList(newUserId), userIdAttr.getValues());
AttrTO fullNameAttr = userTO.getPlainAttr("fullname").get();
assertEquals(Collections.singletonList(newFullName), fullNameAttr.getValues());
// update by username
userPatch = new UserPatch();
userPatch.setKey(userTO.getUsername());
String newUsername = UUID.randomUUID().toString();
userPatch.setUsername(new StringReplacePatchItem.Builder().value(newUsername).build());
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
assertEquals(newUsername, userTO.getUsername());
}
use of org.apache.syncope.common.lib.to.AttrTO 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.AttrTO in project syncope by apache.
the class TemplateUtils method fill.
private void fill(final AnyTO anyTO, final AnyTO template) {
MapContext jexlContext = new MapContext();
JexlUtils.addFieldsToContext(anyTO, jexlContext);
JexlUtils.addAttrTOsToContext(anyTO.getPlainAttrs(), jexlContext);
JexlUtils.addAttrTOsToContext(anyTO.getDerAttrs(), jexlContext);
JexlUtils.addAttrTOsToContext(anyTO.getVirAttrs(), jexlContext);
if (template.getRealm() != null) {
String evaluated = JexlUtils.evaluate(template.getRealm(), jexlContext);
if (StringUtils.isNotBlank(evaluated)) {
anyTO.setRealm(evaluated);
}
}
Map<String, AttrTO> currentAttrMap = EntityTOUtils.buildAttrMap(anyTO.getPlainAttrs());
for (AttrTO templatePlainAttr : template.getPlainAttrs()) {
if (!templatePlainAttr.getValues().isEmpty() && (!currentAttrMap.containsKey(templatePlainAttr.getSchema()) || currentAttrMap.get(templatePlainAttr.getSchema()).getValues().isEmpty())) {
AttrTO evaluated = evaluateAttr(templatePlainAttr, jexlContext);
if (!evaluated.getValues().isEmpty()) {
anyTO.getPlainAttrs().add(evaluated);
jexlContext.set(evaluated.getSchema(), evaluated.getValues().get(0));
}
}
}
currentAttrMap = EntityTOUtils.buildAttrMap(anyTO.getDerAttrs());
for (AttrTO templateDerAttr : template.getDerAttrs()) {
if (!currentAttrMap.containsKey(templateDerAttr.getSchema())) {
anyTO.getDerAttrs().add(templateDerAttr);
}
}
currentAttrMap = EntityTOUtils.buildAttrMap(anyTO.getVirAttrs());
for (AttrTO templateVirAttr : template.getVirAttrs()) {
if (!templateVirAttr.getValues().isEmpty() && (!currentAttrMap.containsKey(templateVirAttr.getSchema()) || currentAttrMap.get(templateVirAttr.getSchema()).getValues().isEmpty())) {
AttrTO evaluated = evaluateAttr(templateVirAttr, jexlContext);
if (!evaluated.getValues().isEmpty()) {
anyTO.getVirAttrs().add(evaluated);
jexlContext.set(evaluated.getSchema(), evaluated.getValues().get(0));
}
}
}
anyTO.getResources().addAll(template.getResources());
anyTO.getAuxClasses().addAll(template.getAuxClasses());
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class TemplateUtils method evaluateAttr.
private AttrTO evaluateAttr(final AttrTO template, final MapContext jexlContext) {
AttrTO result = new AttrTO();
result.setSchema(template.getSchema());
if (template.getValues() != null && !template.getValues().isEmpty()) {
template.getValues().forEach(value -> {
String evaluated = JexlUtils.evaluate(value, jexlContext);
if (StringUtils.isNotBlank(evaluated)) {
result.getValues().add(evaluated);
}
});
}
return result;
}
Aggregations