List of usage examples for javax.servlet.http HttpServletRequest getServletPath
public String getServletPath();
From source file:io.hops.hopsworks.api.kibana.ProxyServlet.java
/** * Copy cookie from the proxy to the servlet client. * Replaces cookie path to local path and renames cookie to avoid collisions. *//* www . j a v a 2 s. c om*/ protected void copyProxyCookie(HttpServletRequest servletRequest, HttpServletResponse servletResponse, String header) { List<HttpCookie> cookies = HttpCookie.parse(header); String path = servletRequest.getContextPath(); // path starts with / or is empty string path += servletRequest.getServletPath(); // servlet path starts with / or is empty string for (HttpCookie cookie : cookies) { //set cookie name prefixed w/ a proxy value so it won't collide w/ other cookies String proxyCookieName = getCookieNamePrefix() + cookie.getName(); Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue()); servletCookie.setComment(cookie.getComment()); servletCookie.setMaxAge((int) cookie.getMaxAge()); servletCookie.setPath(path); //set to the path of the proxy servlet // don't set cookie domain servletCookie.setSecure(cookie.getSecure()); servletCookie.setVersion(cookie.getVersion()); servletResponse.addCookie(servletCookie); } }
From source file:com.huateng.ebank.framework.web.TransFilter.java
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpSession httpSession = request.getSession(false); if (null != httpSession) { Object o = httpSession.getAttribute(GlobalInfo.KEY_GLOBAL_INFO); if (null != o && o instanceof GlobalInfo) { GlobalInfo globalInfo = (GlobalInfo) o; /**// w w w . j a v a 2s . c om * ? */ GlobalInfo.setCurrentInstance(globalInfo); String sessionId = httpSession.getId(); globalInfo.setSessionId(sessionId); //set funcid globalInfo.setFuncId(request.getParameter("__FuncId")); /** add by zhaozhiguo 2011-6-20 BMS-3153 begin */ String path = request.getServletPath(); if (!path.endsWith("ChangePwd.ftl") && !path.endsWith("logout.do") && !path.endsWith("login.do")) { if (globalInfo.getLastpwdchgtm() == null) { globalInfo.setPswdForcedToChange(true);//? } else { long between = DateUtil.getDaysBetween(new Date(), globalInfo.getLastpwdchgtm()); if (between > globalInfo.getEffectiveDay() && globalInfo.getEffectiveDay() >= 0) { globalInfo.setPswdForcedToChange(true);//N?,? } } if (globalInfo.isPswdForcedToChange()) { ((HttpServletResponse) resp).getWriter().print("<script>top.location='" + request.getContextPath() + "/fpages/management/ftl/ChangePwd.ftl';</script>"); return; } /***add by ningpeng 2012-11-7 begin*/ String tlrNo = globalInfo.getTlrno(); String sta = userService.getUserLoginStatus(tlrNo); if (sta == null || SystemConstant.TLR_NO_STATE_LOGOUT.equals(sta)) { ((HttpServletResponse) resp) .sendRedirect(request.getContextPath() + "/common/success.jsp?type=signout"); return; } /***add by ningpeng 2012-11-7 end*/ } /** add by zhaozhiguo 2011-6-20 BMS-3153 end */ } else { if (expiredSystem((HttpServletRequest) req, (HttpServletResponse) resp)) { return; } } } else { if (expiredSystem((HttpServletRequest) req, (HttpServletResponse) resp)) { return; } } filterChain.doFilter(req, resp); }
From source file:eionet.webq.web.controller.FileDownloadController.java
/** * Download uploaded file action./*from w ww . j a v a 2 s . c om*/ * * @param projectId project id for file download * @param fileName requested file name * @param format if format=json, then convert XML file to json format * @param request http request * @param response http response to write file * @throws FileNotAvailableException if project file is not available for given id */ @RequestMapping(value = "/project/{projectId}/file/{fileName:.*}") @Transactional public void downloadProjectFile(@PathVariable String projectId, @PathVariable String fileName, @RequestParam(required = false) String format, HttpServletRequest request, HttpServletResponse response) throws FileNotAvailableException { ProjectFile projectFile = projectFileService.fileContentBy(fileName, projectService.getByProjectId(projectId)); if (projectFile == null) { throw new FileNotAvailableException("The requested project file is not available with path: /project/" + projectId + "/file/" + fileName); } String disposition = request.getServletPath().contains("/download/") ? "attachment" : "inline"; writeProjectFileToResponse(fileName, projectFile, response, disposition, format); }
From source file:cn.bc.web.util.DebugUtils.java
public static StringBuffer getDebugInfo(HttpServletRequest request, HttpServletResponse response) { @SuppressWarnings("rawtypes") Enumeration e;//from w ww . j a va 2 s. co m String name; StringBuffer html = new StringBuffer(); //session HttpSession session = request.getSession(); html.append("<div><b>session:</b></div><ul>"); html.append(createLI("Id", session.getId())); html.append(createLI("CreationTime", new Date(session.getCreationTime()).toString())); html.append(createLI("LastAccessedTime", new Date(session.getLastAccessedTime()).toString())); //session:attributes e = session.getAttributeNames(); html.append("<li>attributes:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, String.valueOf(session.getAttribute(name)))); } html.append("</ul></li>\r\n"); html.append("</ul>\r\n"); //request html.append("<div><b>request:</b></div><ul>"); html.append(createLI("URL", request.getRequestURL().toString())); html.append(createLI("QueryString", request.getQueryString())); html.append(createLI("Method", request.getMethod())); html.append(createLI("CharacterEncoding", request.getCharacterEncoding())); html.append(createLI("ContentType", request.getContentType())); html.append(createLI("Protocol", request.getProtocol())); html.append(createLI("RemoteAddr", request.getRemoteAddr())); html.append(createLI("RemoteHost", request.getRemoteHost())); html.append(createLI("RemotePort", request.getRemotePort() + "")); html.append(createLI("RemoteUser", request.getRemoteUser())); html.append(createLI("ServerName", request.getServerName())); html.append(createLI("ServletPath", request.getServletPath())); html.append(createLI("ServerPort", request.getServerPort() + "")); html.append(createLI("Scheme", request.getScheme())); html.append(createLI("LocalAddr", request.getLocalAddr())); html.append(createLI("LocalName", request.getLocalName())); html.append(createLI("LocalPort", request.getLocalPort() + "")); html.append(createLI("Locale", request.getLocale().toString())); //request:headers e = request.getHeaderNames(); html.append("<li>Headers:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, request.getHeader(name))); } html.append("</ul></li>\r\n"); //request:parameters e = request.getParameterNames(); html.append("<li>Parameters:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, request.getParameter(name))); } html.append("</ul></li>\r\n"); html.append("</ul>\r\n"); //response html.append("<div><b>response:</b></div><ul>"); html.append(createLI("CharacterEncoding", response.getCharacterEncoding())); html.append(createLI("ContentType", response.getContentType())); html.append(createLI("BufferSize", response.getBufferSize() + "")); html.append(createLI("Locale", response.getLocale().toString())); html.append("<ul>\r\n"); return html; }
From source file:dk.itst.oiosaml.sp.configuration.ConfigurationHandler.java
protected String getBaseUrl(HttpServletRequest request) { String url = request.getRequestURL().toString(); log.info("url (old method): " + url); // might only be necessary because of my crazy pagekite setup --pdurbin // url = request.getScheme() url = "https" + "://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI(); log.info("url (new method): " + url); int idx = url.lastIndexOf(request.getServletPath()); return url.substring(0, idx + request.getServletPath().length()); }
From source file:br.mdarte.exemplo.academico.accessControl.LoginController.java
public boolean verificarPermissao(ActionMapping mapping, HttpServletRequest request, HttpServletResponse response, HttpServlet servlet) throws Exception { java.util.HashMap<String, HashMap<String, Collection<accessControl.Perfil>>> servicos = ServicosSingleton .instance().getServicos();// www.j a va2s . co m HashMap<String, Collection<accessControl.Perfil>> mapServicos; if (servicos == null) { mapServicos = new HashMap<String, Collection<accessControl.Perfil>>(); } else { mapServicos = servicos.get("sistemaacademico"); } Subject subject = (Subject) request.getSession().getAttribute(Constantes.USER_SESSION); String nomeServico = StringUtils.remove(request.getServletPath(), ".do"); Servico servico = new Servico(nomeServico); boolean possuiPermissao = accessControl.ControleAcesso.verificaPermissao(subject, mapServicos, servico, true); if (possuiPermissao) { return true; } else { saveErrorMessage(request, "acesso.negado"); return false; } }
From source file:net.maritimecloud.identityregistry.controllers.ServiceController.java
/** * Deletes a Service/*from ww w . j a va2s . c om*/ * * @return a reply... * @throws McBasicRestException */ @RequestMapping(value = "/api/org/{orgMrn}/service/{serviceMrn}", method = RequestMethod.DELETE) @ResponseBody @PreAuthorize("hasRole('SERVICE_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)") public ResponseEntity<?> deleteService(HttpServletRequest request, @PathVariable String orgMrn, @PathVariable String serviceMrn) throws McBasicRestException { Organization org = this.organizationService.getOrganizationByMrn(orgMrn); if (org != null) { // Check that the entity being deleted belongs to the organization if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn) .equals(MrnUtil.getOrgShortNameFromEntityMrn(serviceMrn))) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } Service service = this.entityService.getByMrn(serviceMrn); if (service == null) { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ENTITY_NOT_FOUND, request.getServletPath()); } if (service.getIdOrganization().compareTo(org.getId()) == 0) { // Delete the keycloak client for the service if needed if (service.getOidcAccessType() != null && !service.getOidcAccessType().trim().isEmpty() && service.getOidcRedirectUri() != null && !service.getOidcRedirectUri().trim().isEmpty()) { keycloakAU.init(KeycloakAdminUtil.BROKER_INSTANCE); keycloakAU.deleteClient(service.getMrn()); } this.entityService.delete(service.getId()); return new ResponseEntity<>(HttpStatus.OK); } throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } else { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND, request.getServletPath()); } }
From source file:net.maritimecloud.identityregistry.controllers.ServiceController.java
/** * Returns keycloak.json the service identified by the given ID * * @return a reply.../*from w ww. j a v a 2 s. c om*/ * @throws McBasicRestException */ @RequestMapping(value = "/api/org/{orgMrn}/service/{serviceMrn}/keycloakjson", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") @ResponseBody @PreAuthorize("hasRole('SERVICE_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)") public ResponseEntity<String> getServiceKeycloakJson(HttpServletRequest request, @PathVariable String orgMrn, @PathVariable String serviceMrn) throws McBasicRestException { Organization org = this.organizationService.getOrganizationByMrn(orgMrn); if (org != null) { // Check that the entity being queried belongs to the organization if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn) .equals(MrnUtil.getOrgShortNameFromEntityMrn(serviceMrn))) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } Service service = this.entityService.getByMrn(serviceMrn); if (service == null) { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ENTITY_NOT_FOUND, request.getServletPath()); } if (service.getIdOrganization().compareTo(org.getId()) == 0) { // Get the keycloak json for the client the service represents if it exists if (service.getOidcAccessType() != null && !service.getOidcAccessType().trim().isEmpty()) { keycloakAU.init(KeycloakAdminUtil.BROKER_INSTANCE); String keycloakJson = keycloakAU.getClientKeycloakJson(service.getMrn()); return new ResponseEntity<>(keycloakJson, HttpStatus.OK); } throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.OIDC_CONF_FILE_NOT_AVAILABLE, request.getServletPath()); } throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } else { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND, request.getServletPath()); } }
From source file:com.jsmartframework.web.manager.TagHandler.java
protected String getRequestPath() { HttpServletRequest request = getRequest(); String[] paths = request.getServletPath().split("/"); return request.getContextPath() + "/" + paths[paths.length - 1].substring(0, paths[paths.length - 1].indexOf(".")); }
From source file:net.maritimecloud.identityregistry.controllers.ServiceController.java
/** * Returns keycloak.json the service identified by the given ID * * @return a reply.../* www . j a va2 s . com*/ * @throws McBasicRestException */ @RequestMapping(value = "/api/org/{orgMrn}/service/{serviceMrn}/jbossxml", method = RequestMethod.GET) @ResponseBody @PreAuthorize("hasRole('SERVICE_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)") public ResponseEntity<String> getServiceJbossXml(HttpServletRequest request, @PathVariable String orgMrn, @PathVariable String serviceMrn) throws McBasicRestException { Organization org = this.organizationService.getOrganizationByMrn(orgMrn); if (org != null) { // Check that the entity being queried belongs to the organization if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn) .equals(MrnUtil.getOrgShortNameFromEntityMrn(serviceMrn))) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } Service service = this.entityService.getByMrn(serviceMrn); if (service == null) { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ENTITY_NOT_FOUND, request.getServletPath()); } if (service.getIdOrganization().compareTo(org.getId()) == 0) { // Get the jboss xml for the client the service represents if it exists if (service.getOidcAccessType() != null && !service.getOidcAccessType().trim().isEmpty()) { keycloakAU.init(KeycloakAdminUtil.BROKER_INSTANCE); String jbossXml = keycloakAU.getClientJbossXml(service.getMrn()); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentLength(jbossXml.length()); responseHeaders.setContentType(MediaType.APPLICATION_XML); return new ResponseEntity<>(jbossXml, responseHeaders, HttpStatus.OK); } throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.OIDC_CONF_FILE_NOT_AVAILABLE, request.getServletPath()); } throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } else { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND, request.getServletPath()); } }