List of usage examples for javax.servlet.http HttpServletResponse SC_FORBIDDEN
int SC_FORBIDDEN
To view the source code for javax.servlet.http HttpServletResponse SC_FORBIDDEN.
Click Source Link
From source file:com.mirth.connect.server.servlets.ChannelStatisticsServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {/* ww w . j av a 2 s. co m*/ try { ChannelStatisticsController statisticsController = ControllerFactory.getFactory() .createChannelStatisticsController(); ObjectXMLSerializer serializer = new ObjectXMLSerializer(); PrintWriter out = response.getWriter(); Operation operation = Operations.getOperation(request.getParameter("op")); String channelId = request.getParameter("id"); Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("channelId", channelId); if (operation.equals(Operations.CHANNEL_STATS_GET)) { if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { response.setContentType(APPLICATION_XML); serializer.toXML(statisticsController.getStatistics(channelId), out); } } else if (operation.equals(Operations.CHANNEL_STATS_CLEAR)) { if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { boolean deleteReceived = Boolean.valueOf(request.getParameter("deleteReceived")); boolean deleteFiltered = Boolean.valueOf(request.getParameter("deleteFiltered")); boolean deleteQueued = Boolean.valueOf(request.getParameter("deleteQueued")); boolean deleteSent = Boolean.valueOf(request.getParameter("deleteSent")); boolean deleteErrored = Boolean.valueOf(request.getParameter("deleteErrored")); boolean deleteAlerted = Boolean.valueOf(request.getParameter("deleteAlerted")); statisticsController.clearStatistics(channelId, deleteReceived, deleteFiltered, deleteQueued, deleteSent, deleteErrored, deleteAlerted); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }
From source file:com.thinkberg.webdav.GetHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = VFSBackend.resolveFile(request.getPathInfo()); if (object.exists()) { if (FileType.FOLDER.equals(object.getType())) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; }/*from ww w .ja va 2 s .c o m*/ setHeader(response, object.getContent()); InputStream is = object.getContent().getInputStream(); OutputStream os = response.getOutputStream(); Util.copyStream(is, os); is.close(); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } }
From source file:fr.aliasource.webmail.server.DownloadEmlImpl.java
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { IAccount account = (IAccount) req.getSession().getAttribute("account"); if (account == null) { resp.sendError(HttpServletResponse.SC_FORBIDDEN); return;/*from w ww . ja v a 2 s . co m*/ } String emlId = req.getParameter("emlId"); String folderName = req.getParameter("folderName"); logger.info("[" + account.getLogin() + "] " + "download eml with id: " + emlId); InputStream in = account.downloadEml(folderName, emlId); resp.setHeader("Content-Disposition", "application/force-download; filename=\"email.eml\""); resp.setHeader("Content-Transfer-Encoding", "binary"); resp.setHeader("Content-Type", "application/force-download; name=\"email.eml\""); OutputStream out = resp.getOutputStream(); int size = transfer(in, out, true); resp.setHeader("Content-Length", "" + size); }
From source file:com.mirth.connect.server.servlets.EngineServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {/*from w w w . j av a 2 s . com*/ try { EngineController engineController = ControllerFactory.getFactory().createEngineController(); ObjectXMLSerializer serializer = new ObjectXMLSerializer(); Operation operation = Operations.getOperation(request.getParameter("op")); Map<String, Object> parameterMap = new HashMap<String, Object>(); ServerEventContext context = new ServerEventContext(); context.setUserId(getCurrentUserId(request)); if (operation.equals(Operations.CHANNEL_REDEPLOY)) { if (!isUserAuthorized(request, null) || doesUserHaveChannelRestrictions(request)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { engineController.redeployAllChannels(context); } } else if (operation.equals(Operations.CHANNEL_DEPLOY)) { List<String> channelIds = (List<String>) serializer.fromXML(request.getParameter("channelIds")); parameterMap.put("channelIds", channelIds); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { engineController.deployChannels(channelIds, context); } } else if (operation.equals(Operations.CHANNEL_UNDEPLOY)) { List<String> channelIds = (List<String>) serializer.fromXML(request.getParameter("channelIds")); parameterMap.put("channelIds", channelIds); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { engineController.undeployChannels(channelIds, context); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }
From source file:org.cloudfoundry.identity.uaa.error.JsonAwareAccessDeniedHandlerTests.java
@Test public void testCommenceWithJson() throws Exception { request.addHeader("Accept", MediaType.APPLICATION_JSON_VALUE); entryPoint.handle(request, response, new AccessDeniedException("Bad")); assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus()); assertEquals("{\"error\":\"Bad\"}", response.getContentAsString()); assertEquals(null, response.getErrorMessage()); }
From source file:com.mirth.connect.server.servlets.AlertServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {//from ww w. j av a2 s . com try { AlertController alertController = ControllerFactory.getFactory().createAlertController(); ObjectXMLSerializer serializer = new ObjectXMLSerializer(); PrintWriter out = response.getWriter(); Operation operation = Operations.getOperation(request.getParameter("op")); Map<String, Object> parameterMap = new HashMap<String, Object>(); if (operation.equals(Operations.ALERT_GET)) { Alert alert = (Alert) serializer.fromXML(request.getParameter("alert")); parameterMap.put("alert", alert); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { response.setContentType(APPLICATION_XML); serializer.toXML(alertController.getAlert(alert), out); } } else if (operation.equals(Operations.ALERT_UPDATE)) { List<Alert> alerts = (List<Alert>) serializer.fromXML(request.getParameter("alerts")); parameterMap.put("alerts", alerts); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { alertController.updateAlerts(alerts); } } else if (operation.equals(Operations.ALERT_REMOVE)) { Alert alert = (Alert) serializer.fromXML(request.getParameter("alert")); parameterMap.put("alert", alert); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { alertController.removeAlert(alert); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }
From source file:com.mirth.connect.server.servlets.CodeTemplateServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {//from w w w . j av a 2 s . c o m try { CodeTemplateController codeTemplateController = ControllerFactory.getFactory() .createCodeTemplateController(); ObjectXMLSerializer serializer = new ObjectXMLSerializer(); PrintWriter out = response.getWriter(); Operation operation = Operations.getOperation(request.getParameter("op")); Map<String, Object> parameterMap = new HashMap<String, Object>(); if (operation.equals(Operations.CODE_TEMPLATE_GET)) { CodeTemplate codeTemplate = (CodeTemplate) serializer .fromXML(request.getParameter("codeTemplate")); parameterMap.put("codeTemplate", codeTemplate); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { response.setContentType(APPLICATION_XML); serializer.toXML(codeTemplateController.getCodeTemplate(codeTemplate), out); } } else if (operation.equals(Operations.CODE_TEMPLATE_UPDATE)) { List<CodeTemplate> codeTemplates = (List<CodeTemplate>) serializer .fromXML(request.getParameter("codeTemplates")); parameterMap.put("codeTemplates", codeTemplates); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { codeTemplateController.updateCodeTemplates(codeTemplates); } } else if (operation.equals(Operations.CODE_TEMPLATE_REMOVE)) { CodeTemplate codeTemplate = (CodeTemplate) serializer .fromXML(request.getParameter("codeTemplate")); parameterMap.put("codeTemplate", codeTemplate); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { codeTemplateController.removeCodeTemplate(codeTemplate); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }
From source file:fr.aliasource.webmail.server.DownloadAttachmentsImpl.java
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { IAccount account = (IAccount) req.getSession().getAttribute("account"); if (account == null) { resp.sendError(HttpServletResponse.SC_FORBIDDEN); return;// ww w .j a v a 2s .c o m } String[] items = req.getRequestURI().split("/"); String atId = null; boolean dl = false; boolean preview = false; for (String s : items) { if (s.startsWith("at_")) { atId = s; } else if (s.equals("download")) { dl = true; } else if (s.equals("preview")) { dl = false; preview = true; } } logger.info("[" + account.getLogin() + "] " + (dl ? "download" : "view") + " of attachment id: " + atId + " uri: " + req.getRequestURI().split("/")); AttachmentMetadata[] metas = account.getAttachementsMetadata(new String[] { atId }); if (!preview) { resp.setHeader("Content-Type", (dl ? "application/octet-stream" : metas[0].getMime())); } else { resp.setHeader("Content-Type", metas[0].getPreviewMime()); } if (!preview) { resp.setHeader("Content-Length", "" + metas[0].getSize()); } OutputStream out = resp.getOutputStream(); InputStream in = account.downloadAttachement(atId + (preview ? ".preview" : "")); transfer(in, out, true); }
From source file:com.mirth.connect.server.servlets.ChannelStatusServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {/*from w ww. ja va 2s . c o m*/ try { ChannelStatusController channelStatusController = ControllerFactory.getFactory() .createChannelStatusController(); ObjectXMLSerializer serializer = new ObjectXMLSerializer(); PrintWriter out = response.getWriter(); Operation operation = Operations.getOperation(request.getParameter("op")); String channelId = request.getParameter("id"); Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("channelId", channelId); if (operation.equals(Operations.CHANNEL_START)) { if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { channelStatusController.startChannel(channelId); } } else if (operation.equals(Operations.CHANNEL_STOP)) { if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { channelStatusController.stopChannel(channelId); } } else if (operation.equals(Operations.CHANNEL_PAUSE)) { if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { channelStatusController.pauseChannel(channelId); } } else if (operation.equals(Operations.CHANNEL_RESUME)) { if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { channelStatusController.resumeChannel(channelId); } } else if (operation.equals(Operations.CHANNEL_GET_STATUS)) { response.setContentType(APPLICATION_XML); List<ChannelStatus> channelStatuses = null; if (!isUserAuthorized(request, null)) { channelStatuses = new ArrayList<ChannelStatus>(); } else if (doesUserHaveChannelRestrictions(request)) { channelStatuses = redactChannelStatuses(request, channelStatusController.getChannelStatusList()); } else { channelStatuses = channelStatusController.getChannelStatusList(); } serializer.toXML(channelStatuses, out); } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }
From source file:com.mirth.connect.server.servlets.DatabaseTaskServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // MIRTH-1745 response.setCharacterEncoding("UTF-8"); if (!isUserLoggedIn(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } else {//w w w .j a v a 2s . co m try { DatabaseTaskController databaseTaskController = ControllerFactory.getFactory() .createDatabaseTaskController(); ObjectXMLSerializer serializer = ObjectXMLSerializer.getInstance(); PrintWriter out = response.getWriter(); Operation operation = Operations.getOperation(request.getParameter("op")); Map<String, Object> parameterMap = new HashMap<String, Object>(); ServerEventContext context = new ServerEventContext(); context.setUserId(getCurrentUserId(request)); if (operation.equals(Operations.DATABASE_TASKS_GET)) { if (!isUserAuthorized(request, null)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { serializer.serialize(databaseTaskController.getDatabaseTasks(), out); } } else if (operation.equals(Operations.DATABASE_TASK_RUN)) { DatabaseTask databaseTask = serializer .deserialize((String) request.getParameter("databaseTask"), DatabaseTask.class); parameterMap.put("databaseTask", databaseTask); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { String result = databaseTaskController.runDatabaseTask(databaseTask); if (StringUtils.isNotBlank(result)) { out.write(result); } } } else if (operation.equals(Operations.DATABASE_TASK_CANCEL)) { DatabaseTask databaseTask = serializer .deserialize((String) request.getParameter("databaseTask"), DatabaseTask.class); parameterMap.put("databaseTask", databaseTask); if (!isUserAuthorized(request, parameterMap)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { databaseTaskController.cancelDatabaseTask(databaseTask); } } } catch (RuntimeIOException rio) { logger.debug(rio); } catch (Throwable t) { logger.error(ExceptionUtils.getStackTrace(t)); throw new ServletException(t); } } }