use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class ExtensionService method extensionOfAttribute.
public Extension extensionOfAttribute(Class<? extends BaseScimResource> cls, String attribute) {
List<Extension> extensions = getResourceExtensions(cls);
Extension belong = null;
try {
for (Extension ext : extensions) {
if (attribute.startsWith(ext.getUrn() + ":")) {
attribute = attribute.substring(ext.getUrn().length() + 1);
for (String fieldName : ext.getFields().keySet()) if (attribute.equals(fieldName)) {
belong = ext;
break;
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return belong;
}
use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class Scim2PatchService method applyPatchOperation.
public BaseScimResource applyPatchOperation(BaseScimResource resource, PatchOperation operation) throws Exception {
BaseScimResource result = null;
Map<String, Object> genericMap = null;
PatchOperationType opType = operation.getType();
Class<? extends BaseScimResource> clazz = resource.getClass();
String path = operation.getPath();
log.debug("applyPatchOperation of type {}", opType);
// Determine if operation is with value filter
if (StringUtils.isNotEmpty(path) && !operation.getType().equals(PatchOperationType.ADD)) {
Pair<Boolean, String> pair = validateBracketedPath(path);
if (pair.getFirst()) {
String valSelFilter = pair.getSecond();
if (valSelFilter == null)
throw new SCIMException("Unexpected syntax in value selection filter");
else {
int i = path.indexOf("[");
String attribute = path.substring(0, i);
i = path.lastIndexOf("].");
String subAttribute = i == -1 ? "" : path.substring(i + 2);
// Abort earlier
return applyPatchOperationWithValueFilter(resource, operation, valSelFilter, attribute, subAttribute);
}
}
}
if (!opType.equals(PatchOperationType.REMOVE)) {
Object value = operation.getValue();
List<String> extensionUrns = extService.getUrnsOfExtensions(clazz);
if (value instanceof Map)
genericMap = IntrospectUtil.strObjMap(value);
else {
// It's an atomic value or an array
if (StringUtils.isEmpty(path))
throw new SCIMException("Value(s) supplied for resource not parseable");
// Create a simple map and trim the last part of path
String[] subPaths = ScimResourceUtil.splitPath(path, extensionUrns);
genericMap = Collections.singletonMap(subPaths[subPaths.length - 1], value);
if (subPaths.length == 1)
path = "";
else
path = path.substring(0, path.lastIndexOf("."));
}
if (StringUtils.isNotEmpty(path)) {
// Visit backwards creating a composite map
String[] subPaths = ScimResourceUtil.splitPath(path, extensionUrns);
for (int i = subPaths.length - 1; i >= 0; i--) {
// Create a string consisting of all subpaths until the i-th
StringBuilder sb = new StringBuilder();
for (int j = 0; j <= i; j++) sb.append(subPaths[j]).append(".");
Attribute annot = IntrospectUtil.getFieldAnnotation(sb.substring(0, sb.length() - 1), clazz, Attribute.class);
boolean multivalued = !(annot == null || annot.multiValueClass().equals(NullType.class));
Map<String, Object> genericBiggerMap = new HashMap<String, Object>();
genericBiggerMap.put(subPaths[i], multivalued ? Collections.singletonList(genericMap) : genericMap);
genericMap = genericBiggerMap;
}
}
log.debug("applyPatchOperation. Generating a ScimResource from generic map: {}", genericMap.toString());
}
// Try parse genericMap as an instance of the resource
ObjectMapper mapper = new ObjectMapper();
BaseScimResource alter = opType.equals(PatchOperationType.REMOVE) ? resource : mapper.convertValue(genericMap, clazz);
List<Extension> extensions = extService.getResourceExtensions(clazz);
switch(operation.getType()) {
case REPLACE:
result = ScimResourceUtil.transferToResourceReplace(alter, resource, extensions);
break;
case ADD:
result = ScimResourceUtil.transferToResourceAdd(alter, resource, extensions);
break;
case REMOVE:
result = ScimResourceUtil.deleteFromResource(alter, operation.getPath(), extensions);
break;
}
return result;
}
use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class Scim2UserService method searchUsers.
public ListViewResponse<BaseScimResource> searchUsers(String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String url, int maxCount) throws Exception {
Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "inum=*", UserResource.class);
log.info("Executing search for users using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
ListViewResponse<GluuCustomPerson> list = ldapEntryManager.findListViewResponse(personService.getDnForPerson(null), GluuCustomPerson.class, ldapFilter, startIndex, count, maxCount, sortBy, sortOrder, null);
List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
for (GluuCustomPerson person : list.getResult()) {
UserResource scimUsr = new UserResource();
transferAttributesToUserResource(person, scimUsr, url);
resources.add(scimUsr);
}
log.info("Found {} matching entries - returning {}", list.getTotalResults(), list.getResult().size());
ListViewResponse<BaseScimResource> result = new ListViewResponse<BaseScimResource>();
result.setResult(resources);
result.setTotalResults(list.getTotalResults());
return result;
}
use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class BaseScimWebService method assignMetaInformation.
protected void assignMetaInformation(BaseScimResource resource) {
// Generate some meta information (this replaces the info client passed in the request)
long now = new Date().getTime();
String val = ISODateTimeFormat.dateTime().withZoneUTC().print(now);
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(resource.getClass()));
meta.setCreated(val);
meta.setLastModified(val);
// For version attritute: Service provider support for this attribute is optional and subject to the service provider's support for versioning
// For location attribute: this will be set after current user creation in LDAP
resource.setMeta(meta);
}
use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class SchemaWebService method setup.
@PostConstruct
public void setup() {
// Do not use getClass() here... a typical weld issue...
endpointUrl = appConfiguration.getBaseEndpoint() + SchemaWebService.class.getAnnotation(Path.class).value();
List<Class<? extends BaseScimResource>> excludedResources = Arrays.asList(SchemaResource.class, ResourceType.class, ServiceProviderConfig.class);
resourceSchemas = new HashMap<String, Class<? extends BaseScimResource>>();
// Fill map with urn vs. resource
for (Class<? extends BaseScimResource> cls : IntrospectUtil.allAttrs.keySet()) {
if (!excludedResources.contains(cls)) {
resourceSchemas.put(ScimResourceUtil.getDefaultSchemaUrn(cls), cls);
for (Extension extension : extService.getResourceExtensions(cls)) resourceSchemas.put(extension.getUrn(), cls);
}
}
}
Aggregations