List of usage examples for java.rmi ServerException ServerException
public ServerException(String s)
ServerException
with the specified detail message. From source file:net.tirasa.saml.Consumer.java
/** * Processes AuthNResponses and LogoutRequests only. * * @param request servlet request/*from ww w .j a v a 2 s .c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs * @throws DotDataException */ protected void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException, DotDataException { response.setContentType("text/html;charset=UTF-8"); String spEntityId = request.getRequestURL().toString(); spEntityId = spEntityId.substring(0, spEntityId.indexOf(Properties.getString(Constants.SAML_URL_SERVLET_PREFIX))) + "/"; final String responseMessage = request.getParameter(Constants.SAML_AUTHN_RESPONSE_PARAMETER_NAME); final String requestMessage = request.getParameter(Constants.SAML_AUTHN_REQUEST_PARAMETER_NAME); if (StringUtils.isNotBlank(responseMessage)) { Logger.debug(Consumer.class, "Check for SSO response: " + responseMessage); ssoResonse(request, response, spEntityId); } else if (StringUtils.isNotBlank(requestMessage)) { Logger.debug(Consumer.class, "Check for SLO request: " + requestMessage); sloRequest(request, response, spEntityId); } else { Logger.warn(Consumer.class, "Received empty message"); throw new ServerException("Received message is invalid"); } }
From source file:org.apache.syncope.core.rest.cxf.WADLServlet.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//from w ww.ja v a 2s . co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { Matcher schemaMatcher = SCHEMA_PATTERN.matcher(request.getServletPath()); WadlGenerator wadlGenerator = ApplicationContextProvider.getApplicationContext() .getBean(WadlGenerator.class); String wadl = wadlGenerator.getWadl(); Pipeline<SAXPipelineComponent> pipeline = new CachingPipeline<>(); pipeline.addComponent(new XMLGenerator(wadl)); if ("/index.html".equals(request.getServletPath())) { XSLTTransformer xslt = new XSLTTransformer(getClass().getResource("/wadl2html/index.xsl")); Map<String, Object> parameters = new HashMap<>(); parameters.put("contextPath", request.getContextPath()); xslt.setParameters(parameters); pipeline.addComponent(xslt); finish(pipeline, response); } else if (schemaMatcher.matches()) { XSLTTransformer xslt = new XSLTTransformer(getClass().getResource("/wadl2html/schema.xsl")); Map<String, Object> parameters = new HashMap<>(); parameters.put("contextPath", request.getContextPath()); parameters.put("schema-position", schemaMatcher.group(1)); parameters.put("schema-prefix", schemaMatcher.group(2)); xslt.setParameters(parameters); pipeline.addComponent(xslt); finish(pipeline, response); } else if ("/syncope.wadl".equals(request.getServletPath())) { response.setContentType(MediaType.APPLICATION_XML); try (InputStream in = new ByteArrayInputStream(wadl.getBytes()); OutputStream out = response.getOutputStream()) { IOUtils.copy(in, out); } } else { throw new ServerException("URL not supported: " + request.getRequestURI()); } }
From source file:com.esri.gpt.sdisuite.IntegrationLinkServlet.java
/** * Processes a click on a resource link. * @param request the HTTP request/*from w ww. j a va2s .c om*/ * @param response HTTP response * @throws ServletException if an exception occurs * @throws IOException if an I/O exception occurs */ private void executeClick(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOGGER.finer("Processing resource link click..."); // initialize parameters String act = request.getParameter("act"); String fwd = request.getParameter("fwd"); String resourceUrl = null; String addToMapHint = null; // determine the resource URL to be checked if (act != null) { if (act.equals("open")) { resourceUrl = fwd; } else if (act.equals("preview")) { Map<String, String> params = this.gatherParams(fwd); resourceUrl = params.get("url"); } else if (act.equals("addToMap")) { Map<String, String> params = this.gatherParams(fwd); resourceUrl = params.get("resource"); if ((resourceUrl != null) && (resourceUrl.length() > 0)) { if (!resourceUrl.toLowerCase().startsWith("http")) { int idx = resourceUrl.indexOf(":"); if (idx != -1) { addToMapHint = resourceUrl.substring(0, idx); resourceUrl = resourceUrl.substring(idx + 1); } } } } else { resourceUrl = fwd; } } // check the resource URL if ((resourceUrl != null) && (resourceUrl.length() > 0)) { LOGGER.finer("Checking resource URL: " + resourceUrl); RequestContext rc = null; String samlToken = null; try { rc = RequestContext.extract(request); User user = rc.getUser(); IntegrationResponse resp = null; IntegrationContextFactory icf = new IntegrationContextFactory(); if (icf.isIntegrationEnabled()) { IntegrationContext ic = icf.newIntegrationContext(); if (ic != null) { resp = ic.checkUrl(resourceUrl, user, null, null, null); if ((resp != null) && resp.isLicensed()) { if ((user != null) && (user.getProfile() != null)) { if (user.getProfile().containsKey(SDI_SECURITY_TOKEN)) { samlToken = ic.getBase64EncodedToken(user); } } } } } // handle a licensed URL if ((resp != null) && resp.isLicensed()) { String wssUrl = resp.getUrl(); String licenseSelectionUrl = resp.getLicenseSelectionClientUrl(); if ((licenseSelectionUrl != null) && (licenseSelectionUrl.length() > 0) && (wssUrl != null) && (wssUrl.length() > 0)) { // save resource URL parameters String wssUrlParams = null; int idx = wssUrl.indexOf("?"); if (idx != -1) { wssUrlParams = wssUrl.substring(idx + 1).trim(); wssUrl = wssUrl.substring(0, idx); } // make the callback URL String callbackUrl = RequestContext.resolveBaseContextPath(request) + "/link"; callbackUrl += "?lcb=" + URLEncoder.encode("true", "UTF-8"); callbackUrl += "&act=" + URLEncoder.encode(act, "UTF-8"); callbackUrl += "&fwd=" + URLEncoder.encode(fwd, "UTF-8"); if ((wssUrlParams != null) && (wssUrlParams.length() > 0)) { callbackUrl += "&rqs=" + URLEncoder.encode(wssUrlParams, "UTF-8"); } if ((addToMapHint != null) && (addToMapHint.length() > 0)) { callbackUrl += "&atmh=" + URLEncoder.encode(addToMapHint, "UTF-8"); } // make the full license selection URL (can set &embedded=true) licenseSelectionUrl += "?WSS=" + URLEncoder.encode(wssUrl, "UTF-8"); licenseSelectionUrl += "&returnURL=" + URLEncoder.encode(callbackUrl, "UTF-8"); // if user is logged in, // return an HTML response that immediately posts the SAML token to the license selection URL // else // forward to the licenseSelectionUrl if ((samlToken != null) && (samlToken.length() > 0)) { LOGGER.finer("Sending POST redirect with token to: " + licenseSelectionUrl); fwd = null; String title = "License redirect SSO page"; StringBuilder sbHtml = new StringBuilder(); sbHtml.append( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); sbHtml.append( "\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">"); sbHtml.append("\r\n<head>"); sbHtml.append("\r\n<title>").append(Val.escapeXmlForBrowser(title)).append("</title>"); sbHtml.append( "\r\n<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"/>"); sbHtml.append( "\r\n<meta http-equiv=\"Expires\" content=\"Mon, 01 Jan 1990 00:00:01 GMT\"/>"); sbHtml.append("\r\n<meta http-equiv=\"pragma\" content=\"no-cache\"/>"); sbHtml.append("\r\n<meta http-equiv=\"cache-control\" content=\"no-cache\"/>"); sbHtml.append("\r\n<meta name=\"robots\" content=\"noindex\"/>"); sbHtml.append("\r\n</head>"); sbHtml.append("\r\n<body onload=\"document.forms[0].submit();\">"); sbHtml.append("\r\n<form method=\"post\" action=\"") .append(Val.escapeXmlForBrowser(licenseSelectionUrl)).append("\">"); sbHtml.append("\r\n<input type=\"hidden\" name=\"ticket\" value=\"") .append(Val.escapeXmlForBrowser(samlToken)).append("\"/>"); sbHtml.append("\r\n</form>"); sbHtml.append("\r\n</body>"); sbHtml.append("\r\n</html>"); this.writeCharacterResponse(response, sbHtml.toString(), "UTF-8", "text/html; charset=UTF-8"); } else { fwd = licenseSelectionUrl; } } else { String msg = "IntegrationResponse isLicensed() was true, but getLicenseSelectionClientUrl() was empty."; LOGGER.warning(msg); } // handle a secured URL } else if ((resp != null) && resp.isSecured()) { String securedUrl = resp.getUrl(); if ((securedUrl != null) && !securedUrl.equals(resourceUrl)) { if (act.equals("open")) { fwd = securedUrl; } else if (act.equals("preview")) { fwd = this.replaceParam(fwd, "url", securedUrl); } else if (act.equals("addToMap")) { if ((addToMapHint != null) && (addToMapHint.length() > 0)) { securedUrl = addToMapHint + ":" + securedUrl; } fwd = this.replaceParam(fwd, "resource", securedUrl); } else { fwd = securedUrl; } } } } catch (NotAuthorizedException e) { String msg = "Error checking resource URL"; LOGGER.log(Level.SEVERE, msg, e); this.writeError(request, response, msg + ": " + e.toString(), null); return; } catch (Exception e) { String msg = "Error checking resource URL"; LOGGER.log(Level.SEVERE, msg, e); this.writeError(request, response, msg + ": " + e.toString(), null); return; } finally { if (rc != null) rc.onExecutionPhaseCompleted(); } } // send the redirect if ((fwd != null) && (fwd.length() > 0)) { LOGGER.finer("Redirecting to: " + fwd); if (!Val.isUrl(fwd)) { throw new ServerException("Invalid redirect URL."); } response.sendRedirect(fwd); } }
From source file:com.esri.gpt.sdisuite.IntegrationLinkServlet.java
/** * Processes the response of a license selection. * @param request the HTTP request// w w w.j ava2 s . co m * @param response HTTP response * @throws ServletException if an exception occurs * @throws IOException if an I/O exception occurs */ private void executeLicenseCallback(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOGGER.finer("Processing license selection callback..."); // this code is a modification of Oliver's returnAction.jsp // Geoportal parameters String act = request.getParameter("act"); if ((act == null) || (act.length() == 0)) act = request.getParameter("amp;act"); String fwd = request.getParameter("fwd"); if ((fwd == null) || (fwd.length() == 0)) fwd = request.getParameter("amp;fwd"); String wssUrlParams = request.getParameter("rqs"); if ((wssUrlParams == null) || (wssUrlParams.length() == 0)) wssUrlParams = request.getParameter("amp;rqs"); String addToMapHint = request.getParameter("atmh"); if ((addToMapHint == null) || (addToMapHint.length() == 0)) addToMapHint = request.getParameter("amp;atmh"); // license parameters String lLicenseReference = request.getParameter("licenseReference"); String lWssUrl = request.getParameter("WSS"); String lSuccess = request.getParameter("success"); String lError = request.getParameter("errorMessage"); // check for error if ((lSuccess == null) || !lSuccess.equals("true")) { if ((lError != null) && (lError.length() > 0)) { this.writeError(request, response, "An error occurred while acquiring a license: " + lError, Level.SEVERE); } else { this.writeError(request, response, "Canceled", null); } } else if ((act == null) || (act.length() == 0)) { this.writeError(request, response, "Empty parameter on license callback (act)", Level.SEVERE); } else if ((fwd == null) || (fwd.length() == 0)) { this.writeError(request, response, "Empty parameter on license callback (fwd)", Level.SEVERE); } else { // get license id String lLicenseId = null; IntegrationContextFactory icf = new IntegrationContextFactory(); if (icf.isIntegrationEnabled()) { try { LOGGER.finer("Getting license id form licenseReference=" + lLicenseReference); IntegrationContext ic = icf.newIntegrationContext(); lLicenseId = ic.getLicenseId(lLicenseReference); LOGGER.finer("License id=" + lLicenseId); } catch (Exception e) { String msg = "Error getting license id."; LOGGER.log(Level.SEVERE, msg, e); this.writeError(request, response, msg + ": " + e.toString(), null); return; } } // change wss to http auth url if ((lWssUrl != null) && (lWssUrl.length() > 0)) { if ((lLicenseId != null) && (lLicenseId.length() > 0)) { lWssUrl = lWssUrl.replace("/WSS", "/httpauth/licid-" + lLicenseId); } if (!lWssUrl.endsWith("?")) { lWssUrl += "?"; } if ((wssUrlParams != null) && (wssUrlParams.length() > 0)) { lWssUrl += wssUrlParams; } } else { lWssUrl = ""; } LOGGER.finer("Licensed WSS endpoint: " + lWssUrl); // determine the redirection endpoint based upon the resource link action if ((lWssUrl != null) && (lWssUrl.length() > 0)) { if (act.equals("open")) { fwd = lWssUrl; } else if (act.equals("preview")) { fwd = this.replaceParam(fwd, "url", lWssUrl); } else if (act.equals("addToMap")) { if ((addToMapHint != null) && (addToMapHint.length() > 0)) { lWssUrl = addToMapHint + ":" + lWssUrl; } fwd = this.replaceParam(fwd, "resource", lWssUrl); } else { fwd = lWssUrl; } } // send the redirect if ((fwd != null) && (fwd.length() > 0)) { LOGGER.finer("Redirecting to: " + fwd); fwd = Val.stripControls(fwd); if (!Val.isUrl(fwd)) { throw new ServerException("Invalid redirect URL."); } response.sendRedirect(fwd); } } }