use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class VirAttrITCase method issueSYNCOPE442.
@Test
public void issueSYNCOPE442() {
UserTO userTO = UserITCase.getUniqueSampleTO("syncope442@apache.org");
userTO.getVirAttrs().clear();
AttrTO virAttrTO = new AttrTO();
virAttrTO.setSchema("virtualdata");
virAttrTO.getValues().add("virattrcache");
userTO.getVirAttrs().add(virAttrTO);
userTO.getMemberships().clear();
userTO.getResources().clear();
userTO.getResources().add(RESOURCE_NAME_DBVIRATTR);
// 1. create user
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
// 2. check for virtual attribute value
userTO = userService.read(userTO.getKey());
assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
// ----------------------------------------
// 3. change connector URL so that we are sure that any provided value will come from virtual cache
// ----------------------------------------
String jdbcURL = null;
ConnInstanceTO connInstanceTO = connectorService.readByResource(RESOURCE_NAME_DBVIRATTR, Locale.ENGLISH.getLanguage());
for (ConnConfProperty prop : connInstanceTO.getConf()) {
if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
jdbcURL = prop.getValues().iterator().next().toString();
prop.getValues().clear();
prop.getValues().add("jdbc:h2:tcp://localhost:9092/xxx");
}
}
connectorService.update(connInstanceTO);
// ----------------------------------------
// ----------------------------------------
// 4. update value on external resource
// ----------------------------------------
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
String value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
assertEquals("virattrcache", value);
jdbcTemplate.update("UPDATE testpull set USERNAME='virattrcache2' WHERE ID=?", userTO.getKey());
value = queryForObject(jdbcTemplate, 50, "SELECT USERNAME FROM testpull WHERE ID=?", String.class, userTO.getKey());
assertEquals("virattrcache2", value);
// ----------------------------------------
userTO = userService.read(userTO.getKey());
assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
// ----------------------------------------
for (ConnConfProperty prop : connInstanceTO.getConf()) {
if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
prop.getValues().clear();
prop.getValues().add(jdbcURL);
}
}
connectorService.update(connInstanceTO);
// ----------------------------------------
// cached value still in place...
userTO = userService.read(userTO.getKey());
assertEquals("virattrcache", userTO.getVirAttr("virtualdata").get().getValues().get(0));
// force cache update by adding a resource which has virtualdata mapped for propagation
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS2).build());
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
userTO = userService.read(userTO.getKey());
assertEquals("virattrcache2", userTO.getVirAttr("virtualdata").get().getValues().get(0));
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class VirAttrITCase method issueSYNCOPE691.
@Test
public void issueSYNCOPE691() {
ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
try {
ProvisionTO provision = ldap.getProvision(AnyTypeKind.USER.name()).orElse(null);
assertNotNull(provision);
List<ItemTO> mail = provision.getMapping().getItems().stream().filter(item -> "mail".equals(item.getExtAttrName())).collect(Collectors.toList());
provision.getMapping().getItems().removeAll(mail);
provision.getVirSchemas().clear();
ldap.getProvisions().clear();
ldap.getProvisions().add(provision);
ldap.setKey(RESOURCE_NAME_LDAP + "691" + getUUIDString());
resourceService.create(ldap);
ldap = resourceService.read(ldap.getKey());
provision = ldap.getProvision(AnyTypeKind.USER.name()).get();
assertNotNull(provision);
// create new virtual schema for the resource below
VirSchemaTO virSchema = new VirSchemaTO();
virSchema.setKey("syncope691" + getUUIDString());
virSchema.setExtAttrName("mail");
virSchema.setResource(ldap.getKey());
virSchema.setAnyType(provision.getAnyType());
virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
assertNotNull(virSchema);
AnyTypeClassTO newClass = new AnyTypeClassTO();
newClass.setKey("syncope691" + getUUIDString());
newClass.getVirSchemas().add(virSchema.getKey());
Response response = anyTypeClassService.create(newClass);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
// create a new user
UserTO userTO = UserITCase.getUniqueSampleTO("syncope691@syncope.apache.org");
userTO.getAuxClasses().add(newClass.getKey());
userTO.getResources().clear();
userTO.getMemberships().clear();
userTO.getVirAttrs().clear();
AttrTO emailTO = new AttrTO();
emailTO.setSchema(virSchema.getKey());
emailTO.getValues().add("test@issue691.dom1.org");
emailTO.getValues().add("test@issue691.dom2.org");
userTO.getVirAttrs().add(emailTO);
// assign resource-ldap691 to user
userTO.getResources().add(ldap.getKey());
// save user
userTO = createUser(userTO).getEntity();
// make std controls about user
assertNotNull(userTO);
assertTrue(ldap.getKey().equals(userTO.getResources().iterator().next()));
assertEquals(2, userTO.getVirAttrs().iterator().next().getValues().size());
assertTrue(userTO.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom1.org"));
assertTrue(userTO.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom2.org"));
// update user
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
// modify virtual attribute
userPatch.getVirAttrs().add(new AttrTO.Builder().schema(virSchema.getKey()).value("test@issue691.dom3.org").value("test@issue691.dom4.org").build());
UserTO updated = updateUser(userPatch).getEntity();
assertNotNull(updated);
assertEquals(2, updated.getVirAttrs().iterator().next().getValues().size());
assertTrue(updated.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom3.org"));
assertTrue(updated.getVirAttrs().iterator().next().getValues().contains("test@issue691.dom4.org"));
} finally {
try {
resourceService.delete(ldap.getKey());
} catch (Exception ignore) {
// ignore
}
}
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class VirAttrITCase method issueSYNCOPE397.
@Test
public void issueSYNCOPE397() {
ResourceTO csv = resourceService.read(RESOURCE_NAME_CSV);
// change mapping of resource-csv
MappingTO origMapping = SerializationUtils.clone(csv.getProvisions().get(0).getMapping());
try {
// remove this mapping
Optional<ItemTO> email = csv.getProvisions().get(0).getMapping().getItems().stream().filter(item -> "email".equals(item.getIntAttrName())).findFirst();
if (email.isPresent()) {
csv.getProvisions().get(0).getMapping().getItems().remove(email.get());
}
resourceService.update(csv);
csv = resourceService.read(RESOURCE_NAME_CSV);
assertNotNull(csv.getProvisions().get(0).getMapping());
// create new virtual schema for the resource below
ProvisionTO provision = csv.getProvision(AnyTypeKind.USER.name()).get();
assertNotNull(provision);
VirSchemaTO virSchema = new VirSchemaTO();
virSchema.setKey("syncope397" + getUUIDString());
virSchema.setExtAttrName("email");
virSchema.setResource(RESOURCE_NAME_CSV);
virSchema.setAnyType(provision.getAnyType());
virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
assertNotNull(virSchema);
AnyTypeClassTO newClass = new AnyTypeClassTO();
newClass.setKey("syncope397" + getUUIDString());
newClass.getVirSchemas().add(virSchema.getKey());
Response response = anyTypeClassService.create(newClass);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
// create a new user
UserTO userTO = UserITCase.getUniqueSampleTO("397@syncope.apache.org");
userTO.getAuxClasses().add("csv");
userTO.getAuxClasses().add(newClass.getKey());
userTO.getResources().clear();
userTO.getMemberships().clear();
userTO.getVirAttrs().clear();
userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "test@testone.org"));
// assign resource-csv to user
userTO.getResources().add(RESOURCE_NAME_CSV);
// save user
userTO = createUser(userTO).getEntity();
// make std controls about user
assertNotNull(userTO);
assertTrue(RESOURCE_NAME_CSV.equals(userTO.getResources().iterator().next()));
assertEquals("test@testone.org", userTO.getVirAttrs().iterator().next().getValues().get(0));
// update user
UserTO toBeUpdated = userService.read(userTO.getKey());
UserPatch userPatch = new UserPatch();
userPatch.setKey(toBeUpdated.getKey());
userPatch.setPassword(new PasswordPatch.Builder().value("password234").build());
// assign new resource to user
userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS2).build());
// modify virtual attribute
userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "test@testoneone.com"));
// check Syncope change password
userPatch.setPassword(new PasswordPatch.Builder().value("password234").onSyncope(true).resource(RESOURCE_NAME_WS2).build());
ProvisioningResult<UserTO> result = updateUser(userPatch);
assertNotNull(result);
toBeUpdated = result.getEntity();
assertTrue(toBeUpdated.getVirAttrs().iterator().next().getValues().contains("test@testoneone.com"));
// check if propagates correctly with assertEquals on size of tasks list
assertEquals(2, result.getPropagationStatuses().size());
} finally {
// restore mapping of resource-csv
csv.getProvisions().get(0).setMapping(origMapping);
resourceService.update(csv);
}
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class PropagationTaskITCase method privileges.
@Test
public void privileges() {
ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
ldap.setKey("ldapWithPrivileges");
ItemTO item = new ItemTO();
item.setIntAttrName("privileges[mightyApp]");
item.setExtAttrName("businessCategory");
item.setPurpose(MappingPurpose.PROPAGATION);
ProvisionTO provision = ldap.getProvision(AnyTypeKind.USER.name()).get();
provision.getVirSchemas().clear();
provision.getMapping().add(item);
ldap = createResource(ldap);
try {
UserTO user = UserITCase.getUniqueSampleTO("privilege@syncope.apache.org");
user.getResources().add(ldap.getKey());
user.getRoles().add("Other");
ProvisioningResult<UserTO> result = createUser(user);
assertEquals(1, result.getPropagationStatuses().size());
assertNotNull(result.getPropagationStatuses().get(0).getAfterObj());
AttrTO businessCategory = result.getPropagationStatuses().get(0).getAfterObj().getAttr("businessCategory").orElse(null);
assertNotNull(businessCategory);
assertEquals(1, businessCategory.getValues().size());
assertEquals("postMighty", businessCategory.getValues().get(0));
} finally {
resourceService.delete(ldap.getKey());
}
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class GroupITCase method patch.
@Test
public void patch() {
GroupTO original = getBasicSampleTO("patch");
original.setUDynMembershipCond("(($groups==3;$resources!=ws-target-resource-1);aLong==1)");
original.getADynMembershipConds().put("PRINTER", "(($groups==7;cool==ss);$resources==ws-target-resource-2);$type==PRINTER");
GroupTO updated = createGroup(original).getEntity();
updated.getPlainAttrs().add(new AttrTO.Builder().schema("icon").build());
updated.getPlainAttrs().add(new AttrTO.Builder().schema("show").build());
updated.getPlainAttrs().add(new AttrTO.Builder().schema("rderived_sx").value("sx").build());
updated.getPlainAttrs().add(new AttrTO.Builder().schema("rderived_dx").value("dx").build());
updated.getPlainAttrs().add(new AttrTO.Builder().schema("title").value("mr").build());
original = groupService.read(updated.getKey());
GroupPatch patch = AnyOperations.diff(updated, original, true);
GroupTO group = updateGroup(patch).getEntity();
Map<String, AttrTO> attrs = EntityTOUtils.buildAttrMap(group.getPlainAttrs());
assertFalse(attrs.containsKey("icon"));
assertFalse(attrs.containsKey("show"));
assertEquals(Collections.singletonList("sx"), attrs.get("rderived_sx").getValues());
assertEquals(Collections.singletonList("dx"), attrs.get("rderived_dx").getValues());
assertEquals(Collections.singletonList("mr"), attrs.get("title").getValues());
}
Aggregations