use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class PullTaskITCase method issueSYNCOPE1062.
@Test
public void issueSYNCOPE1062() {
GroupTO propagationGroup = null;
PullTaskTO pullTask = null;
UserTO user = null;
GroupTO group = null;
try {
// 1. create group with resource for propagation
propagationGroup = GroupITCase.getBasicSampleTO("SYNCOPE1062");
propagationGroup.getResources().add(RESOURCE_NAME_DBPULL);
propagationGroup = createGroup(propagationGroup).getEntity();
// 2. create pull task for another resource, with user template assigning the group above
pullTask = new PullTaskTO();
pullTask.setDestinationRealm(SyncopeConstants.ROOT_REALM);
pullTask.setName("SYNCOPE1062");
pullTask.setActive(true);
pullTask.setPerformCreate(true);
pullTask.setPerformUpdate(true);
pullTask.setPullMode(PullMode.FULL_RECONCILIATION);
pullTask.setResource(RESOURCE_NAME_LDAP);
UserTO template = new UserTO();
template.getAuxClasses().add("minimal group");
template.getMemberships().add(new MembershipTO.Builder().group(propagationGroup.getKey()).build());
template.getPlainAttrs().add(attrTO("firstname", "'fixed'"));
pullTask.getTemplates().put(AnyTypeKind.USER.name(), template);
Response taskResponse = taskService.create(TaskType.PULL, pullTask);
pullTask = getObject(taskResponse.getLocation(), TaskService.class, PullTaskTO.class);
assertNotNull(pullTask);
assertFalse(pullTask.getTemplates().isEmpty());
// 3. exec the pull task
ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// the user is successfully pulled...
user = userService.read("pullFromLDAP");
assertNotNull(user);
assertEquals("pullFromLDAP@syncope.apache.org", user.getPlainAttr("email").get().getValues().get(0));
group = groupService.read("testLDAPGroup");
assertNotNull(group);
ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
assertNotNull(connObject);
assertEquals("pullFromLDAP@syncope.apache.org", connObject.getAttr("mail").get().getValues().get(0));
AttrTO userDn = connObject.getAttr(Name.NAME).get();
assertNotNull(userDn);
assertEquals(1, userDn.getValues().size());
assertNotNull(getLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0)));
// ...and propagated
PagedResult<TaskTO> propagationTasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).resource(RESOURCE_NAME_DBPULL).anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
assertEquals(1, propagationTasks.getSize());
// 4. update the user on the external resource
updateLdapRemoteObject(RESOURCE_LDAP_ADMIN_DN, RESOURCE_LDAP_ADMIN_PWD, userDn.getValues().get(0), Pair.of("mail", "pullFromLDAP2@syncope.apache.org"));
connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
assertNotNull(connObject);
assertEquals("pullFromLDAP2@syncope.apache.org", connObject.getAttr("mail").get().getValues().get(0));
// 5. exec the pull task again
execution = execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// the internal is updated...
user = userService.read("pullFromLDAP");
assertNotNull(user);
assertEquals("pullFromLDAP2@syncope.apache.org", user.getPlainAttr("email").get().getValues().get(0));
// ...and propagated
propagationTasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).resource(RESOURCE_NAME_DBPULL).anyTypeKind(AnyTypeKind.USER).entityKey(user.getKey()).build());
assertEquals(2, propagationTasks.getSize());
} catch (Exception e) {
LOG.error("Unexpected during issueSYNCOPE1062()", e);
fail(e.getMessage());
} finally {
if (pullTask != null) {
taskService.delete(TaskType.PULL, pullTask.getKey());
}
if (propagationGroup != null) {
groupService.delete(propagationGroup.getKey());
}
if (group != null) {
groupService.delete(group.getKey());
}
if (user != null) {
userService.delete(user.getKey());
}
}
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class PullTaskITCase method create.
@Test
public void create() {
PullTaskTO task = new PullTaskTO();
task.setName("Test create Pull");
task.setDestinationRealm("/");
task.setResource(RESOURCE_NAME_WS2);
task.setPullMode(PullMode.FULL_RECONCILIATION);
UserTO userTemplate = new UserTO();
userTemplate.getResources().add(RESOURCE_NAME_WS2);
userTemplate.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
task.getTemplates().put(AnyTypeKind.USER.name(), userTemplate);
GroupTO groupTemplate = new GroupTO();
groupTemplate.getResources().add(RESOURCE_NAME_LDAP);
task.getTemplates().put(AnyTypeKind.GROUP.name(), groupTemplate);
Response response = taskService.create(TaskType.PULL, task);
PullTaskTO actual = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
assertNotNull(actual);
task = taskService.read(TaskType.PULL, actual.getKey(), true);
assertNotNull(task);
assertEquals(actual.getKey(), task.getKey());
assertEquals(actual.getJobDelegate(), task.getJobDelegate());
assertEquals(userTemplate, task.getTemplates().get(AnyTypeKind.USER.name()));
assertEquals(groupTemplate, task.getTemplates().get(AnyTypeKind.GROUP.name()));
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class GroupReportlet method doExtract.
private void doExtract(final ContentHandler handler, final List<Group> groups) throws SAXException {
AttributesImpl atts = new AttributesImpl();
for (Group group : groups) {
atts.clear();
for (Feature feature : conf.getFeatures()) {
String type = null;
String value = null;
switch(feature) {
case key:
type = ReportXMLConst.XSD_STRING;
value = group.getKey();
break;
case name:
type = ReportXMLConst.XSD_STRING;
value = String.valueOf(group.getName());
break;
case groupOwner:
type = ReportXMLConst.XSD_STRING;
value = group.getGroupOwner().getKey();
break;
case userOwner:
type = ReportXMLConst.XSD_STRING;
value = group.getUserOwner().getKey();
break;
default:
}
if (type != null && value != null) {
atts.addAttribute("", "", feature.name(), type, value);
}
}
handler.startElement("", "", "group", atts);
// Using GroupTO for attribute values, since the conversion logic of
// values to String is already encapsulated there
GroupTO groupTO = groupDataBinder.getGroupTO(group, true);
doExtractAttributes(handler, groupTO, conf.getPlainAttrs(), conf.getDerAttrs(), conf.getVirAttrs());
// to get resources associated to a group
if (conf.getFeatures().contains(Feature.resources)) {
doExtractResources(handler, groupTO);
}
// to get users asscoiated to a group is preferred GroupDAO to GroupTO
if (conf.getFeatures().contains(Feature.users)) {
handler.startElement("", "", "users", null);
for (UMembership memb : groupDAO.findUMemberships(group)) {
atts.clear();
atts.addAttribute("", "", "key", ReportXMLConst.XSD_STRING, memb.getLeftEnd().getKey());
atts.addAttribute("", "", "username", ReportXMLConst.XSD_STRING, String.valueOf(memb.getLeftEnd().getUsername()));
handler.startElement("", "", "user", atts);
handler.endElement("", "", "user");
}
handler.endElement("", "", "users");
}
handler.endElement("", "", "group");
}
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class SearchITCase method searchByDynGroup.
@Test
public void searchByDynGroup() {
GroupTO group = GroupITCase.getBasicSampleTO("dynMembership");
group.setUDynMembershipCond("cool==true");
group = createGroup(group).getEntity();
assertNotNull(group);
if (ElasticsearchDetector.isElasticSearchEnabled(syncopeService)) {
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
// ignore
}
}
PagedResult<UserTO> matchingUsers = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(group.getKey()).query()).build());
assertNotNull(matchingUsers);
assertFalse(matchingUsers.getResult().isEmpty());
assertTrue(matchingUsers.getResult().stream().anyMatch(user -> "c9b2dec2-00a7-4855-97c0-d854842b4b24".equals(user.getKey())));
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class PullTaskITCase method reconcileFromLDAP.
@Test
public void reconcileFromLDAP() {
// First of all, clear any potential conflict with existing user / group
ldapCleanup();
// 0. pull
ExecTO execution = execProvisioningTask(taskService, TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", 50, false);
// 1. verify execution status
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// 2. verify that pulled group is found
PagedResult<GroupTO> matchingGroups = groupService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getGroupSearchConditionBuilder().is("name").equalTo("testLDAPGroup").query()).build());
assertNotNull(matchingGroups);
assertEquals(1, matchingGroups.getResult().size());
// SYNCOPE-898
PullTaskTO task = taskService.read(TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", false);
assertEquals("/", task.getDestinationRealm());
assertEquals("/", matchingGroups.getResult().get(0).getRealm());
// 3. verify that pulled user is found
PagedResult<UserTO> matchingUsers = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()).build());
assertNotNull(matchingUsers);
assertEquals(1, matchingUsers.getResult().size());
// SYNCOPE-898
assertEquals("/odd", matchingUsers.getResult().get(0).getRealm());
// Check for SYNCOPE-436
assertEquals("pullFromLDAP", matchingUsers.getResult().get(0).getVirAttr("virtualReadOnly").get().getValues().get(0));
// Check for SYNCOPE-270
assertNotNull(matchingUsers.getResult().get(0).getPlainAttr("obscure"));
// Check for SYNCOPE-123
assertNotNull(matchingUsers.getResult().get(0).getPlainAttr("photo"));
GroupTO groupTO = matchingGroups.getResult().iterator().next();
assertNotNull(groupTO);
assertEquals("testLDAPGroup", groupTO.getName());
assertEquals("true", groupTO.getPlainAttr("show").get().getValues().get(0));
assertEquals(matchingUsers.getResult().iterator().next().getKey(), groupTO.getUserOwner());
assertNull(groupTO.getGroupOwner());
// SYNCOPE-317
execProvisioningTask(taskService, TaskType.PULL, "1e419ca4-ea81-4493-a14f-28b90113686d", 50, false);
// 4. verify that LDAP group membership is propagated as Syncope membership
int i = 0;
int maxit = 50;
PagedResult<UserTO> members;
do {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
members = userService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(groupTO.getKey()).query()).build());
assertNotNull(members);
i++;
} while (members.getResult().isEmpty() && i < maxit);
if (i == maxit) {
fail("Timeout while checking for memberships of " + groupTO.getName());
}
assertEquals(1, members.getResult().size());
}
Aggregations