use of io.jans.scim.model.scim2.ListResponse in project oxTrust by GluuFederation.
the class SchemaWebService method serve.
@GET
@Produces(MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT)
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@RejectFilterParam
public Response serve() {
Response response;
try {
int total = resourceSchemas.size();
ListResponse listResponse = new ListResponse(1, total, total);
for (String urn : resourceSchemas.keySet()) {
listResponse.addResource(getSchemaInstance(resourceSchemas.get(urn), urn));
}
String json = resourceSerializer.getListResponseMapper().writeValueAsString(listResponse);
response = Response.ok(json).location(new URI(endpointUrl)).build();
} catch (Exception e) {
log.error("Failure at serve method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.model.scim2.ListResponse in project oxTrust by GluuFederation.
the class SearchResourcesWebService method search.
@POST
@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
@RefAdjusted
@ApiOperation(value = "General search POST /.search", notes = "Returns a list of resources (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response search(@ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) {
SearchRequest searchReq = new SearchRequest();
Response response = prepareSearchRequest(searchRequest.getSchemas(), searchRequest.getFilter(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr(), searchReq);
if (response == null) {
try {
List<JsonNode> resources = new ArrayList<JsonNode>();
Pair<Integer, Integer> totals = computeResults(searchReq, resources);
ListResponseJsonSerializer custSerializer = new ListResponseJsonSerializer(resourceSerializer, searchReq.getAttributesStr(), searchReq.getExcludedAttributesStr(), searchReq.getCount() == 0);
if (resources.size() > 0)
custSerializer.setJsonResources(resources);
ObjectMapper objmapper = new ObjectMapper();
SimpleModule module = new SimpleModule("ListResponseModule", Version.unknownVersion());
module.addSerializer(ListResponse.class, custSerializer);
objmapper.registerModule(module);
// Provide to constructor original start index, and totals calculated in computeResults call
ListResponse listResponse = new ListResponse(searchReq.getStartIndex(), totals.getFirst(), totals.getSecond());
String json = objmapper.writeValueAsString(listResponse);
response = Response.ok(json).location(new URI(endpointUrl)).build();
} catch (Exception e) {
log.error("Failure at search method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
}
return response;
}
use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.
the class ComplexSearchUserTest method searchNoAttributesParam.
@Test
public void searchNoAttributesParam() {
final String ims = "Skype";
logger.debug("Searching users with attribute nickName existent or ims.value={} using POST verb", ims);
SearchRequest sr = new SearchRequest();
sr.setFilter("nickName pr or ims.value eq \"" + ims + "\"");
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse listResponse = response.readEntity(ListResponse.class);
if (listResponse.getResources() != null) {
for (BaseScimResource resource : listResponse.getResources()) {
UserResource other = (UserResource) resource;
boolean c1 = other.getNickName() != null;
boolean c2 = true;
if (other.getIms() != null)
c2 = other.getIms().stream().anyMatch(im -> im.getValue().toLowerCase().equals(ims.toLowerCase()));
assertTrue(c1 || c2);
}
}
}
use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.
the class ComplexSearchUserTest method searchAttributesParam.
@Test
public void searchAttributesParam() throws Exception {
int count = 3;
List<String> attrList = Arrays.asList("name.familyName", "active");
logger.debug("Searching at most {} users using POST verb", count);
logger.debug("Sorted by family name descending");
logger.debug("Retrieving only the attributes {}", attrList);
SearchRequest sr = new SearchRequest();
sr.setFilter("name.familyName pr");
sr.setSortBy("name.familyName");
sr.setSortOrder("descending");
// Generate a string with the attributes desired to be returned separated by comma
sr.setAttributes(attrList.toString().replaceFirst("\\[", "").replaceFirst("]", ""));
sr.setCount(count);
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse listResponse = response.readEntity(ListResponse.class);
if (listResponse.getResources().size() < count)
logger.warn("Less than {} users satisfying the criteria. TESTER please check manually", count);
else {
// Obtain an array of results
UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
assertEquals(users.length, count);
// Build a set of all attributes that should not appear in the response
Set<String> check = new HashSet<>();
check.addAll(IntrospectUtil.allAttrs.get(usrClass));
// Remove from the ALL list, those requested plus its "parents"
for (String attr : attrList) {
String part = attr;
for (int i = part.length(); i > 0; i = part.lastIndexOf(".")) {
part = part.substring(0, i);
check.remove(part);
}
}
// Remove those that are ALWAYS present (per spec)
check.removeAll(IntrospectUtil.alwaysCoreAttrs.get(usrClass).keySet());
// Confirm for every user, those attributes are not there
for (UserResource user : users) {
for (String path : check) {
String val = null;
try {
val = BeanUtils.getProperty(user, path);
} catch (NestedNullException nne) {
// Intentionally left empty
} finally {
assertNull(val);
}
}
}
boolean correctSorting = true;
for (int i = 1; i < users.length && correctSorting; i++) {
String familyName = users[i - 1].getName().getFamilyName();
String familyName2 = users[i].getName().getFamilyName();
// First string has to be greater than or equal second
correctSorting = familyName.compareTo(familyName2) >= 0;
}
if (!correctSorting) {
// LDAP may ignore case sensitivity, try again using lowercasing
correctSorting = true;
for (int i = 1; i < users.length && correctSorting; i++) {
String familyName = users[i - 1].getName().getFamilyName().toLowerCase();
String familyName2 = users[i].getName().getFamilyName().toLowerCase();
// First string has to be greater than or equal second
correctSorting = familyName.compareTo(familyName2) >= 0;
}
}
assertTrue(correctSorting);
}
}
use of io.jans.scim.model.scim2.ListResponse in project jans by JanssenProject.
the class GroupsBulkTest method getAdminId.
private String getAdminId() {
// Search the id of the admin user
SearchRequest sr = new SearchRequest();
sr.setFilter("userName eq \"admin\"");
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), Status.OK.getStatusCode());
ListResponse lr = response.readEntity(ListResponse.class);
assertTrue(lr.getResources().size() > 0);
return lr.getResources().get(0).getId();
}
Aggregations