use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.
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<>();
// 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<>());
// 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.Attribute in project jans by JanssenProject.
the class UserWebService method patchUser.
@Path("{id}")
@PATCH
@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(scopes = { "https://jans.io/scim/users.write" })
@RefAdjusted
public Response patchUser(PatchRequest request, @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. patchUser");
response = inspectPatchRequest(request, UserResource.class);
if (response != null)
return response;
ScimCustomPerson person = userPersistenceHelper.getPersonByInum(id);
if (person == null)
return notFoundResponse(id, userResourceType);
response = externalConstraintsService.applyEntityCheck(person, request, httpHeaders, uriInfo, HttpMethod.PATCH, userResourceType);
if (response != null)
return response;
UserResource user = new UserResource();
// Fill user instance with all info from person
scim2UserService.transferAttributesToUserResource(person, user, endpointUrl);
// Apply patches one by one in sequence
for (PatchOperation po : request.getOperations()) {
// Handle special case: https://github.com/GluuFederation/oxTrust/issues/800
if (po.getType().equals(REMOVE) && po.getPath().equals("pairwiseIdentifiers")) {
// If this block weren't here, the implementation will throw error because read-only attribute cannot be altered
person.setPpid(null);
user.setPairwiseIdentifiers(null);
scim2UserService.removePPIDsBranch(person.getDn());
} else {
user = (UserResource) scim2PatchService.applyPatchOperation(user, po);
}
}
// Throws exception if final representation does not pass overall validation
log.debug("patchUser. Revising final resource representation still passes validations");
executeValidation(user);
ScimResourceUtil.adjustPrimarySubAttributes(user);
// Update timestamp
user.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
// Replaces the information found in person with the contents of user
scim2UserService.replacePersonInfo(person, user, endpointUrl);
String json = resourceSerializer.serialize(user, attrsList, excludedAttrsList);
response = Response.ok(new URI(user.getMeta().getLocation())).entity(json).build();
} catch (InvalidAttributeValueException e) {
log.error(e.getMessage(), e);
response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
} catch (SCIMException e) {
response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, e.getMessage());
} catch (Exception e) {
log.error("Failure at patchUser method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
Aggregations