use of io.jans.scim.model.GluuCustomPerson in project jans by JanssenProject.
the class BaseScimWebService method validateExistenceOfUser.
public Response validateExistenceOfUser(String id) {
Response response = null;
if (StringUtils.isNotEmpty(id)) {
GluuCustomPerson person = personService.getPersonByInum(id);
if (person == null) {
log.info("Person with inum {} not found", id);
response = getErrorResponse(Response.Status.NOT_FOUND, "User with id " + id + " not found");
}
}
return response;
}
use of io.jans.scim.model.GluuCustomPerson in project jans by JanssenProject.
the class Scim2GroupService method transferAttributesToGroup.
private void transferAttributesToGroup(GroupResource res, GluuGroup group, boolean skipMembersValidation, boolean fillMembersDisplay, String usersUrl) {
// externalId (so jansExtId) not part of LDAP schema
group.setAttribute("jansMetaCreated", res.getMeta().getCreated());
group.setAttribute("jansMetaLastMod", res.getMeta().getLastModified());
// When creating group, location will be set again when having an inum
group.setAttribute("jansMetaLocation", res.getMeta().getLocation());
group.setDisplayName(res.getDisplayName());
group.setStatus(GluuStatus.ACTIVE);
group.setOrganization(organizationService.getDnForOrganization());
Set<Member> members = res.getMembers();
if (members != null && members.size() > 0) {
Set<String> groupMembers = group.getMembers().stream().map(userPersistenceHelper::getUserInumFromDN).collect(Collectors.toCollection(HashSet::new));
List<String> listMembers = new ArrayList<>();
List<Member> invalidMembers = new ArrayList<>();
// Add the members, and complement the $refs and users' display names in res
for (Member member : members) {
GluuCustomPerson person;
// it's not null as it is required in GroupResource
String inum = member.getValue();
// we make database lookups
if (!skipMembersValidation && !groupMembers.contains(inum)) {
person = personService.getPersonByInum(inum);
if (person != null && fillMembersDisplay) {
member.setDisplay(person.getDisplayName());
}
} else {
person = new GluuCustomPerson();
person.setDn(personService.getDnForPerson(inum));
}
if (person == null) {
log.info("Member identified by {} does not exist. Ignored", inum);
invalidMembers.add(member);
} else {
member.setRef(usersUrl + "/" + inum);
member.setType(ScimResourceUtil.getType(UserResource.class));
if (skipMembersValidation) {
// In overhead bypass mode, display names must not be returned
member.setDisplay(null);
}
listMembers.add(person.getDn());
}
}
group.setMembers(listMembers);
members.removeAll(invalidMembers);
if (members.isEmpty()) {
res.setMembers(null);
}
} else {
group.setMembers(new ArrayList<>());
}
}
use of io.jans.scim.model.GluuCustomPerson 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.GluuCustomPerson in project jans by JanssenProject.
the class Scim2GroupService method syncMemberAttributeInPerson.
private void syncMemberAttributeInPerson(String groupDn, Set<String> before, Set<String> after) {
log.debug("syncMemberAttributeInPerson. Updating memberOf attribute in user LDAP entries");
log.trace("Before member dns {}; After member dns {}", before, after);
// Do removals
for (String dn : before) {
if (!after.contains(dn)) {
try {
GluuCustomPerson gluuPerson = personService.getPersonByDn(dn);
List<String> memberOf = new ArrayList<>();
memberOf.addAll(gluuPerson.getMemberOf());
memberOf.remove(groupDn);
gluuPerson.setMemberOf(memberOf);
personService.updatePerson(gluuPerson);
} catch (Exception e) {
log.error("An error occurred while removing group {} from user {}", groupDn, dn);
log.error(e.getMessage(), e);
}
}
}
// Do insertions
for (String dn : after) {
if (!before.contains(dn)) {
try {
GluuCustomPerson gluuPerson = personService.getPersonByDn(dn);
List<String> memberOf = new ArrayList<>();
memberOf.add(groupDn);
if (gluuPerson.getMemberOf() != null)
memberOf.addAll(gluuPerson.getMemberOf());
gluuPerson.setMemberOf(memberOf);
personService.updatePerson(gluuPerson);
} catch (Exception e) {
log.error("An error occurred while adding group {} to user {}", groupDn, dn);
log.error(e.getMessage(), e);
}
}
}
}
use of io.jans.scim.model.GluuCustomPerson in project jans by JanssenProject.
the class PersonService method searchPersons.
public List<GluuCustomPerson> searchPersons(String pattern, int sizeLimit, List<GluuCustomPerson> excludedPersons) throws Exception {
Filter orFilter = buildFilter(pattern);
Filter searchFilter = orFilter;
if (excludedPersons != null && excludedPersons.size() > 0) {
List<Filter> excludeFilters = new ArrayList<Filter>();
for (GluuCustomPerson excludedPerson : excludedPersons) {
Filter eqFilter = Filter.createEqualityFilter(OxConstants.UID, excludedPerson.getUid());
excludeFilters.add(eqFilter);
}
Filter orExcludeFilter = null;
if (excludedPersons.size() == 1) {
orExcludeFilter = excludeFilters.get(0);
} else {
orExcludeFilter = Filter.createORFilter(excludeFilters);
}
Filter notFilter = Filter.createNOTFilter(orExcludeFilter);
searchFilter = Filter.createANDFilter(orFilter, notFilter);
}
return persistenceEntryManager.findEntries(getDnForPerson(null), GluuCustomPerson.class, searchFilter, sizeLimit);
}
Aggregations