use of org.apache.syncope.common.lib.to.MappingTO in project syncope by apache.
the class ResourceProvision method setAnyType.
public void setAnyType(final String anyType) {
if (SyncopeConstants.REALM_ANYTYPE.equals(anyType)) {
setOrgUnitTO(new OrgUnitTO());
} else {
setProvisionTO(new ProvisionTO());
getProvisionTO().setAnyType(anyType);
getProvisionTO().setMapping(new MappingTO());
}
}
use of org.apache.syncope.common.lib.to.MappingTO in project syncope by apache.
the class VirAttrITCase method issueSYNCOPE453.
@Test
public void issueSYNCOPE453() {
String resourceName = "issueSYNCOPE453Res" + getUUIDString();
String groupKey = null;
String groupName = "issueSYNCOPE453Group" + getUUIDString();
try {
// -------------------------------------------
// Create a VirAttrITCase ad-hoc
// -------------------------------------------
VirSchemaTO rvirtualdata;
try {
rvirtualdata = schemaService.read(SchemaType.VIRTUAL, "rvirtualdata");
} catch (SyncopeClientException e) {
LOG.warn("rvirtualdata not found, re-creating", e);
rvirtualdata = new VirSchemaTO();
rvirtualdata.setKey("rvirtualdata");
rvirtualdata.setExtAttrName("businessCategory");
rvirtualdata.setResource(RESOURCE_NAME_LDAP);
rvirtualdata.setAnyType(AnyTypeKind.GROUP.name());
rvirtualdata = createSchema(SchemaType.VIRTUAL, rvirtualdata);
}
assertNotNull(rvirtualdata);
if (!"minimal group".equals(rvirtualdata.getAnyTypeClass())) {
LOG.warn("rvirtualdata not in minimal group, restoring");
AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
minimalGroup.getVirSchemas().add(rvirtualdata.getKey());
anyTypeClassService.update(minimalGroup);
rvirtualdata = schemaService.read(SchemaType.VIRTUAL, rvirtualdata.getKey());
assertEquals("minimal group", rvirtualdata.getAnyTypeClass());
}
// -------------------------------------------
// Create a resource ad-hoc
// -------------------------------------------
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey(resourceName);
resourceTO.setConnector("be24b061-019d-4e3e-baf0-0a6d0a45cb9c");
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setIntAttrName("fullname");
item.setExtAttrName("ID");
item.setPurpose(MappingPurpose.PROPAGATION);
item.setConnObjectKey(true);
mapping.setConnObjectKeyItem(item);
item = new ItemTO();
item.setIntAttrName("username");
item.setExtAttrName("USERNAME");
item.setPurpose(MappingPurpose.PROPAGATION);
mapping.getItems().add(item);
item = new ItemTO();
item.setIntAttrName("groups[" + groupName + "].rvirtualdata");
item.setExtAttrName("EMAIL");
item.setPurpose(MappingPurpose.PROPAGATION);
mapping.getItems().add(item);
assertNotNull(getObject(resourceService.create(resourceTO).getLocation(), ResourceService.class, ResourceTO.class));
// -------------------------------------------
GroupTO groupTO = new GroupTO();
groupTO.setName(groupName);
groupTO.setRealm("/");
groupTO.getVirAttrs().add(attrTO(rvirtualdata.getKey(), "ml@group.it"));
groupTO.getResources().add(RESOURCE_NAME_LDAP);
groupTO = createGroup(groupTO).getEntity();
groupKey = groupTO.getKey();
assertEquals(1, groupTO.getVirAttrs().size());
assertEquals("ml@group.it", groupTO.getVirAttrs().iterator().next().getValues().get(0));
// -------------------------------------------
// -------------------------------------------
// Create new user
// -------------------------------------------
UserTO userTO = UserITCase.getUniqueSampleTO("syn453@syncope.apache.org");
userTO.getPlainAttrs().add(attrTO("fullname", "123"));
userTO.getResources().clear();
userTO.getResources().add(resourceName);
userTO.getVirAttrs().clear();
userTO.getMemberships().clear();
userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
ProvisioningResult<UserTO> result = createUser(userTO);
assertEquals(2, result.getPropagationStatuses().size());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(1).getStatus());
userTO = result.getEntity();
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
Map<String, Object> actuals = jdbcTemplate.queryForMap("SELECT id, surname, email FROM testpull WHERE id=?", new Object[] { userTO.getPlainAttr("fullname").get().getValues().get(0) });
assertEquals(userTO.getPlainAttr("fullname").get().getValues().get(0), actuals.get("id").toString());
assertEquals("ml@group.it", actuals.get("email"));
// -------------------------------------------
} catch (Exception e) {
LOG.error("Unexpected error", e);
} finally {
// -------------------------------------------
// Delete resource and group ad-hoc
// -------------------------------------------
resourceService.delete(resourceName);
if (groupKey != null) {
groupService.delete(groupKey);
}
// -------------------------------------------
}
}
use of org.apache.syncope.common.lib.to.MappingTO 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.MappingTO in project syncope by apache.
the class ResourceITCase method issueSYNCOPE493.
@Test
public void issueSYNCOPE493() {
// create resource with attribute mapping set to NONE and check its propagation
String resourceKey = RESOURCE_NAME_CREATE_NONE;
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey(resourceKey);
resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setIntAttrName("key");
item.setExtAttrName("userId");
item.setConnObjectKey(true);
item.setPurpose(MappingPurpose.PROPAGATION);
mapping.setConnObjectKeyItem(item);
ItemTO item2 = new ItemTO();
item2.setConnObjectKey(false);
item2.setIntAttrName("gender");
item2.setExtAttrName("gender");
item2.setPurpose(MappingPurpose.NONE);
mapping.add(item2);
Response response = resourceService.create(resourceTO);
ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
assertNotNull(actual);
assertNotNull(actual.getProvision(AnyTypeKind.USER.name()).get().getMapping());
assertNotNull(actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getItems());
assertEquals(MappingPurpose.PROPAGATION, actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getConnObjectKeyItem().getPurpose());
actual.getProvision(AnyTypeKind.USER.name()).get().getMapping().getItems().stream().filter(itemTO -> ("gender".equals(itemTO.getIntAttrName()))).forEach(itemTO -> assertEquals(MappingPurpose.NONE, itemTO.getPurpose()));
}
use of org.apache.syncope.common.lib.to.MappingTO in project syncope by apache.
the class ResourceITCase method createWithInvalidMapping.
@Test
public void createWithInvalidMapping() {
String resourceKey = RESOURCE_NAME_CREATE_WRONG;
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey(resourceKey);
resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setIntAttrName("key");
item.setExtAttrName("userId");
item.setConnObjectKey(true);
mapping.setConnObjectKeyItem(item);
item = new ItemTO();
item.setExtAttrName("email");
// missing intAttrName ...
mapping.add(item);
try {
createResource(resourceTO);
fail("Create should not have worked");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
assertEquals("intAttrName", e.getElements().iterator().next());
}
}
Aggregations