001/*
002 * Copyright 2011-2013 UnboundID Corp.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License (GPLv2 only)
006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
007 * as published by the Free Software Foundation.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program; if not, see <http://www.gnu.org/licenses>.
016 */
017
018package com.unboundid.scim.wink;
019
020import com.unboundid.scim.sdk.OAuthTokenHandler;
021
022import javax.servlet.http.HttpServletRequest;
023import javax.ws.rs.GET;
024import javax.ws.rs.Path;
025import javax.ws.rs.PathParam;
026import javax.ws.rs.Produces;
027import javax.ws.rs.QueryParam;
028import javax.ws.rs.core.Context;
029import javax.ws.rs.core.HttpHeaders;
030import javax.ws.rs.core.MediaType;
031import javax.ws.rs.core.Response;
032import javax.ws.rs.core.SecurityContext;
033import javax.ws.rs.core.UriInfo;
034
035import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_BASE_ID;
036import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_FILTER;
037import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_PAGE_SIZE;
038import static com.unboundid.scim.sdk.SCIMConstants.
039    QUERY_PARAMETER_PAGE_START_INDEX;
040import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_SCOPE;
041import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_SORT_BY;
042import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_SORT_ORDER;
043
044
045
046/**
047 * This class is a Wink dynamic resource implementation for query operations
048 * on a SCIM resource where the client requests XML response format in the URL
049 * by appending ".xml" on to the endpoint.
050 */
051@Path("{endpoint}.xml")
052public class XMLQueryResource extends AbstractSCIMResource
053{
054  /**
055   * Create a new SCIM wink resource for XML query operations on a
056   * SCIM endpoint.
057   *
058   * @param application         The SCIM JAX-RS application associated with this
059   *                            resource.
060   * @param tokenHandler        The token handler to use for OAuth
061   *                            authentication.
062   */
063  public XMLQueryResource(final SCIMApplication application,
064                          final OAuthTokenHandler tokenHandler)
065  {
066    super(application, tokenHandler);
067  }
068
069
070
071  /**
072   * Implement the GET operation producing XML format.
073   *
074   * @param endpoint         The resource endpoint.
075   * @param request          The current HTTP servlet request.
076   * @param securityContext  The security context of the current request.
077   * @param headers          The request headers.
078   * @param uriInfo          The URI info for the request.
079   * @param filterString     The filter query parameter, or {@code null}.
080   * @param baseID           The SCIM resource ID of the search base entry,
081   *                         or {@code null}.
082   * @param searchScope      The LDAP search scope to use, or {@code null}.
083   * @param sortBy           The sortBy query parameter, or {@code null}.
084   * @param sortOrder        The sortOrder query parameter, or {@code null}.
085   * @param pageStartIndex   The startIndex query parameter, or {@code null}.
086   * @param pageSize         The count query parameter, or {@code null}.
087   *
088   * @return  The response to the request.
089   */
090  @GET
091  @Produces(MediaType.APPLICATION_XML)
092  public Response doXmlGet(@PathParam("endpoint") final String endpoint,
093                           @Context final HttpServletRequest request,
094                           @Context final SecurityContext securityContext,
095                           @Context final HttpHeaders headers,
096                           @Context final UriInfo uriInfo,
097                           @QueryParam(QUERY_PARAMETER_FILTER)
098                           final String filterString,
099                           @QueryParam(QUERY_PARAMETER_BASE_ID)
100                           final String baseID,
101                           @QueryParam(QUERY_PARAMETER_SCOPE)
102                           final String searchScope,
103                           @QueryParam(QUERY_PARAMETER_SORT_BY)
104                           final String sortBy,
105                           @QueryParam(QUERY_PARAMETER_SORT_ORDER)
106                           final String sortOrder,
107                           @QueryParam(QUERY_PARAMETER_PAGE_START_INDEX)
108                           final String pageStartIndex,
109                           @QueryParam(QUERY_PARAMETER_PAGE_SIZE)
110                           final String pageSize)
111  {
112    final RequestContext requestContext =
113        new RequestContext(request, securityContext, headers, uriInfo,
114                           MediaType.APPLICATION_XML_TYPE,
115                           MediaType.APPLICATION_XML_TYPE);
116
117    return getUsers(requestContext, endpoint, filterString, baseID, searchScope,
118                    sortBy, sortOrder, pageStartIndex, pageSize);
119  }
120
121
122
123}