use of io.jans.scim.model.scim2.annotations.Schema 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 io.jans.scim.model.scim2.annotations.Schema in project jans by JanssenProject.
the class ResourceTypeWS method fillResourceType.
private void fillResourceType(ResourceType rt, Schema schemaAnnot, String endpointUrl, String location, List<SchemaExtensionHolder> schemaExtensions) {
rt.setId(schemaAnnot.name());
rt.setName(schemaAnnot.name());
rt.setDescription(schemaAnnot.description());
rt.setEndpoint(endpointUrl.substring(appConfiguration.getBaseEndpoint().length()));
rt.setSchema(schemaAnnot.id());
rt.setSchemaExtensions(schemaExtensions);
Meta rtMeta = new Meta();
rtMeta.setLocation(location);
rtMeta.setResourceType("ResourceType");
rt.setMeta(rtMeta);
}
use of io.jans.scim.model.scim2.annotations.Schema in project jans by JanssenProject.
the class BaseScimWebService method prepareSearchRequest.
protected Response prepareSearchRequest(List<String> schemas, String filter, String sortBy, String sortOrder, Integer startIndex, Integer count, String attrsList, String excludedAttrsList, SearchRequest request) {
Response response = null;
if (schemas != null && schemas.size() == 1 && schemas.get(0).equals(SEARCH_REQUEST_SCHEMA_ID)) {
count = count == null ? getMaxCount() : count;
// Per spec, a negative value SHALL be interpreted as "0" for count
if (count < 0) {
count = 0;
}
if (count <= getMaxCount()) {
// SCIM searches are 1 indexed
startIndex = (startIndex == null || startIndex < 1) ? 1 : startIndex;
if (StringUtils.isEmpty(sortOrder) || !sortOrder.equals(SortOrder.DESCENDING.getValue())) {
sortOrder = SortOrder.ASCENDING.getValue();
}
request.setSchemas(schemas);
request.setAttributes(attrsList);
request.setExcludedAttributes(excludedAttrsList);
request.setFilter(filter);
request.setSortBy(sortBy);
request.setSortOrder(sortOrder);
request.setStartIndex(startIndex);
request.setCount(count);
} else {
response = getErrorResponse(BAD_REQUEST, ErrorScimType.TOO_MANY, "Maximum number of results per page is " + getMaxCount());
}
} else {
response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Wrong schema(s) supplied in Search Request");
}
return response;
}
use of io.jans.scim.model.scim2.annotations.Schema in project jans by JanssenProject.
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 io.jans.scim.model.scim2.annotations.Schema in project jans by JanssenProject.
the class Scim2GroupService method transferAttributesToGroup.
private void transferAttributesToGroup(GroupResource res, GluuGroup group, boolean skipMembersValidation, boolean fillMembersDisplay, String usersUrl) {
// externalId (so jansExtId) not part of LDAP schema
group.setAttribute("jansMetaCreated", res.getMeta().getCreated());
group.setAttribute("jansMetaLastMod", res.getMeta().getLastModified());
// When creating group, location will be set again when having an inum
group.setAttribute("jansMetaLocation", res.getMeta().getLocation());
group.setDisplayName(res.getDisplayName());
group.setStatus(GluuStatus.ACTIVE);
group.setOrganization(organizationService.getDnForOrganization());
Set<Member> members = res.getMembers();
if (members != null && members.size() > 0) {
Set<String> groupMembers = group.getMembers().stream().map(userPersistenceHelper::getUserInumFromDN).collect(Collectors.toCollection(HashSet::new));
List<String> listMembers = new ArrayList<>();
List<Member> invalidMembers = new ArrayList<>();
// Add the members, and complement the $refs and users' display names in res
for (Member member : members) {
GluuCustomPerson person;
// it's not null as it is required in GroupResource
String inum = member.getValue();
// we make database lookups
if (!skipMembersValidation && !groupMembers.contains(inum)) {
person = personService.getPersonByInum(inum);
if (person != null && fillMembersDisplay) {
member.setDisplay(person.getDisplayName());
}
} else {
person = new GluuCustomPerson();
person.setDn(personService.getDnForPerson(inum));
}
if (person == null) {
log.info("Member identified by {} does not exist. Ignored", inum);
invalidMembers.add(member);
} else {
member.setRef(usersUrl + "/" + inum);
member.setType(ScimResourceUtil.getType(UserResource.class));
if (skipMembersValidation) {
// In overhead bypass mode, display names must not be returned
member.setDisplay(null);
}
listMembers.add(person.getDn());
}
}
group.setMembers(listMembers);
members.removeAll(invalidMembers);
if (members.isEmpty()) {
res.setMembers(null);
}
} else {
group.setMembers(new ArrayList<>());
}
}
Aggregations