Search in sources :

Example 21 with BaseScimResource

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;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Filter(org.gluu.search.filter.Filter) ListViewResponse(org.gluu.persist.model.ListViewResponse) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) ArrayList(java.util.ArrayList) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource)

Example 22 with BaseScimResource

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);
        }
    }
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) PostConstruct(javax.annotation.PostConstruct)

Example 23 with BaseScimResource

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;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 24 with BaseScimResource

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);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 25 with BaseScimResource

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) ListResponse(io.jans.scim.model.scim2.ListResponse) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Aggregations

BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)12 Extension (io.jans.scim.model.scim2.extensions.Extension)12 ArrayList (java.util.ArrayList)12 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)12 Response (javax.ws.rs.core.Response)11 SCIMException (io.jans.scim.model.exception.SCIMException)10 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)9 URI (java.net.URI)8 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)7 ListResponse (io.jans.scim.model.scim2.ListResponse)6 URISyntaxException (java.net.URISyntaxException)6 ListViewResponse (org.gluu.persist.model.ListViewResponse)6 SearchRequest (io.jans.scim.model.scim2.SearchRequest)5 UserResource (io.jans.scim.model.scim2.user.UserResource)5 PagedResult (io.jans.orm.model.PagedResult)4 Filter (io.jans.orm.search.filter.Filter)4 Attribute (io.jans.scim.model.scim2.annotations.Attribute)4 DefaultValue (javax.ws.rs.DefaultValue)4 GET (javax.ws.rs.GET)4 HeaderParam (javax.ws.rs.HeaderParam)4