List of usage examples for javax.servlet.http HttpServletRequest getServletPath
public String getServletPath();
From source file:com.ctc.storefront.filters.StorefrontFilter.java
protected boolean isRequestPathExcluded(final HttpServletRequest request) { final Set<String> inputSet = getRefererExcludeUrlSet(); final String servletPath = request.getServletPath(); for (final String input : inputSet) { if (getPathMatcher().match(input, servletPath)) { return true; }// w w w .j a v a 2 s .c om } return false; }
From source file:edu.harvard.iq.dataverse.NavigationWrapper.java
public String getPageFromContext() { if (redirectPage == null) { StringBuilder redirectBuilder = new StringBuilder(); HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest();/*from w w w. j av a 2s . com*/ redirectBuilder.append(req.getServletPath()); // to regenerate the query string, we need to use the parameter map; however this can contain internal POST parameters // that we don't want, so we filter through a list of paramters we do allow // @todo verify what needs to be in this list of available parameters (for example do we want to repeat searches when you login? List<String> acceptableParameters = new ArrayList<>(); acceptableParameters.addAll(Arrays.asList("id", "alias", "version", "q", "ownerId", "persistentId", "versionId", "datasetId", "selectedFileIds", "mode", "dataverseId", "fileId", "datasetVersionId", "guestbookId")); if (req.getParameterMap() != null) { StringBuilder queryString = new StringBuilder(); for (Map.Entry<String, String[]> entry : ((Map<String, String[]>) req.getParameterMap()) .entrySet()) { String name = entry.getKey(); if (acceptableParameters.contains(name)) { String value = entry.getValue()[0]; queryString.append(queryString.length() == 0 ? "?" : "&").append(name).append("=") .append(value); } } redirectBuilder.append(queryString); } try { redirectPage = URLEncoder.encode(redirectBuilder.toString(), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(DataverseHeaderFragment.class.getName()).log(Level.SEVERE, null, ex); redirectPage = ""; } } return redirectPage; }
From source file:com.acc.storefront.security.ExcludeUrlRequestMatcher.java
@Override public boolean matches(final HttpServletRequest request) { // Do not match patterns specified in the excludeUrlSet to the servletPath for (final String excludeUrl : getExcludeUrlSet()) { if (getPathMatcher().match(excludeUrl, request.getServletPath())) { // Found an exclude pattern return false; }//from ww w . j a v a 2 s. c o m } // Not found an exclude URL that matched therefore ok to proceed return true; }
From source file:com.cloud.servlet.StaticResourceServletTest.java
private HttpServletResponse doGetTest(final String uri, final Map<String, String> headers) throws ServletException, IOException { final StaticResourceServlet servlet = Mockito.mock(StaticResourceServlet.class); Mockito.doCallRealMethod().when(servlet).doGet(Matchers.any(HttpServletRequest.class), Matchers.any(HttpServletResponse.class)); final ServletContext servletContext = Mockito.mock(ServletContext.class); Mockito.when(servletContext.getRealPath(uri)).thenReturn(new File(rootDirectory, uri).getAbsolutePath()); Mockito.when(servlet.getServletContext()).thenReturn(servletContext); final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.when(request.getServletPath()).thenReturn(uri); Mockito.when(request.getHeader(Matchers.anyString())).thenAnswer(new Answer<String>() { @Override//from w ww. j a v a 2s .co m public String answer(final InvocationOnMock invocation) throws Throwable { return headers.get(invocation.getArguments()[0]); } }); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); final ServletOutputStream responseBody = Mockito.mock(ServletOutputStream.class); Mockito.when(response.getOutputStream()).thenReturn(responseBody); servlet.doGet(request, response); return response; }
From source file:com.jayway.jaxrs.hateoas.web.RequestContextFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest servletRequest = (HttpServletRequest) request; String requestURI = servletRequest.getRequestURI(); requestURI = StringUtils.removeStart(requestURI, servletRequest.getContextPath() + servletRequest.getServletPath()); String baseURL = StringUtils.removeEnd(servletRequest.getRequestURL().toString(), requestURI); UriBuilder uriBuilder = UriBuilder.fromUri(baseURL); RequestContext ctx = new RequestContext(uriBuilder, servletRequest.getHeader(RequestContext.HATEOAS_OPTIONS_HEADER)); RequestContext.setRequestContext(ctx); try {/*w ww.java 2 s . c om*/ chain.doFilter(request, response); } finally { RequestContext.clearRequestContext(); } }
From source file:com.groupon.odo.controllers.ConfigurationInterceptor.java
/** * This will check to see if certain configuration values exist from the ConfigurationService * If not then it redirects to the configuration screen *///from ww w. j av a2s . c o m public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String queryString = request.getQueryString() == null ? "" : request.getQueryString(); if (ConfigurationService.getInstance().isValid() || request.getServletPath().startsWith("/configuration") || request.getServletPath().startsWith("/resources") || queryString.contains("requestFromConfiguration=true")) { return true; } else { response.sendRedirect("configuration"); return false; } }
From source file:org.iwethey.forums.web.user.LoginInterceptor.java
/** * Check the session for an authenticated user name. If none, redirect to * the login page.// w w w . j ava2 s. c om * <p> * @param request The servlet request object. * @param response The servlet response object. * @param handler The request handler processing this request. */ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Integer id = (Integer) WebUtils.getSessionAttribute(request, USER_ID_ATTRIBUTE); if (id == null) { String uri = request.getServletPath(); String query = request.getQueryString(); ModelAndView mv = new ModelAndView(new RedirectView("../user/login.iwt")); throw new ModelAndViewDefiningException(mv); } else { return true; } }
From source file:org.openmrs.module.personalhr.web.controller.SpringController.java
@Override public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { this.log.debug("Entering org.openmrs.module.cancertoolkit.web.controller.SpringController"); String path = request.getServletPath(); if (path.endsWith("htm")) { path = path.replace(".htm", ""); } else if (path.endsWith("jsp")) { path = path.replace(".jsp", ""); }//w w w. j a v a2 s. c o m path = path.replace("/phr/", ""); path = "module/personalhr/view/" + path; //int qmark = path.indexOf("?"); this.log.debug("Exiting: path=" + path); final Map<String, Object> model = new HashMap<String, Object>(); final String sharingToken = request.getParameter("sharingToken"); model.put("sharingToken", sharingToken); return new ModelAndView(path, "model", model); }
From source file:org.sakaiproject.tool.section.filter.RoleFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; String servletPath = request.getServletPath(); if (logger.isDebugEnabled()) logger.debug("Filtering request for servletPath=" + servletPath); servletPath = servletPath.replaceFirst("^/", ""); if (servletPath.indexOf("/") >= 0) { // Only protect the top-level folder, to allow for login through // a subdirectory, shared resource files, and so on. chain.doFilter(request, response); return;//from ww w .j a v a 2 s .c o m } Authn authn = (Authn) ac.getBean(authnBeanName); Authz authz = (Authz) ac.getBean(authzBeanName); Context context = (Context) ac.getBean(contextBeanName); AuthorizationFilterConfigurationBean authzFilterConfigBean = (AuthorizationFilterConfigurationBean) ac .getBean(authorizationFilterConfigurationBeanName); String userUid = authn.getUserUid(request); if (logger.isDebugEnabled()) logger.debug("Filtering request for user " + userUid + ", pathInfo=" + request.getPathInfo()); // Try to get the currently selected site context, if any String siteContext = context.getContext(request); if (logger.isDebugEnabled()) logger.debug("context=" + siteContext); if (siteContext != null) { // Get the name of the page from the servlet path. String[] splitPath = servletPath.split("[./]"); String pageName = splitPath[0]; boolean isAuthorized = false; if (authz.isSectionManagementAllowed(userUid, siteContext) && authzFilterConfigBean.getManageAllSections().contains(pageName)) { isAuthorized = true; } else if (authz.isViewAllSectionsAllowed(userUid, siteContext) && authzFilterConfigBean.getViewAllSections().contains(pageName)) { isAuthorized = true; } else if (authz.isSectionTaManagementAllowed(userUid, siteContext) && authzFilterConfigBean.getManageTeachingAssistants().contains(pageName)) { isAuthorized = true; } else if (authz.isSectionEnrollmentMangementAllowed(userUid, siteContext) && authzFilterConfigBean.getManageEnrollments().contains(pageName)) { isAuthorized = true; } else if (authz.isViewOwnSectionsAllowed(userUid, siteContext) && authzFilterConfigBean.getViewOwnSections().contains(pageName)) { isAuthorized = true; } else if (pageName.contains("closed")) { isAuthorized = true; } // SAK-13408 - This fix addresses the problem of the filter receiving a blank field on WebSphere. // Without this, users would be denied access to the tool if ("websphere".equals(ServerConfigurationService.getString("servlet.container")) && (isAuthorized || pageName.equals(""))) { chain.doFilter(request, response); } else if (!"websphere".equals(ServerConfigurationService.getString("servlet.container")) && isAuthorized) { chain.doFilter(request, response); } else { logger.error("AUTHORIZATION FAILURE: User " + userUid + " in site " + siteContext + " attempted to reach URL " + request.getRequestURL()); ((HttpServletResponse) response).sendError(HttpServletResponse.SC_UNAUTHORIZED); } } else { if (selectSiteRedirect != null) { ((HttpServletResponse) response).sendRedirect(selectSiteRedirect); } else { ((HttpServletResponse) response).sendError(HttpServletResponse.SC_UNAUTHORIZED); } } }
From source file:com.baidu.cc.web.filter.LoginFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String path = request.getServletPath(); if (request.getParameter("method") != null) { path = path + "?method=" + request.getParameter("method"); }/*from ww w .ja v a2 s.co m*/ // exclude path ??? if (UrlUtils.urlMatch(excludePathv, path)) { filterChain.doFilter(request, response); return; } CookieHelper cookieHelper = new CookieHelper(request, response); Long uid = NumberUtils.toLong(cookieHelper.getCookieVal("rcc_uid")); String name = cookieHelper.getCookieVal("rcc_name"); String token = cookieHelper.getCookieVal("rcc_token"); if (uid > 0L && StringUtils.isNotEmpty(name) && SysUtils.genCookieToken(uid, name).equals(token)) { ThreadLocalInfo.setThreadUuid(uid.toString()); User user = new User(); user.setId(uid); user.setName(name); SysUtils.addLoginCookie(request, response, user); filterChain.doFilter(request, response); } else { response.sendRedirect(StringUtils.defaultIfEmpty(request.getContextPath(), "/")); } }