use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class GroupWebService method searchGroups.
@GET
@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 groups", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchGroups(@QueryParam(QUERY_PARAM_FILTER) String filter, @QueryParam(QUERY_PARAM_START_INDEX) Integer startIndex, @QueryParam(QUERY_PARAM_COUNT) Integer count, @QueryParam(QUERY_PARAM_SORT_BY) String sortBy, @QueryParam(QUERY_PARAM_SORT_ORDER) String sortOrder, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
Response response;
try {
log.debug("Executing web service method. searchGroups");
sortBy = translateSortByAttribute(GroupResource.class, sortBy);
ListViewResponse<BaseScimResource> resources = scim2GroupService.searchGroups(filter, sortBy, SortOrder.getByValue(sortOrder), startIndex, count, endpointUrl, userWebService.getEndpointUrl(), getMaxCount());
String json = getListResponseSerialized(resources.getTotalResults(), startIndex, resources.getResult(), attrsList, excludedAttrsList, count == 0);
response = Response.ok(json).location(new URI(endpointUrl)).build();
} catch (SCIMException e) {
log.error(e.getMessage(), e);
response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, e.getMessage());
} catch (Exception e) {
log.error("Failure at searchGroups method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class ResourceTypeWS method getUserResourceType.
private ResourceType getUserResourceType() {
Class<? extends BaseScimResource> cls = UserResource.class;
List<Extension> usrExtensions = extService.getResourceExtensions(cls);
List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
for (Extension extension : usrExtensions) {
SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
userExtensionSchema.setSchema(extension.getUrn());
userExtensionSchema.setRequired(false);
schemaExtensions.add(userExtensionSchema);
}
ResourceType usrRT = new ResourceType();
fillResourceType(usrRT, ScimResourceUtil.getSchemaAnnotation(cls), userService.getEndpointUrl(), getResourceLocation(USER_SUFFIX), schemaExtensions);
return usrRT;
}
use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class SchemaWebService method getSchemaInstance.
private SchemaResource getSchemaInstance(Class<? extends BaseScimResource> clazz, String urn) throws Exception {
if (ScimResourceUtil.getDefaultSchemaUrn(clazz).equals(urn))
// Process core attributes
return getSchemaInstance(clazz);
else {
// process extension attributes
SchemaResource resource = null;
Class<? extends BaseScimResource> schemaCls = SchemaResource.class;
// Find the appropriate extension
List<Extension> extensions = extService.getResourceExtensions(clazz);
for (Extension extension : extensions) {
if (extension.getUrn().equals(urn)) {
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(schemaCls));
meta.setLocation(endpointUrl + "/" + urn);
resource = new SchemaResource();
resource.setId(urn);
resource.setName(extension.getName());
resource.setDescription(extension.getDescription());
resource.setMeta(meta);
List<SchemaAttribute> attribs = new ArrayList<SchemaAttribute>();
for (ExtensionField field : extension.getFields().values()) {
SchemaAttribute schAttr = new SchemaAttribute();
schAttr.setName(field.getName());
schAttr.setMultiValued(field.isMultiValued());
schAttr.setDescription(field.getDescription());
schAttr.setRequired(false);
schAttr.setCanonicalValues(null);
schAttr.setCaseExact(false);
schAttr.setMutability(AttributeDefinition.Mutability.READ_WRITE.getName());
schAttr.setReturned(AttributeDefinition.Returned.DEFAULT.getName());
schAttr.setUniqueness(AttributeDefinition.Uniqueness.NONE.getName());
schAttr.setReferenceTypes(null);
AttributeDefinition.Type type = field.getAttributeDefinitionType();
schAttr.setType(type == null ? null : type.getName());
schAttr.setSubAttributes(null);
attribs.add(schAttr);
}
resource.setAttributes(attribs);
break;
}
}
return resource;
}
}
use of org.gluu.oxtrust.model.scim2.BaseScimResource 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.BaseScimResource 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;
}
Aggregations