001/* 002 * Copyright 2011-2016 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.Consumes; 024import javax.ws.rs.GET; 025import javax.ws.rs.POST; 026import javax.ws.rs.Path; 027import javax.ws.rs.PathParam; 028import javax.ws.rs.Produces; 029import javax.ws.rs.QueryParam; 030import javax.ws.rs.core.Context; 031import javax.ws.rs.core.HttpHeaders; 032import javax.ws.rs.core.MediaType; 033import javax.ws.rs.core.Response; 034import javax.ws.rs.core.SecurityContext; 035import javax.ws.rs.core.UriInfo; 036 037import java.io.InputStream; 038 039import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_BASE_ID; 040import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_FILTER; 041import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_PAGE_SIZE; 042import static com.unboundid.scim.sdk.SCIMConstants. 043 QUERY_PARAMETER_PAGE_START_INDEX; 044import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_SCOPE; 045import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_SORT_BY; 046import static com.unboundid.scim.sdk.SCIMConstants.QUERY_PARAMETER_SORT_ORDER; 047 048 049 050/** 051 * This class is a Wink dynamic resource implementation for query operations 052 * on a SCIM resource where the client requests XML response format in the URL 053 * by appending ".xml" on to the endpoint. 054 */ 055@Path("{endpoint}.xml") 056public class XMLQueryResource extends AbstractSCIMResource 057{ 058 /** 059 * Create a new SCIM wink resource for XML query operations on a 060 * SCIM endpoint. 061 * 062 * @param application The SCIM JAX-RS application associated with this 063 * resource. 064 * @param tokenHandler The token handler to use for OAuth 065 * authentication. 066 */ 067 public XMLQueryResource(final SCIMApplication application, 068 final OAuthTokenHandler tokenHandler) 069 { 070 super(application, tokenHandler); 071 } 072 073 074 075 /** 076 * Implement the GET operation producing XML format. 077 * 078 * @param endpoint The resource endpoint. 079 * @param request The current HTTP servlet request. 080 * @param securityContext The security context of the current request. 081 * @param headers The request headers. 082 * @param uriInfo The URI info for the request. 083 * @param filterString The filter query parameter, or {@code null}. 084 * @param baseID The SCIM resource ID of the search base entry, 085 * or {@code null}. 086 * @param searchScope The LDAP search scope to use, or {@code null}. 087 * @param sortBy The sortBy query parameter, or {@code null}. 088 * @param sortOrder The sortOrder query parameter, or {@code null}. 089 * @param pageStartIndex The startIndex query parameter, or {@code null}. 090 * @param pageSize The count query parameter, or {@code null}. 091 * 092 * @return The response to the request. 093 */ 094 @GET 095 @Produces(MediaType.APPLICATION_XML) 096 public Response doXmlGet(@PathParam("endpoint") final String endpoint, 097 @Context final HttpServletRequest request, 098 @Context final SecurityContext securityContext, 099 @Context final HttpHeaders headers, 100 @Context final UriInfo uriInfo, 101 @QueryParam(QUERY_PARAMETER_FILTER) 102 final String filterString, 103 @QueryParam(QUERY_PARAMETER_BASE_ID) 104 final String baseID, 105 @QueryParam(QUERY_PARAMETER_SCOPE) 106 final String searchScope, 107 @QueryParam(QUERY_PARAMETER_SORT_BY) 108 final String sortBy, 109 @QueryParam(QUERY_PARAMETER_SORT_ORDER) 110 final String sortOrder, 111 @QueryParam(QUERY_PARAMETER_PAGE_START_INDEX) 112 final String pageStartIndex, 113 @QueryParam(QUERY_PARAMETER_PAGE_SIZE) 114 final String pageSize) 115 { 116 final RequestContext requestContext = 117 new RequestContext(request, securityContext, headers, uriInfo, 118 MediaType.APPLICATION_XML_TYPE, 119 MediaType.APPLICATION_XML_TYPE); 120 121 return getUsers(requestContext, endpoint, filterString, baseID, searchScope, 122 sortBy, sortOrder, pageStartIndex, pageSize); 123 } 124 125 126 127 /** 128 * Implement the POST operation consuming and producing XML format. 129 * 130 * @param inputStream The content to be consumed. 131 * @param endpoint The resource endpoint. 132 * @param request The current HTTP servlet request. 133 * @param securityContext The security context for the request. 134 * @param headers The request headers. 135 * @param uriInfo The URI info for the request. 136 * 137 * @return The response to the request. 138 */ 139 @POST 140 @Consumes(MediaType.APPLICATION_XML) 141 @Produces(MediaType.APPLICATION_XML) 142 public Response doXmlDotXmlPost(final InputStream inputStream, 143 @PathParam("endpoint") final String endpoint, 144 @Context final HttpServletRequest request, 145 @Context final SecurityContext 146 securityContext, 147 @Context final HttpHeaders headers, 148 @Context final UriInfo uriInfo) 149 { 150 final RequestContext requestContext = 151 new RequestContext(request, securityContext, headers, uriInfo, 152 MediaType.APPLICATION_XML_TYPE, 153 MediaType.APPLICATION_XML_TYPE); 154 return postUser(requestContext, endpoint, inputStream); 155 } 156 157 158 159 /** 160 * Implement the POST operation consuming JSON and producing XML format. 161 * 162 * @param inputStream The content to be consumed. 163 * @param endpoint The resource endpoint. 164 * @param request The current HTTP servlet request. 165 * @param securityContext The security context for the request. 166 * @param headers The request headers. 167 * @param uriInfo The URI info for the request. 168 * 169 * @return The response to the request. 170 */ 171 @POST 172 @Consumes(MediaType.APPLICATION_JSON) 173 @Produces(MediaType.APPLICATION_XML) 174 public Response doJsonDotXmlPost(final InputStream inputStream, 175 @PathParam("endpoint") final String endpoint, 176 @Context final HttpServletRequest request, 177 @Context final SecurityContext 178 securityContext, 179 @Context final HttpHeaders headers, 180 @Context final UriInfo uriInfo) 181 { 182 final RequestContext requestContext = 183 new RequestContext(request, securityContext, headers, uriInfo, 184 MediaType.APPLICATION_JSON_TYPE, 185 MediaType.APPLICATION_XML_TYPE); 186 return postUser(requestContext, endpoint, inputStream); 187 } 188}