use of io.jans.scim.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 io.jans.scim.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);
}
}
}
use of io.jans.scim.model.scim2.BaseScimResource in project oxTrust by GluuFederation.
the class UserWebService method searchUsers.
@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 users", notes = "Returns a list of users (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchUsers(@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. searchUsers");
sortBy = translateSortByAttribute(UserResource.class, sortBy);
ListViewResponse<BaseScimResource> resources = scim2UserService.searchUsers(filter, sortBy, SortOrder.getByValue(sortOrder), startIndex, count, endpointUrl, 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 searchUsers 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 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.BaseScimResource in project jans by JanssenProject.
the class ListResponseProvider method readFrom.
public ListResponse readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
InputStreamReader isr = new InputStreamReader(entityStream, Charset.forName("UTF-8"));
List<BaseScimResource> resources = null;
// we will get a LinkedHashMap here...
Map<String, Object> map = mapper.readValue(isr, new TypeReference<Map<String, Object>>() {
});
// "remove" what came originally
Object branch = map.remove("Resources");
if (branch != null) {
resources = new ArrayList<>();
// Here we assume everything is coming from the server correctly (that is, following the spec) and conversions succeed
for (Object resource : (Collection) branch) {
Map<String, Object> resourceAsMap = IntrospectUtil.strObjMap(resource);
List<String> schemas = (List<String>) resourceAsMap.get("schemas");
// Guess the real class of the resource by inspecting the schemas in it
for (String schema : schemas) {
for (Class<? extends BaseScimResource> cls : IntrospectUtil.allAttrs.keySet()) {
if (ScimResourceUtil.getSchemaAnnotation(cls).id().equals(schema)) {
// Create the object with the proper class
resources.add(mapper.convertValue(resource, cls));
logger.trace("Found resource of class {} in ListResponse", cls.getSimpleName());
break;
}
}
}
}
}
ListResponse response = mapper.convertValue(map, ListResponse.class);
response.setResources(resources);
return response;
}
Aggregations