use of io.jans.scim.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class FidoDeviceWebService method searchDevices.
private ListViewResponse<BaseScimResource> searchDevices(String userId, String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String url) throws Exception {
Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "oxId=*", FidoDeviceResource.class);
log.info("Executing search for fido devices using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
ListViewResponse<GluuCustomFidoDevice> list = ldapEntryManager.findListViewResponse(fidoDeviceService.getDnForFidoDevice(userId, null), GluuCustomFidoDevice.class, ldapFilter, startIndex, count, getMaxCount(), sortBy, sortOrder, null);
List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
for (GluuCustomFidoDevice device : list.getResult()) {
FidoDeviceResource scimDev = new FidoDeviceResource();
transferAttributesToFidoResource(device, scimDev, url, getUserInumFromDN(device.getDn()));
resources.add(scimDev);
}
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 io.jans.scim.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class FidoDeviceWebService method searchDevices.
@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 devices", notes = "Returns a list of devices", response = ListResponse.class)
public Response searchDevices(@QueryParam("userId") String userId, @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. searchDevices");
sortBy = translateSortByAttribute(FidoDeviceResource.class, sortBy);
ListViewResponse<BaseScimResource> resources = searchDevices(userId, filter, sortBy, SortOrder.getByValue(sortOrder), startIndex, count, endpointUrl);
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 searchDevices 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 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 io.jans.scim.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class Scim2GroupService method searchGroups.
public ListViewResponse<BaseScimResource> searchGroups(String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String groupsUrl, String usersUrl, int maxCount) throws Exception {
Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "inum=*", GroupResource.class);
log.info("Executing search for groups using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
ListViewResponse<GluuGroup> list = ldapEntryManager.findListViewResponse(groupService.getDnForGroup(null), GluuGroup.class, ldapFilter, startIndex, count, maxCount, sortBy, sortOrder, null);
List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
for (GluuGroup group : list.getResult()) {
GroupResource scimGroup = new GroupResource();
transferAttributesToGroupResource(group, scimGroup, groupsUrl, usersUrl);
// TODO: Delete this IF in the future - added for backwards compatibility with SCIM-Client <= 3.1.2.
if (scimGroup.getMembers() == null)
scimGroup.setMembers(new HashSet<Member>());
resources.add(scimGroup);
}
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 io.jans.scim.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class ListResponseJsonSerializer method serialize.
@Override
public void serialize(ListResponse listResponse, JsonGenerator jGen, SerializerProvider provider) throws IOException {
try {
jGen.writeStartObject();
jGen.writeArrayFieldStart("schemas");
for (String schema : listResponse.getSchemas()) jGen.writeString(schema);
jGen.writeEndArray();
jGen.writeNumberField("totalResults", listResponse.getTotalResults());
if (!skipResults) {
if (listResponse.getItemsPerPage() > 0) {
// these two bits are "REQUIRED when partial results are returned due to pagination." (section 3.4.2 RFC 7644)
jGen.writeNumberField("startIndex", listResponse.getStartIndex());
jGen.writeNumberField("itemsPerPage", listResponse.getItemsPerPage());
}
// Section 3.4.2 RFC 7644: Resources [...] REQUIRED if "totalResults" is non-zero
if (listResponse.getTotalResults() > 0) {
jGen.writeArrayFieldStart("Resources");
if (listResponse.getResources().size() > 0)
for (BaseScimResource resource : listResponse.getResources()) {
JsonNode jsonResource = mapper.readTree(resourceSerializer.serialize(resource, attributes, excludeAttributes));
jGen.writeTree(jsonResource);
}
else if (jsonResources != null)
for (JsonNode node : jsonResources) jGen.writeTree(node);
jGen.writeEndArray();
}
}
jGen.writeEndObject();
} catch (Exception e) {
throw new IOException(e);
}
}
Aggregations