List of usage examples for javax.servlet.http HttpServletRequest getRequestURI
public String getRequestURI();
From source file:coyote.commons.web.AuthFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; String uri = req.getRequestURI(); LOG.debug("Requested Resource:" + uri); HttpServletResponse res = (HttpServletResponse) response; if (uriIsProtected(uri)) { Login login = WebApp.getLogin(req); if (login == null) { LOG.warn("Must be logged in to access " + uri); // set the original request URI in the session so login script can redirect req.getSession().setAttribute(WebApp.SESSION_TARGET_URI_KEY, uri); res.sendRedirect("login"); } else {// ww w .j a v a2 s. c o m // TODO: Check if login has access to the URI target } // login check } else { // Not a protected URI, pass the request along the filter chain try { chain.doFilter(request, response); } catch (Exception e) { LOG.warn("Exception sending request down the chain", e); } } // if protected URI }
From source file:edu.cornell.mannlib.vitro.webapp.filters.CharsetEncodingFilter.java
private void setContentTypeOnResponse(HttpServletRequest req, ServletResponse servletResponse) { if (servletResponse.getContentType() != null) { return;/*from ww w . j a va 2 s . co m*/ } String uri = req.getRequestURI(); if (!hasExtension(uri)) { servletResponse.setContentType("text/html;charset=UTF-8"); return; } String typeFromContext = req.getSession().getServletContext().getMimeType(uri); if (typeFromContext == null) { servletResponse.setContentType("text/html;charset=UTF-8"); return; } servletResponse.setContentType(typeFromContext); servletResponse.setCharacterEncoding("UTF-8"); }
From source file:io.apiman.manager.test.server.MockGatewayServlet.java
/** * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///from w w w. j a v a2 s . co m @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { builder.append("GET:").append(req.getRequestURI()).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ payloads.add(null); if (req.getRequestURI().endsWith("/system/status")) { //$NON-NLS-1$ resp.setStatus(200); resp.setContentType("application/json"); //$NON-NLS-1$ PrintWriter printWriter = new PrintWriter(resp.getOutputStream()); printWriter.println("{ \"up\" : true, \"version\" : \"1.0.Mock\" }"); //$NON-NLS-1$ printWriter.flush(); printWriter.close(); } else { resp.setStatus(204); } }
From source file:br.vschettino.forum.interceptor.AuthInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Usuario visitante = (Usuario) request.getSession().getAttribute("usuario"); if (request.getRequestURI().contains("/login") || request.getRequestURI().contains("/logout")) { return true; }//from ww w .j av a 2s . c o m if (visitante == null) { response.sendRedirect(request.getContextPath() + "/web/login?unauthorized=true"); return false; } return true; }
From source file:net.paulgray.mocklti2.web.Lti2ConsumerController.java
@RequestMapping(value = "/") public String getWelcome(HttpServletRequest request, ModelMap model) { model.addAttribute("contextPath", request.getContextPath()); model.addAttribute("contextUrl", request.getRequestURL()); model.addAttribute("contextUri", request.getRequestURI()); return "welcome"; }
From source file:AIR.Common.Web.Session.HttpRequestLoggerInitializerFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; final String requestPath = StringUtils.defaultString(httpRequest.getRequestURI()); MDC.put("requestSequence", getNextSequence()); MDC.put("requestTime", new SimpleDateFormat("YYYY-MM-dd hh:mm:ss.SSS").format(new Date())); MDC.put("requestPath", requestPath); MDC.put("safeRequestPath", requestPath.replace('/', '~').replace('\\', '~')); MDC.put("prefix", StringUtils.defaultString(prefix, "")); HttpServletRequest wrappedRequest = httpRequest; if (logger.isDebugEnabled()) { addRequestDetailsToLoggers(httpRequest); // TODO: To log request bodies, more work is needed on the ContentLoggingHttpServletRequest // if (logRequestBodies && !( // httpRequest.getMethod ().equals ("GET") || // httpRequest.getMethod ().equals ("DELETE"))) { // wrappedRequest = new ContentLoggingHttpServletRequest (httpRequest); // ((ContentLoggingHttpServletRequest) wrappedRequest).logContent (logger); // } // else { // logger.debug ("<<<<< Request content logging disabled. Set filter parameter LogRequestBodies to enable >>>>>"); // } }//from ww w . jav a2 s . co m chain.doFilter(wrappedRequest, response); // This tells the appender to close the file with the next logging request MDC.put("close", "true"); logger.debug("========================== Request Logging End ==================================="); MDC.clear(); }
From source file:com.glaf.base.servlet.SpringDispatcherServlet.java
@Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { logger.debug("RequestURI:" + request.getRequestURI()); try {// ww w. jav a 2 s. c o m String systemName = RequestUtils.getCurrentSystem(request); if (systemName != null && !StringUtils.equals("GLAF", systemName)) { Environment.setCurrentSystemName(systemName); } String actorId = RequestUtils.getActorId(request); if (actorId != null) { // logger.debug("actorId:" + actorId); Authentication.setAuthenticatedAccount(actorId); } SysUser user = RequestUtil.getLoginUser(request); if (user != null) { Authentication.setAuthenticatedUser(user); com.glaf.core.security.Authentication.setAuthenticatedActorId(user.getAccount()); } /** * ?????? */ if ((user == null) || (!user.isSystemAdmin())) { String uri = request.getRequestURI(); logger.debug("request uri:" + uri); } } catch (Exception ex) { ex.printStackTrace(); } ThreadContextHolder.setHttpRequest(request); ThreadContextHolder.setHttpResponse(response); try { super.doService(request, response); } finally { Environment.removeCurrentSystemName(); Environment.clear(); Authentication.clear(); ThreadContextHolder.clear(); ConnectionThreadHolder.closeAndClear(); com.glaf.core.security.Authentication.clear(); } }
From source file:com.glaf.core.web.servlet.SpringDispatcherServlet.java
@Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { logger.debug("RequestURI:" + request.getRequestURI()); try {//from w w w.j a va 2 s .co m String systemName = RequestUtils.getCurrentSystem(request); if (systemName != null && !StringUtils.equals("GLAF", systemName)) { Environment.setCurrentSystemName(systemName); } String actorId = RequestUtils.getActorId(request); if (actorId != null) { // logger.debug("actorId:" + actorId); Authentication.setAuthenticatedActorId(actorId); } LoginContext user = RequestUtils.getLoginContext(request); if (user != null) { Authentication.setLoginContext(user); com.glaf.core.security.Authentication.setAuthenticatedActorId(user.getActorId()); } /** * ?????? */ if ((user == null) || (!user.isSystemAdministrator())) { String uri = request.getRequestURI(); logger.debug("request uri:" + uri); } } catch (Exception ex) { ex.printStackTrace(); } ThreadContextHolder.setHttpRequest(request); ThreadContextHolder.setHttpResponse(response); ThreadContextHolder.setServletContext(request.getServletContext()); try { super.doService(request, response); } finally { Environment.setCurrentSystemName(null); Environment.removeCurrentSystemName(); Environment.clear(); Authentication.clear(); ThreadContextHolder.clear(); ConnectionThreadHolder.closeAndClear(); } }
From source file:com.google.code.lightssh.project.security.shiro.MySecondaryLicensePermissionsAuthorizationFilter.java
/** * ??/* ww w. j a v a2s . c o m*/ */ @Override public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException { Subject subject = getSubject(request, response); String[] perms = (String[]) mappedValue; boolean isPermitted = true; String targetUrl = request.getParameter("targetUrl"); if (targetUrl == null) { HttpServletRequest httpServletRequest = (HttpServletRequest) request; targetUrl = httpServletRequest.getRequestURI().substring(httpServletRequest.getContextPath().length()); } AuthorizedResource authResource = authorizedResourceManager.getWithRegexp("/" + targetUrl); if (authResource != null) { isPermitted = checkTempAuth((HttpServletRequest) request, perms); } else { if (perms != null && perms.length > 0) { // boolean tempAuthed = tempAuthService.authorize(perms,request); if (perms.length == 1) { if (!subject.isPermitted(perms[0])) { isPermitted = false; } } else { if (!subject.isPermittedAll(perms)) { isPermitted = false; } } } } return isPermitted; }
From source file:com.redhat.rhn.frontend.security.BaseAuthenticationService.java
protected boolean requestURIRequiresAuthentication(final HttpServletRequest request) { return !CollectionUtils.exists(getUnprotectedURIs(), new Predicate() { public boolean evaluate(Object uri) { return request.getRequestURI().startsWith(uri.toString()); }// www . j a v a 2s. c o m }); }