use of org.gluu.oxtrust.model.scim2.user.Group in project oxTrust by GluuFederation.
the class BulkWebService method processGroupOperation.
private BulkOperation processGroupOperation(BulkOperation operation, Map<String, String> processedBulkIds) throws Exception {
log.info(" Operation is for Group ");
// Intercept bulkId
Group group = null;
if (operation.getData() != null) {
// Required in a request when
// "method" is "POST", "PUT", or
// "PATCH".
String serializedData = serialize(operation.getData());
for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
String key = "bulkId:" + entry.getKey();
serializedData = serializedData.replaceAll(key, entry.getValue());
}
group = deserializeToGroup(serializedData);
}
String groupRootEndpoint = appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/";
if (operation.getMethod().equalsIgnoreCase(HttpMethod.POST)) {
log.info(" Method is POST ");
try {
group = scim2GroupService.createGroup(group);
GluuGroup gluuGroup = groupService.getGroupByDisplayName(group.getDisplayName());
String id = gluuGroup.getInum();
// String location = (new
// StringBuilder()).append(domain).append("/Groups/").append(id).toString();
String location = groupRootEndpoint + id;
operation.setLocation(location);
operation.setStatus(String.valueOf(Response.Status.CREATED.getStatusCode()));
operation.setResponse(group);
// Set aside successfully-processed bulkId
// bulkId is only required in POST
processedBulkIds.put(operation.getBulkId(), group.getId());
} catch (DuplicateEntryException ex) {
log.error("DuplicateEntryException", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
} catch (Exception ex) {
log.error("Failed to create group", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
}
} else if (operation.getMethod().equalsIgnoreCase(HttpMethod.PUT)) {
log.info(" Method is PUT ");
String path = operation.getPath();
String id = getId(path);
for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
String key = "bulkId:" + entry.getKey();
if (id.equalsIgnoreCase(key)) {
id = id.replaceAll(key, entry.getValue());
break;
}
}
try {
group = scim2GroupService.updateGroup(id, group);
// String location = (new
// StringBuilder()).append(domain).append("/Groups/").append(groupiD).toString();
String location = groupRootEndpoint + id;
operation.setLocation(location);
operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
operation.setResponse(group);
// bulkId is only required in POST
if (operation.getBulkId() != null) {
processedBulkIds.put(operation.getBulkId(), group.getId());
}
} catch (EntryPersistenceException ex) {
log.error("Failed to update group", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found"));
} catch (DuplicateEntryException ex) {
log.error("DuplicateEntryException", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
} catch (Exception ex) {
log.error("Failed to update group", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
}
} else if (operation.getMethod().equalsIgnoreCase(HttpMethod.DELETE)) {
log.info(" Method is DELETE ");
String path = operation.getPath();
String id = getId(path);
for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
String key = "bulkId:" + entry.getKey();
if (id.equalsIgnoreCase(key)) {
id = id.replaceAll(key, entry.getValue());
break;
}
}
try {
scim2GroupService.deleteGroup(id);
// Location may be omitted on DELETE
operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
operation.setResponse("Group " + id + " deleted");
// bulkId is only required in POST
if (operation.getBulkId() != null) {
processedBulkIds.put(operation.getBulkId(), id);
}
} catch (EntryPersistenceException ex) {
log.error("Failed to delete group", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, null, "Resource " + id + " not found"));
} catch (Exception ex) {
log.error("Failed to delete group", ex);
ex.printStackTrace();
operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
}
}
return operation;
}
use of org.gluu.oxtrust.model.scim2.user.Group in project oxTrust by GluuFederation.
the class SchemaTypeUserSerializer method serialize.
@Override
public void serialize(User user, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
log.info(" serialize() ");
try {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
JsonNode rootNode = mapper.convertValue(user, JsonNode.class);
Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
while (iterator.hasNext()) {
Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
if (!(SchemaTypeMapping.getSchemaTypeInstance(rootNodeEntry.getKey()) instanceof UserExtensionSchema)) {
if (rootNodeEntry.getValue() instanceof ObjectNode) {
if (rootNodeEntry.getKey().equalsIgnoreCase("name")) {
AttributeHolder attributeHolder = new AttributeHolder();
attributeHolder.setName(rootNodeEntry.getKey());
attributeHolder.setType("string");
attributeHolder.setDescription("Name object");
attributeHolder.setRequired(Boolean.FALSE);
List<AttributeHolder> nameAttributeHolders = new ArrayList<AttributeHolder>();
Iterator<Map.Entry<String, JsonNode>> nameIterator = rootNodeEntry.getValue().getFields();
while (nameIterator.hasNext()) {
Map.Entry<String, JsonNode> nameRootNodeEntry = nameIterator.next();
AttributeHolder nameAttributeHolder = new AttributeHolder();
nameAttributeHolder.setName(nameRootNodeEntry.getKey());
nameAttributeHolder.setType("string");
if (nameRootNodeEntry.getKey().equalsIgnoreCase("formatted")) {
nameAttributeHolder.setDescription("Formatted name on-the-fly for display. Using this in a query filter is not supported.");
nameAttributeHolder.setMutability("readOnly");
} else {
nameAttributeHolder.setDescription(nameRootNodeEntry.getKey());
}
if (nameRootNodeEntry.getKey().equalsIgnoreCase("givenName") || nameRootNodeEntry.getKey().equalsIgnoreCase("familyName")) {
nameAttributeHolder.setRequired(true);
} else {
nameAttributeHolder.setRequired(false);
}
nameAttributeHolders.add(nameAttributeHolder);
}
attributeHolder.setSubAttributes(nameAttributeHolders);
attributeHolders.add(attributeHolder);
}
} else if (rootNodeEntry.getValue() instanceof ArrayNode) {
AttributeHolder arrayNodeAttributeHolder = new AttributeHolder();
arrayNodeAttributeHolder.setName(rootNodeEntry.getKey());
if (rootNodeEntry.getKey().equalsIgnoreCase("groups")) {
arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list; using sub-attributes in a query filter is not supported (cross-querying)");
arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
List<String> referenceTypes = new ArrayList<String>();
referenceTypes.add("Group");
arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
} else {
arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list");
arrayNodeAttributeHolder.setCaseExact(Boolean.FALSE);
}
arrayNodeAttributeHolder.setRequired(Boolean.FALSE);
arrayNodeAttributeHolder.setMultiValued(Boolean.TRUE);
if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {
arrayNodeAttributeHolder.setUniqueness("server");
arrayNodeAttributeHolder.setType("string");
arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
arrayNodeAttributeHolder.setReturned("always");
} else {
arrayNodeAttributeHolder.setType("complex");
}
if (rootNodeEntry.getKey().equalsIgnoreCase("photos")) {
arrayNodeAttributeHolder.setType("reference");
List<String> referenceTypes = new ArrayList<String>();
referenceTypes.add("uri");
arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
}
List<AttributeHolder> arrayNodeMapAttributeHolders = new ArrayList<AttributeHolder>();
Iterator<JsonNode> arrayNodeIterator = rootNodeEntry.getValue().getElements();
while (arrayNodeIterator.hasNext()) {
JsonNode jsonNode = arrayNodeIterator.next();
Iterator<Map.Entry<String, JsonNode>> arrayNodeMapIterator = jsonNode.getFields();
while (arrayNodeMapIterator.hasNext()) {
Map.Entry<String, JsonNode> arrayNodeMapRootNodeEntry = arrayNodeMapIterator.next();
AttributeHolder arrayNodeMapAttributeHolder = new AttributeHolder();
if (rootNodeEntry.getKey().equalsIgnoreCase("groups") && arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("reference")) {
arrayNodeMapAttributeHolder.setName("$ref");
} else {
arrayNodeMapAttributeHolder.setName(arrayNodeMapRootNodeEntry.getKey());
}
arrayNodeMapAttributeHolder.setType("string");
arrayNodeMapAttributeHolder.setDescription(arrayNodeMapRootNodeEntry.getKey());
if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("value") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("type")) {
arrayNodeMapAttributeHolder.setRequired(Boolean.TRUE);
} else {
arrayNodeMapAttributeHolder.setRequired(Boolean.FALSE);
}
if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("valueAsImageDataURI") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("valueAsURI")) {
arrayNodeMapAttributeHolder.setMutability("readOnly");
arrayNodeMapAttributeHolder.setType("reference");
List<String> referenceTypes = new ArrayList<String>();
referenceTypes.add("uri");
arrayNodeMapAttributeHolder.setReferenceTypes(referenceTypes);
}
arrayNodeMapAttributeHolders.add(arrayNodeMapAttributeHolder);
}
arrayNodeAttributeHolder.setSubAttributes(arrayNodeMapAttributeHolders);
attributeHolders.add(arrayNodeAttributeHolder);
}
} else {
AttributeHolder attributeHolder = new AttributeHolder();
attributeHolder.setName(rootNodeEntry.getKey());
if (rootNodeEntry.getValue().isBoolean()) {
attributeHolder.setType("boolean");
} else {
attributeHolder.setType("string");
}
attributeHolder.setDescription(rootNodeEntry.getKey());
if (rootNodeEntry.getKey().equalsIgnoreCase("userName") || rootNodeEntry.getKey().equalsIgnoreCase("displayName")) {
attributeHolder.setRequired(Boolean.TRUE);
} else {
attributeHolder.setRequired(Boolean.FALSE);
}
if (rootNodeEntry.getKey().equalsIgnoreCase("id") || rootNodeEntry.getKey().equalsIgnoreCase("userName")) {
attributeHolder.setUniqueness("server");
attributeHolder.setReturned("always");
}
if (rootNodeEntry.getKey().equalsIgnoreCase("id") || rootNodeEntry.getKey().equalsIgnoreCase("externalId") || rootNodeEntry.getKey().equalsIgnoreCase("password")) {
attributeHolder.setCaseExact(Boolean.TRUE);
}
if (rootNodeEntry.getKey().equalsIgnoreCase("id")) {
attributeHolder.setMutability("readOnly");
}
attributeHolders.add(attributeHolder);
}
}
}
UserCoreSchema userCoreSchema = (UserCoreSchema) schemaType;
userCoreSchema.setAttributeHolders(attributeHolders);
schemaType = userCoreSchema;
} catch (Exception e) {
e.printStackTrace();
throw new IOException("Unexpected processing error; please check the User class structure.");
}
}
use of org.gluu.oxtrust.model.scim2.user.Group in project oxTrust by GluuFederation.
the class GroupCoreLoadingStrategy method createDummyGroup.
private Group createDummyGroup() {
Group group = new Group();
group.setId("");
group.setExternalId("");
group.setDisplayName("");
Set<MemberRef> members = new HashSet<MemberRef>();
MemberRef memberRef = new MemberRef();
memberRef.setOperation("");
memberRef.setPrimary(false);
memberRef.setValue("test");
memberRef.setDisplay("");
memberRef.setType(MemberRef.Type.USER);
memberRef.setReference("");
members.add(memberRef);
group.setMembers(members);
return group;
}
use of org.gluu.oxtrust.model.scim2.user.Group in project oxTrust by GluuFederation.
the class GroupWebService method updateGroup.
/**
* This implementation differs from spec in the following aspects:
* - Passing a null value for an attribute, does not modify the attribute in the destination, however passing an
* empty array for a multivalued attribute does clear the attribute. Thus, to clear single-valued attribute, PATCH
* operation should be used
*/
@Path("{id}")
@PUT
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Update group", notes = "Update group (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = GroupResource.class)
public Response updateGroup(@ApiParam(value = "Group", required = true) GroupResource group, @PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
Response response;
try {
log.debug("Executing web service method. updateGroup");
GroupResource updatedResource = scim2GroupService.updateGroup(id, group, endpointUrl, userWebService.getEndpointUrl());
String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
} catch (InvalidAttributeValueException e) {
log.error(e.getMessage());
response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
} catch (Exception e) {
log.error("Failure at updateGroup method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of org.gluu.oxtrust.model.scim2.user.Group in project oxTrust by GluuFederation.
the class GroupWebService method searchGroupsPost.
@Path(SEARCH_SUFFIX)
@POST
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Search group POST /.search", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchGroupsPost(@ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) {
log.debug("Executing web service method. searchGroupsPost");
// Calling searchGroups here does not provoke that method's interceptor/decorator being called (only this one's)
URI uri = null;
Response response = searchGroups(searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr());
try {
uri = new URI(endpointUrl + "/" + SEARCH_SUFFIX);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return Response.fromResponse(response).location(uri).build();
}
Aggregations