List of usage examples for org.springframework.http HttpStatus FORBIDDEN
HttpStatus FORBIDDEN
To view the source code for org.springframework.http HttpStatus FORBIDDEN.
Click Source Link
From source file:org.tightblog.ui.restapi.WeblogController.java
private ResponseEntity checkIfOwnerOfValidWeblog(String weblogId, Principal p) { Weblog weblog = weblogRepository.findById(weblogId).orElse(null); if (weblog != null) { if (userManager.checkWeblogRole(p.getName(), weblog, WeblogRole.OWNER)) { return null; } else {/* w w w .ja v a 2 s .co m*/ return new ResponseEntity<>(HttpStatus.FORBIDDEN); } } else { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } }
From source file:org.venice.beachfront.bfapi.services.GeoServerProxyService.java
public ResponseEntity<byte[]> proxyRequest(HttpServletRequest request) throws MalformedURLException, IOException, URISyntaxException, UserException { String requestPath = request.getRequestURI(); // Form the complete URI by piecing together the GeoServer URL with the API proxy request parameters URI requestUri = new URI(geoserverUrl.getProtocol(), null, geoserverUrl.getHost(), geoserverUrl.getPort(), requestPath, request.getQueryString(), null); // Double encoding takes place here. First, in the REST Request delivered to API by the client. Second, in the // translation to the URI object. Decode both of these steps to get the real, completely decoded request to // GeoServer. String decodedUrl = URLDecoder.decode(requestUri.toString(), "UTF-8"); decodedUrl = URLDecoder.decode(decodedUrl.toString(), "UTF-8"); piazzaLogger.log(String.format("Proxying request to GET GeoServer at URI %s", decodedUrl), Severity.INFORMATIONAL); try {// w w w . j a va 2 s. c om ResponseEntity<byte[]> response = restTemplate.exchange(decodedUrl, HttpMethod.GET, requestHeaders, byte[].class); return response; } catch (HttpClientErrorException | HttpServerErrorException exception) { piazzaLogger.log(String.format("Received GeoServer error response, code=%d, length=%d, for URI %s", exception.getStatusCode().value(), exception.getResponseBodyAsString().length(), decodedUrl), Severity.ERROR); if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED) || exception.getStatusCode().equals(HttpStatus.FORBIDDEN)) { throw new UserException("Bad Authentication with GeoServer", exception, exception.getResponseBodyAsString(), HttpStatus.BAD_REQUEST); } throw new UserException("Upstream GeoServer error", exception, exception.getResponseBodyAsString(), exception.getStatusCode()); } }
From source file:org.venice.beachfront.bfapi.services.IABrokerPassthroughService.java
public ResponseEntity<String> passthroughRequest(HttpMethod method, HttpServletRequest request) throws MalformedURLException, IOException, URISyntaxException, UserException { // URI to ia-Broker will strip out the /ia prefix that the bf-api uses to denote ia-broker proxying // Single data source right now, which is planet. In the future, we will switch on the sensor/item type to // determine the source (or have the source just injected) String requestPath = request.getRequestURI().replaceAll("/ia/", "/"); URI uri = new URI(IA_BROKER_PROTOCOL, null, IA_BROKER_SERVER, IA_BROKER_PORT, requestPath, request.getQueryString(), null); String body = IOUtils.toString(request.getReader()); piazzaLogger.log(String.format("Proxying request to IA Broker at URI %s", uri.toString()), Severity.INFORMATIONAL); try {/*from w w w.j a v a 2 s. co m*/ ResponseEntity<String> response = restTemplate.exchange(uri, method, new HttpEntity<String>(body), String.class); piazzaLogger.log( String.format("Received IA Broker response, code=%d, length=%d, for URI %s", response.getStatusCodeValue(), response.getBody() == null ? 0 : response.getBody().length(), uri.toString()), Severity.INFORMATIONAL); return response; } catch (HttpClientErrorException | HttpServerErrorException exception) { piazzaLogger.log(String.format("Received IA Broker error response, code=%d, length=%d, for URI %s", exception.getStatusCode().value(), exception.getResponseBodyAsString().length(), uri.toString()), Severity.ERROR); if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED) || exception.getStatusCode().equals(HttpStatus.FORBIDDEN)) { throw new UserException(exception.getResponseBodyAsString(), exception, exception.getResponseBodyAsString(), HttpStatus.PRECONDITION_FAILED); } throw new UserException("Upstream image broker error", exception, exception.getResponseBodyAsString(), exception.getStatusCode()); } }
From source file:sg.ncl.DataController.java
private ResponseEntity<String> getStringResponseEntity(ExceptionState exceptionState) { switch (exceptionState) { case DATA_NOT_FOUND_EXCEPTION: log.warn("Dataset not found for uploading resource."); return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Dataset not found for uploading resource."); case DATA_RESOURCE_ALREADY_EXISTS_EXCEPTION: log.warn("Data resource already exist."); return ResponseEntity.status(HttpStatus.CONFLICT).body("Data resource already exist"); case FORBIDDEN_EXCEPTION: log.warn("Uploading of dataset resource forbidden."); return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Uploading of dataset resource forbidden."); case UPLOAD_ALREADY_EXISTS_EXCEPTION: log.warn("Upload of data resource already exist."); return ResponseEntity.status(HttpStatus.CONFLICT).body("Upload of data resource already exist."); default://from w w w . ja v a 2s. c o m log.warn("Unknown exception while uploading resource."); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body("Unknown exception while uploading resource."); } }