@Test public void testFind_ErrorIfBothAttributesAndExcludedAttributesExist() { @SuppressWarnings("rawtypes") BaseResourceTypeResourceImpl baseResourceImpl = Mockito.mock(BaseResourceTypeResourceImpl.class); SearchRequest searchRequest = new SearchRequest(); searchRequest.setAttributes(includedAttributeList.getAttributeReferences()); searchRequest.setExcludedAttributes(excludedAttributeList.getAttributeReferences()); when(baseResourceImpl.find(searchRequest)).thenCallRealMethod(); Response response = baseResourceImpl.find(searchRequest); assertTrue(response != null); assertTrue(response.getStatus() == Status.BAD_REQUEST.getStatusCode()); assertTrue(response.getEntity() instanceof ErrorResponse); assertTrue(((ErrorResponse)response.getEntity()).getDetail().equals("Cannot include both attributes and excluded attributes in a single request")); }
@Override public Response find(SearchRequest request) { try { Provider<T> provider = getProviderInternal(); Set<AttributeReference> attributeReferences = Optional.ofNullable(request.getAttributes()) .orElse(Collections.emptySet()); Set<AttributeReference> excludedAttributeReferences = Optional.ofNullable(request.getExcludedAttributes()) .orElse(Collections.emptySet()); if (!attributeReferences.isEmpty() && !excludedAttributeReferences.isEmpty()) { return createAmbiguousAttributeParametersResponse(); } Filter filter = request.getFilter(); PageRequest pageRequest = request.getPageRequest(); SortRequest sortRequest = request.getSortRequest(); ListResponse<T> listResponse = new ListResponse<>(); endpointUtil.process(uriInfo); FilterResponse<T> filterResp = null; try { filterResp = provider.find(filter, pageRequest, sortRequest); } catch (UnableToRetrieveResourceException e1) { log.info("Caught an UnableToRetrieveResourceException " + e1.getMessage() + " : " + e1.getStatus() .toString()); return createGenericExceptionResponse(e1, e1.getStatus()); } catch (Exception e) { log.error("Uncaught provider exception", e); return provider.handleException(e); } if (filterResp == null || filterResp.getResources() == null || filterResp.getResources() .isEmpty()) { listResponse.setTotalResults(0); } else { log.info("Find returned " + filterResp.getResources() .size()); listResponse.setItemsPerPage(filterResp.getResources() .size()); listResponse.setStartIndex(1); listResponse.setTotalResults(filterResp.getResources() .size()); List<T> results = new ArrayList<>(); for (T resource : filterResp.getResources()) { EntityTag etag = null; try { etag = etagGenerator.generateEtag(resource); } catch (JsonProcessingException | NoSuchAlgorithmException | UnsupportedEncodingException e) { return createETagErrorResponse(); } try { log.info("=== Calling processFilterAttributeExtensions"); resource = processFilterAttributeExtensions(provider, resource, attributeReferences, excludedAttributeReferences); } catch (ClientFilterException e1) { ErrorResponse er = new ErrorResponse(e1.getStatus(), e1.getMessage()); return er.toResponse(); } try { if (!excludedAttributeReferences.isEmpty()) { resource = attributeUtil.setExcludedAttributesForDisplay(resource, excludedAttributeReferences); } else { resource = attributeUtil.setAttributesForDisplay(resource, attributeReferences); } results.add(resource); } catch (IllegalArgumentException | IllegalAccessException | AttributeDoesNotExistException | IOException e) { return createAttriubteProcessingErrorResponse(e); } } listResponse.setResources(results); } return Response.ok() .entity(listResponse) .build(); } catch (ScimServerException sse) { LOG.error("Error Processing SCIM Request", sse); return sse.getErrorResponse() .toResponse(); } }
BaseResourceTypeResourceImpl implements BaseResourceTypeResource<T> { @Override public Response find(SearchRequest request) { try { Provider<T> provider = getProviderInternal(); Set<AttributeReference> attributeReferences = Optional.ofNullable(request.getAttributes()) .orElse(Collections.emptySet()); Set<AttributeReference> excludedAttributeReferences = Optional.ofNullable(request.getExcludedAttributes()) .orElse(Collections.emptySet()); if (!attributeReferences.isEmpty() && !excludedAttributeReferences.isEmpty()) { return createAmbiguousAttributeParametersResponse(); } Filter filter = request.getFilter(); PageRequest pageRequest = request.getPageRequest(); SortRequest sortRequest = request.getSortRequest(); ListResponse<T> listResponse = new ListResponse<>(); endpointUtil.process(uriInfo); FilterResponse<T> filterResp = null; try { filterResp = provider.find(filter, pageRequest, sortRequest); } catch (UnableToRetrieveResourceException e1) { log.info("Caught an UnableToRetrieveResourceException " + e1.getMessage() + " : " + e1.getStatus() .toString()); return createGenericExceptionResponse(e1, e1.getStatus()); } catch (Exception e) { log.error("Uncaught provider exception", e); return provider.handleException(e); } if (filterResp == null || filterResp.getResources() == null || filterResp.getResources() .isEmpty()) { listResponse.setTotalResults(0); } else { log.info("Find returned " + filterResp.getResources() .size()); listResponse.setItemsPerPage(filterResp.getResources() .size()); listResponse.setStartIndex(1); listResponse.setTotalResults(filterResp.getResources() .size()); List<T> results = new ArrayList<>(); for (T resource : filterResp.getResources()) { EntityTag etag = null; try { etag = etagGenerator.generateEtag(resource); } catch (JsonProcessingException | NoSuchAlgorithmException | UnsupportedEncodingException e) { return createETagErrorResponse(); } try { log.info("=== Calling processFilterAttributeExtensions"); resource = processFilterAttributeExtensions(provider, resource, attributeReferences, excludedAttributeReferences); } catch (ClientFilterException e1) { ErrorResponse er = new ErrorResponse(e1.getStatus(), e1.getMessage()); return er.toResponse(); } try { if (!excludedAttributeReferences.isEmpty()) { resource = attributeUtil.setExcludedAttributesForDisplay(resource, excludedAttributeReferences); } else { resource = attributeUtil.setAttributesForDisplay(resource, attributeReferences); } results.add(resource); } catch (IllegalArgumentException | IllegalAccessException | AttributeDoesNotExistException | IOException e) { return createAttriubteProcessingErrorResponse(e); } } listResponse.setResources(results); } return Response.ok() .entity(listResponse) .build(); } catch (ScimServerException sse) { LOG.error("Error Processing SCIM Request", sse); return sse.getErrorResponse() .toResponse(); } } }
BaseResourceTypeResourceImpl implements BaseResourceTypeResource<T> { @Override public Response find(SearchRequest request) { try { Provider<T> provider = getProviderInternal(); Set<AttributeReference> attributeReferences = Optional.ofNullable(request.getAttributes()) .orElse(Collections.emptySet()); Set<AttributeReference> excludedAttributeReferences = Optional.ofNullable(request.getExcludedAttributes()) .orElse(Collections.emptySet()); if (!attributeReferences.isEmpty() && !excludedAttributeReferences.isEmpty()) { return createAmbiguousAttributeParametersResponse(); } Filter filter = request.getFilter(); PageRequest pageRequest = request.getPageRequest(); SortRequest sortRequest = request.getSortRequest(); ListResponse<T> listResponse = new ListResponse<>(); endpointUtil.process(uriInfo); FilterResponse<T> filterResp = null; try { filterResp = provider.find(filter, pageRequest, sortRequest); } catch (UnableToRetrieveResourceException e1) { log.info("Caught an UnableToRetrieveResourceException " + e1.getMessage() + " : " + e1.getStatus() .toString()); return createGenericExceptionResponse(e1, e1.getStatus()); } catch (Exception e) { log.error("Uncaught provider exception", e); return provider.handleException(e); } if (filterResp == null || filterResp.getResources() == null || filterResp.getResources() .isEmpty()) { listResponse.setTotalResults(0); } else { log.info("Find returned " + filterResp.getResources() .size()); listResponse.setItemsPerPage(filterResp.getResources() .size()); listResponse.setStartIndex(1); listResponse.setTotalResults(filterResp.getResources() .size()); List<T> results = new ArrayList<>(); for (T resource : filterResp.getResources()) { EntityTag etag = null; try { etag = etagGenerator.generateEtag(resource); } catch (JsonProcessingException | NoSuchAlgorithmException | UnsupportedEncodingException e) { return createETagErrorResponse(); } try { log.info("=== Calling processFilterAttributeExtensions"); resource = processFilterAttributeExtensions(provider, resource, attributeReferences, excludedAttributeReferences); } catch (ClientFilterException e1) { ErrorResponse er = new ErrorResponse(e1.getStatus(), e1.getMessage()); return er.toResponse(); } try { if (!excludedAttributeReferences.isEmpty()) { resource = attributeUtil.setExcludedAttributesForDisplay(resource, excludedAttributeReferences); } else { resource = attributeUtil.setAttributesForDisplay(resource, attributeReferences); } results.add(resource); } catch (IllegalArgumentException | IllegalAccessException | AttributeDoesNotExistException | IOException e) { return createAttriubteProcessingErrorResponse(e); } } listResponse.setResources(results); } return Response.ok() .entity(listResponse) .build(); } catch (ScimServerException sse) { LOG.error("Error Processing SCIM Request", sse); return sse.getErrorResponse() .toResponse(); } }  }
BaseResourceTypeResourceImpl implements BaseResourceTypeResource<T> { @Override public Response find(SearchRequest request) { try { Provider<T> provider = getProviderInternal(); Set<AttributeReference> attributeReferences = Optional.ofNullable(request.getAttributes()) .orElse(Collections.emptySet()); Set<AttributeReference> excludedAttributeReferences = Optional.ofNullable(request.getExcludedAttributes()) .orElse(Collections.emptySet()); if (!attributeReferences.isEmpty() && !excludedAttributeReferences.isEmpty()) { return createAmbiguousAttributeParametersResponse(); } Filter filter = request.getFilter(); PageRequest pageRequest = request.getPageRequest(); SortRequest sortRequest = request.getSortRequest(); ListResponse<T> listResponse = new ListResponse<>(); endpointUtil.process(uriInfo); FilterResponse<T> filterResp = null; try { filterResp = provider.find(filter, pageRequest, sortRequest); } catch (UnableToRetrieveResourceException e1) { log.info("Caught an UnableToRetrieveResourceException " + e1.getMessage() + " : " + e1.getStatus() .toString()); return createGenericExceptionResponse(e1, e1.getStatus()); } catch (Exception e) { log.error("Uncaught provider exception", e); return provider.handleException(e); } if (filterResp == null || filterResp.getResources() == null || filterResp.getResources() .isEmpty()) { listResponse.setTotalResults(0); } else { log.info("Find returned " + filterResp.getResources() .size()); listResponse.setItemsPerPage(filterResp.getResources() .size()); listResponse.setStartIndex(1); listResponse.setTotalResults(filterResp.getResources() .size()); List<T> results = new ArrayList<>(); for (T resource : filterResp.getResources()) { EntityTag etag = null; try { etag = etagGenerator.generateEtag(resource); } catch (JsonProcessingException | NoSuchAlgorithmException | UnsupportedEncodingException e) { return createETagErrorResponse(); } try { log.info("=== Calling processFilterAttributeExtensions"); resource = processFilterAttributeExtensions(provider, resource, attributeReferences, excludedAttributeReferences); } catch (ClientFilterException e1) { ErrorResponse er = new ErrorResponse(e1.getStatus(), e1.getMessage()); return er.toResponse(); } try { if (!excludedAttributeReferences.isEmpty()) { resource = attributeUtil.setExcludedAttributesForDisplay(resource, excludedAttributeReferences); } else { resource = attributeUtil.setAttributesForDisplay(resource, attributeReferences); } results.add(resource); } catch (IllegalArgumentException | IllegalAccessException | AttributeDoesNotExistException | IOException e) { return createAttriubteProcessingErrorResponse(e); } } listResponse.setResources(results); } return Response.ok() .entity(listResponse) .build(); } catch (ScimServerException sse) { LOG.error("Error Processing SCIM Request", sse); return sse.getErrorResponse() .toResponse(); } }  abstract Provider<T> getProvider(); @Override Response getById(String id, AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response query(AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes, FilterWrapper filter, AttributeReference sortBy, SortOrder sortOrder, Integer startIndex, Integer count); @Override Response create(T resource, AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response find(SearchRequest request); @Override Response update(T resource, String id, AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response patch(PatchRequest patchRequest, String id, AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response delete(String id); static Response createGenericExceptionResponse(Throwable e1, Status status); }
BaseResourceTypeResourceImpl implements BaseResourceTypeResource<T> { @Override public Response find(SearchRequest request) { try { Provider<T> provider = getProviderInternal(); Set<AttributeReference> attributeReferences = Optional.ofNullable(request.getAttributes()) .orElse(Collections.emptySet()); Set<AttributeReference> excludedAttributeReferences = Optional.ofNullable(request.getExcludedAttributes()) .orElse(Collections.emptySet()); if (!attributeReferences.isEmpty() && !excludedAttributeReferences.isEmpty()) { return createAmbiguousAttributeParametersResponse(); } Filter filter = request.getFilter(); PageRequest pageRequest = request.getPageRequest(); SortRequest sortRequest = request.getSortRequest(); ListResponse<T> listResponse = new ListResponse<>(); endpointUtil.process(uriInfo); FilterResponse<T> filterResp = null; try { filterResp = provider.find(filter, pageRequest, sortRequest); } catch (UnableToRetrieveResourceException e1) { log.info("Caught an UnableToRetrieveResourceException " + e1.getMessage() + " : " + e1.getStatus() .toString()); return createGenericExceptionResponse(e1, e1.getStatus()); } catch (Exception e) { log.error("Uncaught provider exception", e); return provider.handleException(e); } if (filterResp == null || filterResp.getResources() == null || filterResp.getResources() .isEmpty()) { listResponse.setTotalResults(0); } else { log.info("Find returned " + filterResp.getResources() .size()); listResponse.setItemsPerPage(filterResp.getResources() .size()); listResponse.setStartIndex(1); listResponse.setTotalResults(filterResp.getResources() .size()); List<T> results = new ArrayList<>(); for (T resource : filterResp.getResources()) { EntityTag etag = null; try { etag = etagGenerator.generateEtag(resource); } catch (JsonProcessingException | NoSuchAlgorithmException | UnsupportedEncodingException e) { return createETagErrorResponse(); } try { log.info("=== Calling processFilterAttributeExtensions"); resource = processFilterAttributeExtensions(provider, resource, attributeReferences, excludedAttributeReferences); } catch (ClientFilterException e1) { ErrorResponse er = new ErrorResponse(e1.getStatus(), e1.getMessage()); return er.toResponse(); } try { if (!excludedAttributeReferences.isEmpty()) { resource = attributeUtil.setExcludedAttributesForDisplay(resource, excludedAttributeReferences); } else { resource = attributeUtil.setAttributesForDisplay(resource, attributeReferences); } results.add(resource); } catch (IllegalArgumentException | IllegalAccessException | AttributeDoesNotExistException | IOException e) { return createAttriubteProcessingErrorResponse(e); } } listResponse.setResources(results); } return Response.ok() .entity(listResponse) .build(); } catch (ScimServerException sse) { LOG.error("Error Processing SCIM Request", sse); return sse.getErrorResponse() .toResponse(); } }  abstract Provider<T> getProvider(); @Override Response getById(String id, AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response query(AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes, FilterWrapper filter, AttributeReference sortBy, SortOrder sortOrder, Integer startIndex, Integer count); @Override Response create(T resource, AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response find(SearchRequest request); @Override Response update(T resource, String id, AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response patch(PatchRequest patchRequest, String id, AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response delete(String id); static Response createGenericExceptionResponse(Throwable e1, Status status);  }