use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class Scim2UserService method transferAttributesToUserResource.
public void transferAttributesToUserResource(GluuCustomPerson person, UserResource res, String url) {
log.debug("transferAttributesToUserResource");
res.setId(person.getInum());
res.setExternalId(person.getAttribute("oxTrustExternalId"));
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
meta.setCreated(person.getAttribute("oxTrustMetaCreated"));
if (meta.getCreated() == null) {
Date tmpDate = person.getCreationDate();
meta.setCreated(tmpDate == null ? null : ISODateTimeFormat.dateTime().withZoneUTC().print(tmpDate.getTime()));
}
meta.setLastModified(person.getAttribute("oxTrustMetaLastModified"));
if (meta.getLastModified() == null) {
Date tmpDate = person.getUpdatedAt();
meta.setLastModified(tmpDate == null ? null : ISODateTimeFormat.dateTime().withZoneUTC().print(tmpDate.getTime()));
}
meta.setLocation(person.getAttribute("oxTrustMetaLocation"));
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("oxTrusthonorificPrefix"));
name.setHonorificSuffix(person.getAttribute("oxTrusthonorificSuffix"));
String formatted = person.getAttribute("oxTrustNameFormatted");
if (// recomputes the formatted name if absent in LDAP
formatted == null)
name.computeFormattedName();
else
name.setFormatted(formatted);
res.setName(name);
res.setDisplayName(person.getDisplayName());
res.setNickName(person.getAttribute("nickname"));
res.setProfileUrl(person.getAttribute("oxTrustProfileURL"));
res.setTitle(person.getAttribute("oxTrustTitle"));
res.setUserType(person.getAttribute("oxTrustUserType"));
res.setPreferredLanguage(person.getPreferredLanguage());
res.setLocale(person.getAttribute("locale"));
res.setTimezone(person.getTimezone());
res.setActive(Boolean.valueOf(person.getAttribute("oxTrustActive")) || GluuBoolean.getByValue(person.getAttribute("gluuStatus")).isBooleanValue());
res.setPassword(person.getUserPassword());
res.setEmails(getAttributeListValue(person, Email.class, "oxTrustEmail"));
res.setPhoneNumbers(getAttributeListValue(person, PhoneNumber.class, "oxTrustPhoneValue"));
res.setIms(getAttributeListValue(person, InstantMessagingAddress.class, "oxTrustImsValue"));
res.setPhotos(getAttributeListValue(person, Photo.class, "oxTrustPhotos"));
res.setAddresses(getAttributeListValue(person, Address.class, "oxTrustAddresses"));
List<String> listOfGroups = person.getMemberOf();
if (listOfGroups != null && listOfGroups.size() > 0) {
List<Group> groupList = new ArrayList<Group>();
for (String groupDN : listOfGroups) {
try {
GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
Group group = new Group();
group.setValue(gluuGroup.getInum());
String reference = groupWS.getEndpointUrl() + "/" + 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, "oxTrustEntitlements"));
res.setRoles(getAttributeListValue(person, Role.class, "oxTrustRole"));
res.setX509Certificates(getAttributeListValue(person, X509Certificate.class, "oxTrustx509Certificate"));
res.setPairwiseIdentitifers(person.getOxPPID());
transferExtendedAttributesToResource(person, res);
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebServiceDecorator method validateExistenceOfGroup.
private Response validateExistenceOfGroup(String id) {
Response response = null;
GluuGroup group = StringUtils.isEmpty(id) ? null : groupService.getGroupByInum(id);
if (group == null) {
log.info("Group with inum {} not found", id);
response = getErrorResponse(Response.Status.NOT_FOUND, "Resource " + id + " not found");
}
return response;
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebServiceDecorator method checkDisplayNameExistence.
private void checkDisplayNameExistence(String displayName, String id) throws DuplicateEntryException {
// Validate if there is an attempt to supply a displayName already in use by a group other than current
GluuGroup groupToFind = new GluuGroup();
groupToFind.setDisplayName(displayName);
List<GluuGroup> list = groupService.findGroups(groupToFind, 2);
if (list != null) {
for (GluuGroup g : list) if (!g.getInum().equals(id))
throw new DuplicateEntryException("Duplicate group displayName value: " + displayName);
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class ServiceUtil method groupMembersAdder.
/**
* Adds a person to a group
*
* @return void
* @throws Exception
*/
public void groupMembersAdder(GluuCustomPerson gluuPerson, String dn) throws Exception {
List<String> groups = gluuPerson.getMemberOf();
for (String group : groups) {
GluuGroup oneGroup = groupService.getGroupByDn(group);
List<String> groupMembers = oneGroup.getMembers();
if ((groupMembers != null && !groupMembers.isEmpty()) && !isMemberExist(groupMembers, dn)) {
List<String> cleanGroupMembers = new ArrayList<String>();
cleanGroupMembers.add(dn);
for (String personDN : groupMembers) {
cleanGroupMembers.add(personDN);
}
oneGroup.setMembers(cleanGroupMembers);
groupService.updateGroup(oneGroup);
}
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebService method deleteGroup.
@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
@ApiOperation(value = "Delete group", notes = "Delete group (https://tools.ietf.org/html/rfc7644#section-3.6)")
public Response deleteGroup(@PathParam("id") String id) {
Response response;
try {
log.debug("Executing web service method. deleteGroup");
// group cannot be null (check associated decorator method)
GluuGroup gr = groupService.getGroupByInum(id);
scim2GroupService.deleteGroup(gr);
response = Response.noContent().build();
} catch (Exception e) {
log.error("Failure at deleteGroup method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
Aggregations