use of io.jans.scim.model.scim.ScimCustomPerson in project jans by JanssenProject.
the class Scim2UserService method transferAttributesToUserResource.
public void transferAttributesToUserResource(ScimCustomPerson person, UserResource res, String url) {
log.debug("transferAttributesToUserResource");
res.setId(person.getInum());
res.setExternalId(person.getAttribute("jansExtId"));
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
meta.setCreated(person.getAttribute("jansMetaCreated"));
if (meta.getCreated() == null) {
Date date = person.getCreationDate();
meta.setCreated(date == null ? null : DateUtil.millisToISOString(date.getTime()));
}
meta.setLastModified(person.getAttribute("jansMetaLastMod"));
if (meta.getLastModified() == null) {
Date date = person.getUpdatedAt();
meta.setLastModified(date == null ? null : DateUtil.millisToISOString(date.getTime()));
}
meta.setLocation(person.getAttribute("jansMetaLocation"));
if (meta.getLocation() == null) {
meta.setLocation(url + "/" + person.getInum());
}
res.setMeta(meta);
// Set values in order of appearance in UserResource class
res.setUserName(person.getUid());
Name name = new Name();
name.setGivenName(person.getGivenName());
name.setFamilyName(person.getSurname());
name.setMiddleName(person.getAttribute("middleName"));
name.setHonorificPrefix(person.getAttribute("jansHonorificPrefix"));
name.setHonorificSuffix(person.getAttribute("jansHonorificSuffix"));
String formatted = person.getAttribute("jansNameFormatted");
if (formatted == null) {
// recomputes the formatted name if absent in LDAP
name.computeFormattedName();
} else {
name.setFormatted(formatted);
}
res.setName(name);
res.setDisplayName(person.getDisplayName());
res.setNickName(person.getAttribute("nickname"));
res.setProfileUrl(person.getAttribute("jansProfileURL"));
res.setTitle(person.getAttribute("jansTitle"));
res.setUserType(person.getAttribute("jansUsrTyp"));
res.setPreferredLanguage(person.getPreferredLanguage());
res.setLocale(person.getAttribute("locale"));
res.setTimezone(person.getTimezone());
res.setActive(Boolean.valueOf(person.getAttribute("jansActive")) || GluuBoolean.getByValue(person.getAttribute("jansStatus")).isBooleanValue());
res.setPassword(person.getUserPassword());
res.setEmails(getAttributeListValue(person, Email.class, "jansEmail"));
if (res.getEmails() == null) {
// There can be cases where jansEmail is not synced with mail attribute....
List<Email> emails = person.getAttributeList("mail").stream().map(m -> {
Email email = new Email();
email.setValue(m);
email.setPrimary(false);
return email;
}).collect(Collectors.toList());
res.setEmails(emails.size() == 0 ? null : emails);
}
res.setPhoneNumbers(getAttributeListValue(person, PhoneNumber.class, "jansPhoneValue"));
res.setIms(getAttributeListValue(person, InstantMessagingAddress.class, "jansImsValue"));
res.setPhotos(getAttributeListValue(person, Photo.class, "jansPhotos"));
res.setAddresses(getAttributeListValue(person, Address.class, "jansAddres"));
List<String> listOfGroups = person.getMemberOf();
if (listOfGroups != null && listOfGroups.size() > 0) {
List<Group> groupList = new ArrayList<>();
for (String groupDN : listOfGroups) {
try {
GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
Group group = new Group();
group.setValue(gluuGroup.getInum());
String reference = groupEndpointUrl + "/" + gluuGroup.getInum();
group.setRef(reference);
group.setDisplay(gluuGroup.getDisplayName());
// Only support direct membership: see section 4.1.2 of RFC 7644
group.setType(Group.Type.DIRECT);
groupList.add(group);
} catch (Exception e) {
log.warn("transferAttributesToUserResource. Group with dn {} could not be added to User Resource. {}", groupDN, person.getUid());
log.error(e.getMessage(), e);
}
}
if (groupList.size() > 0) {
res.setGroups(groupList);
}
}
res.setEntitlements(getAttributeListValue(person, Entitlement.class, "jansEntitlements"));
res.setRoles(getAttributeListValue(person, Role.class, "jansRole"));
res.setX509Certificates(getAttributeListValue(person, X509Certificate.class, "jansx509Certificate"));
res.setPairwiseIdentifiers(person.getPpid());
transferExtendedAttributesToResource(person, res);
}
use of io.jans.scim.model.scim.ScimCustomPerson in project jans by JanssenProject.
the class Scim2UserService method preCreateUser.
public ScimCustomPerson preCreateUser(UserResource user) {
log.info("Preparing to create user {}", user.getUserName());
// There is no need to check attributes mutability in this case as there are no
// original attributes (the resource does not exist yet)
ScimCustomPerson gluuPerson = new ScimCustomPerson();
transferAttributesToPerson(user, gluuPerson);
assignComputedAttributesToPerson(gluuPerson);
return gluuPerson;
}
use of io.jans.scim.model.scim.ScimCustomPerson in project jans by JanssenProject.
the class UserPersistenceHelper method removeUserFromGroups.
/**
* "Detaches" a person from all groups he is currently member of
* @param person The person in question
* @throws Exception
*/
public void removeUserFromGroups(ScimCustomPerson person) {
String dn = person.getDn();
List<String> groups = person.getMemberOf();
for (String oneGroup : groups) {
try {
GluuGroup aGroup = groupService.getGroupByDn(oneGroup);
List<String> groupMembers = aGroup.getMembers();
int idx = Optional.ofNullable(groupMembers).map(l -> l.indexOf(dn)).orElse(-1);
if (idx >= 0) {
List<String> newMembers = new ArrayList<>();
newMembers.addAll(groupMembers.subList(0, idx));
newMembers.addAll(groupMembers.subList(idx + 1, groupMembers.size()));
aGroup.setMembers(newMembers.isEmpty() ? null : newMembers);
groupService.updateGroup(aGroup);
}
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
use of io.jans.scim.model.scim.ScimCustomPerson in project jans by JanssenProject.
the class Scim2UserService method searchUsers.
public PagedResult<BaseScimResource> searchUsers(String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String url, int maxCount) throws Exception {
Filter ldapFilter = scimFilterParserService.createFilter(filter, Filter.createPresenceFilter("inum"), UserResource.class);
log.info("Executing search for users using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
PagedResult<ScimCustomPerson> list = ldapEntryManager.findPagedEntries(personService.getDnForPerson(null), ScimCustomPerson.class, ldapFilter, null, sortBy, sortOrder, startIndex - 1, count, maxCount);
List<BaseScimResource> resources = new ArrayList<>();
if (externalScimService.isEnabled() && !externalScimService.executeScimPostSearchUsersMethods(list)) {
throw new WebApplicationException("Failed to execute SCIM script successfully", Status.PRECONDITION_FAILED);
}
for (ScimCustomPerson person : list.getEntries()) {
UserResource scimUsr = new UserResource();
transferAttributesToUserResource(person, scimUsr, url);
resources.add(scimUsr);
}
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.scim.ScimCustomPerson in project jans by JanssenProject.
the class UserWebService method deleteUser.
@Path("{id}")
@DELETE
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi(scopes = { "https://jans.io/scim/users.write" })
public Response deleteUser(@PathParam("id") String id) {
Response response;
try {
log.debug("Executing web service method. deleteUser");
ScimCustomPerson person = userPersistenceHelper.getPersonByInum(id);
if (person == null)
return notFoundResponse(id, userResourceType);
response = externalConstraintsService.applyEntityCheck(person, null, httpHeaders, uriInfo, HttpMethod.DELETE, userResourceType);
if (response != null)
return response;
scim2UserService.deleteUser(person);
response = Response.noContent().build();
} catch (Exception e) {
log.error("Failure at deleteUser method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
Aggregations