List of usage examples for javax.servlet.http HttpServletRequest getRequestURI
public String getRequestURI();
From source file:com.jaspersoft.jasperserver.api.security.externalAuth.DefaultAuthenticationSoapProcessingFilter.java
/** * <p>/*from w w w . ja va 2 s . c om*/ * Indicates whether this filter should attempt to process a login request * for the current invocation. * </p> * <p> * It strips any parameters from the "path" section of the request URL (such * as the jsessionid parameter in * <em>http://host/myapp/index.html;jsessionid=blah</em>) before matching * against the <code>filterProcessesUrl</code> property. * </p> * <p> * Subclasses may override for special requirements, such as Tapestry * integration. * </p> * * @param request as received from the filter chain * @param response as received from the filter chain * * @return <code>true</code> if the filter should attempt authentication, * <code>false</code> otherwise */ protected boolean requiresAuthentication(HttpServletRequest request, HttpServletResponse response) { String uri = request.getRequestURI(); int pathParamIndex = uri.indexOf(';'); if (pathParamIndex > 0) { // strip everything after the first semi-colon uri = uri.substring(0, pathParamIndex); } if ("".equals(request.getContextPath())) { return uri.endsWith(getFilterProcessesUrl()); } return uri.startsWith(request.getContextPath() + getFilterProcessesUrl()); }
From source file:com.mtgi.analytics.servlet.ServletRequestBehaviorTrackingAdapter.java
protected boolean match(HttpServletRequest request) { if (uriPatterns == null) return true; for (Pattern p : uriPatterns) if (p.matcher(request.getRequestURI()).matches()) return true; return false; }
From source file:org.nebula.service.auth.AuthenticationInterceptor.java
private void checkIfAccessAdminUrls(AuthenticationHelper helper, HttpServletRequest request) throws GeneralSecurityException { if (!helper.isAdmin()) { String contextPath = request.getContextPath(); String requestUri = request.getRequestURI(); for (String url : adminUrls) { if (requestUri.startsWith(contextPath + url)) { throw new GeneralSecurityException( "The user is not allowed to access the url " + (contextPath + url)); }/*from w w w. j a va 2s .com*/ } } }
From source file:org.opengeo.gsr.core.controller.ImageResourceController.java
@Override public ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final String path = (String) request.getRequestURI(); int index = path.lastIndexOf('/'); String fileName = index < 0 ? path : path.substring(index + 1); dispatchImageResource(fileName, request, response); return null;//from w w w .ja v a 2 s . c om }
From source file:eventmanager.config.AuthenticationIntercepter.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception { User user = (User) request.getSession().getAttribute("usuario_logado"); if (user == null) { String uri = request.getRequestURI(); if (uri.endsWith("/login") || uri.endsWith("/loginForm")) { return true; }/* www .ja va 2 s . c om*/ response.sendRedirect("/EventsManagement2/loginForm"); return false; } else { String uri = request.getRequestURI(); if (uri.endsWith("/loginForm") || uri.endsWith("/EventsManagement2/login")) { response.sendRedirect("/EventsManagement2/User/menu"); return false; } if (user.getType() == UserType.EMPRESA) { if (uri.endsWith("/config") || uri.contains("/User/delete") || uri.contains("/User/edit")) { response.sendRedirect("/EventsManagement2/User/menu"); return false; } } else if (user.getType() == UserType.PARTICIPANTE) { if (uri.endsWith("/config") || uri.contains("/User/delete") || uri.contains("/User/edit") || uri.contains("/Event/delete") || uri.contains("/Event/edit")) { response.sendRedirect("/EventsManagement2/User/menu"); return false; } } return true; } }
From source file:net.gbmb.collector.FlowFilter.java
@Override public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception { LOGGER.debug("OUT FILTER {} / {} >> {}", httpServletRequest.getMethod(), httpServletRequest.getRequestURI(), httpServletResponse.getStatus()); }
From source file:org.tsm.concharto.web.filter.LoginFilter.java
/** * Returns the first part of the URL path: "/member/settings.htm?id=1234" returns "member" * @param httpRequest/*from w w w .j a v a 2 s . c o m*/ * @return first part of the URL path */ private String[] getUrlParts(HttpServletRequest httpRequest) { String uri = httpRequest.getRequestURI(); //should like like '/admin/canDelete' or '/admin/findUsers' String path = StringUtils.substringBetween(uri, httpRequest.getContextPath(), ".htm"); String[] parts = StringUtils.split(path, '/'); return parts; }
From source file:com.siberhus.web.ckeditor.servlet.BaseActionServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestURI = request.getRequestURI(); if (requestURI != null && requestURI.lastIndexOf("/") != -1) { String actionName = requestURI.substring(requestURI.lastIndexOf("/") + 1, requestURI.length()); int paramIdx = actionName.indexOf("?"); if (paramIdx != -1) { actionName = actionName.substring(0, actionName.indexOf("?")); }/* w ww . j av a2 s. c om*/ Method method = null; try { method = this.getClass().getMethod(actionName, HttpServletRequest.class, HttpServletResponse.class); } catch (Exception e) { e.printStackTrace(); response.sendError(HttpServletResponse.SC_NOT_FOUND, "Action=" + actionName + " not found for servlet=" + this.getClass()); return; } try { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { request = new MultipartServletRequest(request); log.debug("Files *********************"); MultipartServletRequest mrequest = (MultipartServletRequest) request; for (FileItem fileItem : mrequest.getFileItems()) { log.debug("File[fieldName={}, fileName={}, fileSize={}]", new Object[] { fileItem.getFieldName(), fileItem.getName(), fileItem.getSize() }); } } if (log.isDebugEnabled()) { log.debug("Parameters **************************"); Enumeration<String> paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); log.debug("Param[name={},value(s)={}]", new Object[] { paramName, Arrays.toString(request.getParameterValues(paramName)) }); } } Object result = method.invoke(this, request, response); if (result instanceof StreamingResult) { if (!response.isCommitted()) { ((StreamingResult) result).execute(request, response); } } } catch (Exception e) { e.printStackTrace(); if (e instanceof InvocationTargetException) { throw new ServletException(((InvocationTargetException) e).getTargetException()); } throw new ServletException(e); } } }
From source file:com.esd.vs.interceptor.LoginInterceptor.java
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) { String ip = getRemoteAddress(request); logger.debug(ip);// w w w . ja v a2 s . co m logger.debug(request.getRequestURI()); if (request.getRequestURI().indexOf("/security") != -1) { Object obj = request.getSession().getAttribute(Constants.USER_ID); if (obj == null) { PrintWriter out = null; try { out = response.getWriter(); StringBuilder builder = new StringBuilder(); builder.append("<script type=\"text/javascript\" charset=\"UTF-8\">"); builder.append("window.top.location.href='"); builder.append("/vs/login"); builder.append("';"); builder.append("</script>"); out.print(builder.toString()); out.close(); return false; } catch (IOException e) { logger.error(e.getMessage()); } finally { if (out != null) { out.close(); } } } } return true; }
From source file:com.erudika.scoold.utils.CsrfFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) req; final HttpServletResponse response = (HttpServletResponse) res; boolean isCSPReportRequest = request.getRequestURI().startsWith("/reports/cspv"); if ("POST".equals(request.getMethod()) && !isCSPReportRequest) { String csrfToken = request.getParameter("_csrf"); String csrfInCookie = HttpUtils.getStateParam(CSRF_COOKIE, request); Long time = NumberUtils.toLong(request.getParameter("_time"), 0); String timekey = request.getParameter("_timekey"); if (timekey != null) { Long timeInSession = (Long) request.getSession().getAttribute(timekey); request.getSession().setAttribute(timekey, System.currentTimeMillis()); if (!time.equals(timeInSession)) { logger.warn("Time token mismatch. {}, {}", request.getRemoteAddr(), request.getRequestURL()); // response.sendError(403, "Time token mismatch."); response.sendRedirect(request.getRequestURI()); return; }//from w w w . j a v a2 s. c om } if (csrfToken == null) { csrfToken = request.getHeader("X-CSRF-TOKEN"); if (csrfToken == null) { csrfToken = request.getHeader("X-XSRF-TOKEN"); } } if (csrfToken == null || StringUtils.isBlank(csrfInCookie) || !csrfToken.equals(csrfInCookie)) { logger.warn("CSRF token mismatch. {}, {}", request.getRemoteAddr(), request.getRequestURL()); response.sendError(403, "CSRF token mismatch."); return; } } chain.doFilter(request, response); }