use of io.jans.scim.model.scim2.group.GroupResource in project jans by JanssenProject.
the class Scim2GroupService method transferAttributesToGroupResource.
public void transferAttributesToGroupResource(GluuGroup gluuGroup, GroupResource res, boolean fillMembersDisplay, String groupsUrl, String usersUrl) {
res.setId(gluuGroup.getInum());
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
meta.setCreated(gluuGroup.getAttribute("jansMetaCreated"));
meta.setLastModified(gluuGroup.getAttribute("jansMetaLastMod"));
meta.setLocation(gluuGroup.getAttribute("jansMetaLocation"));
if (meta.getLocation() == null)
meta.setLocation(groupsUrl + "/" + gluuGroup.getInum());
res.setMeta(meta);
res.setDisplayName(gluuGroup.getDisplayName());
// Transfer members from GluuGroup to GroupResource
List<String> memberDNs = gluuGroup.getMembers();
if (memberDNs != null) {
Set<Member> members = new HashSet<>();
for (String dn : memberDNs) {
GluuCustomPerson person = null;
if (fillMembersDisplay) {
try {
person = personService.getPersonByDn(dn);
} catch (Exception e) {
log.warn("Wrong member entry {} found in group {}", dn, gluuGroup.getDisplayName());
}
}
if (person == null) {
person = new GluuCustomPerson();
person.setInum(userPersistenceHelper.getUserInumFromDN(dn));
}
Member aMember = new Member();
aMember.setValue(person.getInum());
aMember.setRef(usersUrl + "/" + person.getInum());
aMember.setType(ScimResourceUtil.getType(UserResource.class));
aMember.setDisplay(person.getDisplayName());
members.add(aMember);
}
res.setMembers(members);
}
}
use of io.jans.scim.model.scim2.group.GroupResource in project jans by JanssenProject.
the class Scim2GroupService method searchGroups.
public PagedResult<BaseScimResource> searchGroups(String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String groupsUrl, String usersUrl, int maxCount, boolean fillMembersDisplay) throws Exception {
Filter ldapFilter = scimFilterParserService.createFilter(filter, Filter.createPresenceFilter("inum"), GroupResource.class);
log.info("Executing search for groups using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
PagedResult<GluuGroup> list = ldapEntryManager.findPagedEntries(groupService.getDnForGroup(null), GluuGroup.class, ldapFilter, null, sortBy, sortOrder, startIndex - 1, count, maxCount);
List<BaseScimResource> resources = new ArrayList<>();
if (externalScimService.isEnabled() && !externalScimService.executeScimPostSearchGroupsMethods(list)) {
throw new WebApplicationException("Failed to execute SCIM script successfully", Status.PRECONDITION_FAILED);
}
for (GluuGroup group : list.getEntries()) {
GroupResource scimGroup = new GroupResource();
transferAttributesToGroupResource(group, scimGroup, fillMembersDisplay, groupsUrl, usersUrl);
resources.add(scimGroup);
}
log.info("Found {} matching entries - returning {}", list.getTotalEntriesCount(), list.getEntries().size());
PagedResult<BaseScimResource> result = new PagedResult<>();
result.setEntries(resources);
result.setTotalEntriesCount(list.getTotalEntriesCount());
return result;
}
use of io.jans.scim.model.scim2.group.GroupResource in project jans by JanssenProject.
the class GroupAssignUserTest method assignToGroup.
@Test(dependsOnMethods = "createUsers")
public void assignToGroup() {
Set<Member> buddies = friends.stream().map(buddy -> {
Member m = new Member();
m.setValue(buddy.getId());
m.setDisplay(buddy.getDisplayName());
return m;
}).collect(Collectors.toSet());
GroupResource gr = new GroupResource();
gr.setDisplayName("3 best demented buddies");
gr.setMembers(buddies);
logger.info("Assigning users to new group...");
Response response = client.createGroup(gr, null, null);
assertEquals(response.getStatus(), CREATED.getStatusCode());
group = response.readEntity(GroupResource.class);
// Verify the sanitarium is completely booked
assertTrue(group.getMembers().stream().map(Member::getValue).collect(Collectors.toSet()).equals(friends.stream().map(UserResource::getId).collect(Collectors.toSet())));
}
use of io.jans.scim.model.scim2.group.GroupResource in project jans by JanssenProject.
the class MinimalGroupTest method updateGroup.
@Parameters("group_minimal_update")
@Test(dependsOnMethods = "createGroup")
public void updateGroup(String json) {
logger.debug("Updating group {} with json", group.getDisplayName());
Response response = client.updateGroup(json, group.getId(), null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
GroupResource updated = response.readEntity(groupClass);
assertNotEquals(group.getDisplayName(), updated.getDisplayName());
// Impl. ignores externalId for groups
assertNull(updated.getExternalId());
logger.debug("Updated group {}", updated.getDisplayName());
}
use of io.jans.scim.model.scim2.group.GroupResource in project oxTrust by GluuFederation.
the class BulkWebService method execute.
private Pair<Response, String> execute(Verb verb, BaseScimWebService ws, String data, String fragment) {
Response response = null;
String idCreated = null;
try {
if (ws == userWS)
switch(verb) {
case PUT:
UserResource user = mapper.readValue(data, UserResource.class);
response = userWS.updateUser(user, fragment, "id", null);
break;
case DELETE:
response = userWS.deleteUser(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = userWS.patchUser(pr, fragment, "id", null);
break;
case POST:
user = mapper.readValue(data, UserResource.class);
response = userWS.createUser(user, "id", null);
if (CREATED.getStatusCode() == response.getStatus()) {
user = mapper.readValue(response.getEntity().toString(), UserResource.class);
idCreated = user.getId();
}
break;
}
else if (ws == groupWS)
switch(verb) {
case PUT:
GroupResource group = mapper.readValue(data, GroupResource.class);
response = groupWS.updateGroup(group, fragment, "id", null);
break;
case DELETE:
response = groupWS.deleteGroup(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = groupWS.patchGroup(pr, fragment, "id", null);
break;
case POST:
group = mapper.readValue(data, GroupResource.class);
response = groupWS.createGroup(group, "id", null);
if (CREATED.getStatusCode() == response.getStatus()) {
group = mapper.readValue(response.getEntity().toString(), GroupResource.class);
idCreated = group.getId();
}
break;
}
else if (ws == fidoDeviceWS)
switch(verb) {
case PUT:
FidoDeviceResource dev = mapper.readValue(data, FidoDeviceResource.class);
response = fidoDeviceWS.updateDevice(dev, fragment, "id", null);
break;
case DELETE:
response = fidoDeviceWS.deleteDevice(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = fidoDeviceWS.patchDevice(pr, fragment, "id", null);
break;
case POST:
response = fidoDeviceWS.createDevice();
break;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return new Pair<Response, String>(response, idCreated);
}
Aggregations