use of org.gluu.oxtrust.model.scim2.annotations.Attribute in project oxTrust by GluuFederation.
the class BaseScimWebService method inspectPatchRequest.
protected Response inspectPatchRequest(PatchRequest patch, Class<? extends BaseScimResource> cls) {
Response response = null;
List<String> schemas = patch.getSchemas();
if (schemas != null && schemas.size() == 1 && schemas.get(0).equals(PATCH_REQUEST_SCHEMA_ID)) {
List<PatchOperation> ops = patch.getOperations();
if (ops != null) {
// Adjust paths if they came prefixed
String defSchema = ScimResourceUtil.getDefaultSchemaUrn(cls);
List<String> urns = extService.getUrnsOfExtensions(cls);
urns.add(defSchema);
for (PatchOperation op : ops) {
if (op.getPath() != null)
op.setPath(ScimResourceUtil.adjustNotationInPath(op.getPath(), defSchema, urns));
}
for (PatchOperation op : ops) {
if (op.getType() == null)
response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Operation '" + op.getOperation() + "' not recognized");
else {
String path = op.getPath();
if (StringUtils.isEmpty(path) && op.getType().equals(PatchOperationType.REMOVE))
response = getErrorResponse(BAD_REQUEST, ErrorScimType.NO_TARGET, "Path attribute is required for remove operation");
else if (op.getValue() == null && !op.getType().equals(PatchOperationType.REMOVE))
response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Value attribute is required for operations other than remove");
}
if (response != null)
break;
}
} else
response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Patch request MUST contain the attribute 'Operations'");
} else
response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Wrong schema(s) supplied in Search Request");
log.info("inspectPatchRequest. Preprocessing of patch request {}", response == null ? "passed" : "failed");
return response;
}
use of org.gluu.oxtrust.model.scim2.annotations.Attribute 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.annotations.Attribute in project oxTrust by GluuFederation.
the class SchemaWebService method getSchemaInstance.
private SchemaResource getSchemaInstance(Class<? extends BaseScimResource> clazz) throws Exception {
SchemaResource resource;
Class<? extends BaseScimResource> schemaCls = SchemaResource.class;
Schema annotation = ScimResourceUtil.getSchemaAnnotation(clazz);
if (!clazz.equals(schemaCls) && annotation != null) {
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(schemaCls));
meta.setLocation(endpointUrl + "/" + annotation.id());
resource = new SchemaResource();
resource.setId(annotation.id());
resource.setName(annotation.name());
resource.setDescription(annotation.description());
resource.setMeta(meta);
List<SchemaAttribute> attribs = new ArrayList<SchemaAttribute>();
// paths are, happily alphabetically sorted :)
for (String path : IntrospectUtil.allAttrs.get(clazz)) {
SchemaAttribute schAttr = new SchemaAttribute();
Field f = IntrospectUtil.findFieldFromPath(clazz, path);
Attribute attrAnnot = f.getAnnotation(Attribute.class);
if (attrAnnot != null) {
JsonProperty jsonAnnot = f.getAnnotation(JsonProperty.class);
schAttr.setName(jsonAnnot == null ? f.getName() : jsonAnnot.value());
schAttr.setType(attrAnnot.type().getName());
schAttr.setMultiValued(!attrAnnot.multiValueClass().equals(NullType.class) || IntrospectUtil.isCollection(f.getType()));
schAttr.setDescription(attrAnnot.description());
schAttr.setRequired(attrAnnot.isRequired());
schAttr.setCanonicalValues(attrAnnot.canonicalValues().length == 0 ? null : Arrays.asList(attrAnnot.canonicalValues()));
schAttr.setCaseExact(attrAnnot.isCaseExact());
schAttr.setMutability(attrAnnot.mutability().getName());
schAttr.setReturned(attrAnnot.returned().getName());
schAttr.setUniqueness(attrAnnot.uniqueness().getName());
schAttr.setReferenceTypes(attrAnnot.referenceTypes().length == 0 ? null : Arrays.asList(attrAnnot.referenceTypes()));
if (attrAnnot.type().equals(AttributeDefinition.Type.COMPLEX))
schAttr.setSubAttributes(new ArrayList<SchemaAttribute>());
// root list
List<SchemaAttribute> list = attribs;
String[] parts = path.split("\\.");
for (int i = 0; i < parts.length - 1; i++) {
// skip last part (real attribute name)
int j = list.indexOf(new SchemaAttribute(parts[i]));
list = list.get(j).getSubAttributes();
}
list.add(schAttr);
}
}
resource.setAttributes(attribs);
} else
resource = null;
return resource;
}
use of org.gluu.oxtrust.model.scim2.annotations.Attribute in project oxTrust by GluuFederation.
the class ExtensionService method getResourceExtensions.
public List<Extension> getResourceExtensions(Class<? extends BaseScimResource> cls) {
List<Extension> list = new ArrayList<Extension>();
try {
// Currently support one extension only for User Resource
if (cls.equals(UserResource.class)) {
Map<String, ExtensionField> fields = new HashMap<String, ExtensionField>();
for (GluuAttribute attribute : attrService.getSCIMRelatedAttributes()) {
if (attribute.getOxSCIMCustomAttribute().equals(ScimCustomAtribute.TRUE)) {
// first non-null check is needed because certain entries do not have the multivalue attribute set
boolean multi = attribute.getOxMultivaluedAttribute() != null && attribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE);
ExtensionField field = new ExtensionField();
field.setDescription(attribute.getDescription());
field.setType(attribute.getDataType());
field.setMultiValued(multi);
field.setName(attribute.getName());
fields.put(attribute.getName(), field);
}
}
Extension ext = new Extension(USER_EXT_SCHEMA_ID);
ext.setFields(fields);
ext.setName(USER_EXT_SCHEMA_NAME);
ext.setDescription(USER_EXT_SCHEMA_DESCRIPTION);
list.add(ext);
}
} catch (Exception e) {
log.error("An error ocurred when building extension for {}", cls.getName());
log.error(e.getMessage(), e);
}
return list;
}
use of org.gluu.oxtrust.model.scim2.annotations.Attribute in project oxTrust by GluuFederation.
the class ExtensionService method getFieldOfExtendedAttribute.
public ExtensionField getFieldOfExtendedAttribute(Class<? extends BaseScimResource> cls, String attribute) {
List<Extension> extensions = getResourceExtensions(cls);
ExtensionField field = null;
try {
for (Extension ext : extensions) {
if (attribute.startsWith(ext.getUrn() + ":")) {
attribute = attribute.substring(ext.getUrn().length() + 1);
for (ExtensionField f : ext.getFields().values()) if (attribute.equals(f.getName())) {
field = f;
break;
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return field;
}
Aggregations