use of org.gluu.oxtrust.model.scim2.Group in project oxTrust by GluuFederation.
the class GroupWebService method searchGroups.
@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search groups", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchGroups(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
Response authorizationResponse;
if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
log.info(" ##### SCIM Test Mode is ACTIVE");
authorizationResponse = processTestModeAuthorization(token);
} else {
authorizationResponse = processAuthorization(authorization);
}
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
if (count > getMaxCount()) {
String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.TOO_MANY, detail);
} else {
log.info(" Searching groups from LDAP ");
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuGroup> groupList = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
// List<GluuGroup> groupList = groupService.getAllGroupsList();
ListResponse groupsListResponse = new ListResponse();
List<String> schema = new ArrayList<String>();
schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
log.info(" setting schema");
groupsListResponse.setSchemas(schema);
// Set total
groupsListResponse.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && groupList != null && !groupList.isEmpty()) {
for (GluuGroup gluuGroup : groupList) {
Group group = copyUtils2.copy(gluuGroup, null);
log.info(" group to be added displayName : " + group.getDisplayName());
groupsListResponse.getResources().add(group);
log.info(" group added? : " + groupsListResponse.getResources().contains(group));
}
// Set the rest of results info
groupsListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
groupsListResponse.setStartIndex(vlvResponse.getStartIndex());
}
// Serialize to JSON
String json = serializeToJson(groupsListResponse, attributesArray);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Groups");
return Response.ok(json).location(location).build();
}
} catch (Exception ex) {
log.error("Error in searchGroups", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of org.gluu.oxtrust.model.scim2.Group in project oxTrust by GluuFederation.
the class GroupWebService method createGroup.
@POST
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Create group", notes = "Create group (https://tools.ietf.org/html/rfc7644#section-3.3)", response = Group.class)
public Response createGroup(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "Group", required = true) Group group, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
Response authorizationResponse;
if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
log.info(" ##### SCIM Test Mode is ACTIVE");
authorizationResponse = processTestModeAuthorization(token);
} else {
authorizationResponse = processAuthorization(authorization);
}
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
Group createdGroup = scim2GroupService.createGroup(group);
// Serialize to JSON
String json = serializeToJson(createdGroup, attributesArray);
URI location = new URI(createdGroup.getMeta().getLocation());
// Return HTTP response with status code 201 Created
return Response.created(location).entity(json).build();
} catch (DuplicateEntryException ex) {
log.error("DuplicateEntryException", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
} catch (Exception ex) {
log.error("Failed to create group", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of org.gluu.oxtrust.model.scim2.Group in project oxTrust by GluuFederation.
the class ResourceTypeWS method getResourceTypeGroup.
@Path("Group")
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response getResourceTypeGroup(@HeaderParam("Authorization") String authorization) throws Exception {
ResourceType groupResourceType = new ResourceType();
groupResourceType.setDescription(Constants.GROUP_CORE_SCHEMA_DESCRIPTION);
groupResourceType.setEndpoint("/v2/Groups");
groupResourceType.setName(Constants.GROUP_CORE_SCHEMA_NAME);
groupResourceType.setId(Constants.GROUP_CORE_SCHEMA_NAME);
groupResourceType.setSchema(Constants.GROUP_CORE_SCHEMA_ID);
Meta groupMeta = new Meta();
groupMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/Group");
groupMeta.setResourceType("ResourceType");
groupResourceType.setMeta(groupMeta);
// ResourceType[] resourceTypes = new ResourceType[]{groupResourceType};
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/Group");
// return Response.ok(resourceTypes).location(location).build();
return Response.ok(groupResourceType).location(location).build();
}
use of org.gluu.oxtrust.model.scim2.Group in project oxTrust by GluuFederation.
the class Scim2GroupService method transferAttributesToGroup.
private void transferAttributesToGroup(GroupResource res, GluuGroup group, String usersUrl) {
// externalId (so oxTrustExternalId) not part of LDAP schema
group.setAttribute("oxTrustMetaCreated", res.getMeta().getCreated());
group.setAttribute("oxTrustMetaLastModified", res.getMeta().getLastModified());
// When creating group, location will be set again when having an inum
group.setAttribute("oxTrustMetaLocation", res.getMeta().getLocation());
group.setDisplayName(res.getDisplayName());
group.setStatus(GluuStatus.ACTIVE);
group.setOrganization(organizationService.getDnForOrganization());
// Add the members, and complement the $refs and users' display names in res
Set<Member> members = res.getMembers();
if (members != null && members.size() > 0) {
List<String> listMembers = new ArrayList<String>();
for (Member member : members) {
// it's not null as it is required in GroupResource
String inum = member.getValue();
GluuCustomPerson person = personService.getPersonByInum(inum);
if (person == null)
log.info("Member identified by {} does not exist. Ignored", inum);
else {
member.setDisplay(person.getDisplayName());
member.setRef(usersUrl + "/" + inum);
member.setType(ScimResourceUtil.getType(UserResource.class));
listMembers.add(person.getDn());
}
}
group.setMembers(listMembers);
}
}
use of org.gluu.oxtrust.model.scim2.Group 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);
}
Aggregations