use of io.jans.scim.model.scim2.BaseScimResource in project jans by JanssenProject.
the class FidoDeviceWebService method searchDevices.
private PagedResult<BaseScimResource> searchDevices(String userId, String filter, String sortBy, SortOrder sortOrder, int startIndex, int count) throws Exception {
Filter ldapFilter = scimFilterParserService.createFilter(filter, Filter.createPresenceFilter("jansId"), FidoDeviceResource.class);
log.info("Executing search for fido devices using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}', userId '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count, userId);
// Currently, searching with SUB scope in Couchbase requires some help (beyond use of baseDN)
if (StringUtils.isNotEmpty(userId)) {
ldapFilter = Filter.createANDFilter(ldapFilter, Filter.createEqualityFilter("personInum", userId));
}
PagedResult<GluuCustomFidoDevice> list;
try {
list = entryManager.findPagedEntries(fidoDeviceService.getDnForFidoDevice(userId, null), GluuCustomFidoDevice.class, ldapFilter, null, sortBy, sortOrder, startIndex - 1, count, getMaxCount());
} catch (Exception e) {
log.info("Returning an empty listViewReponse");
log.error(e.getMessage(), e);
list = new PagedResult<>();
list.setEntries(new ArrayList<>());
}
List<BaseScimResource> resources = new ArrayList<>();
for (GluuCustomFidoDevice device : list.getEntries()) {
FidoDeviceResource scimDev = new FidoDeviceResource();
transferAttributesToFidoResource(device, scimDev, endpointUrl, userPersistenceHelper.getUserInumFromDN(device.getDn()));
resources.add(scimDev);
}
log.info("Found {} matching entries - returning {}", list.getTotalEntriesCount(), list.getEntries().size());
PagedResult<BaseScimResource> result = new PagedResult<>();
result.setEntries(resources);
result.setTotalEntriesCount(list.getTotalEntriesCount());
return result;
}
use of io.jans.scim.model.scim2.BaseScimResource in project jans by JanssenProject.
the class Fido2DeviceWebService method doSearchDevices.
private Response doSearchDevices(String userId, String filter, Integer startIndex, Integer count, String sortBy, String sortOrder, String attrsList, String excludedAttrsList, String method) {
Response response;
try {
SearchRequest searchReq = new SearchRequest();
response = prepareSearchRequest(searchReq.getSchemas(), filter, sortBy, sortOrder, startIndex, count, attrsList, excludedAttrsList, searchReq);
if (response != null)
return response;
response = externalConstraintsService.applySearchCheck(searchReq, httpHeaders, uriInfo, method, fido2ResourceType);
if (response != null)
return response;
response = validateExistenceOfUser(userId);
if (response != null)
return response;
PagedResult<BaseScimResource> resources = searchDevices(userId, searchReq.getFilter(), translateSortByAttribute(Fido2DeviceResource.class, searchReq.getSortBy()), SortOrder.getByValue(searchReq.getSortOrder()), searchReq.getStartIndex(), searchReq.getCount());
String json = getListResponseSerialized(resources.getTotalEntriesCount(), searchReq.getStartIndex(), resources.getEntries(), searchReq.getAttributesStr(), searchReq.getExcludedAttributesStr(), searchReq.getCount() == 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 searchF2Devices method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.model.scim2.BaseScimResource in project jans by JanssenProject.
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<>();
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 io.jans.scim.model.scim2.BaseScimResource in project jans by JanssenProject.
the class BaseScimWebService method executeValidation.
protected void executeValidation(BaseScimResource resource, boolean laxRequiredness) throws SCIMException {
ResourceValidator rv = new ResourceValidator(resource, extService.getResourceExtensions(resource.getClass()));
if (!laxRequiredness) {
rv.validateSchemasAttribute();
}
rv.validateRequiredAttributes(laxRequiredness);
rv.validateValidableAttributes();
// By section 7 of RFC 7643, we are not forced to constrain attribute values when they have a list of canonical values associated
// rv.validateCanonicalizedAttributes();
rv.validateExtendedAttributes();
}
use of io.jans.scim.model.scim2.BaseScimResource in project jans by JanssenProject.
the class BaseScimWebService method getListResponseSerialized.
String getListResponseSerialized(int total, int startIndex, List<BaseScimResource> resources, String attrsList, String excludedAttrsList, boolean ignoreResults) throws IOException {
ListResponse listResponse = new ListResponse(startIndex, resources.size(), total);
listResponse.setResources(resources);
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule("ListResponseModule", Version.unknownVersion());
module.addSerializer(ListResponse.class, new ListResponseJsonSerializer(resourceSerializer, attrsList, excludedAttrsList, ignoreResults));
mapper.registerModule(module);
return mapper.writeValueAsString(listResponse);
}
Aggregations