List of usage examples for javax.servlet.http HttpServletRequest getServletPath
public String getServletPath();
From source file:com.jsmartframework.web.manager.ServletControl.java
private void sendRedirect(String path, HttpServletRequest request, HttpServletResponse response, boolean authNeeded) throws IOException, ServletException { if (request.getServletPath().equals(path)) { String url = HANDLER.getForwardPath(path); if (url == null) { LOGGER.log(Level.SEVERE, "Could not find JSP page for path [" + path + "]"); return; }//from www. ja va 2s. c o m // Generate web security token to prevent CSRF attack HANDLER.generateWebSecurityToken(request, response); // Use Forward request internally case is the same page request.getRequestDispatcher(url).forward(request, response); } else { // Use Redirect response case page had changed (Do not use status 302 once cookies are not set) response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT); response.setHeader("Location", getRedirectPath(path, request, authNeeded)); } }
From source file:de.highbyte_le.weberknecht.security.filters.NameBasedLoginPageForwardFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (logger.isDebugEnabled()) logger.debug("doFilter() - start"); boolean forward = true; if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) { logger.error("servlet request is no HTTP servlet request"); } else {/*from ww w .j a va2 s.co m*/ HttpServletRequest httpRequest = (HttpServletRequest) request; HttpSession session = httpRequest.getSession(); UserAuthentication userAuthentication = (UserAuthentication) session.getAttribute("user_auth"); if (userAuthentication != null && userAuthentication.isAuthenticated()) //user is logged in forward = false; else if (!isUserServlet(httpRequest.getServletPath())) //servlet is not protected forward = false; } if (forward) { request.setAttribute("de.highbyte_le.weberknecht.login.status", "failed"); logger.debug("doFilter() - forward to login page"); RequestDispatcher rd = request.getRequestDispatcher(loginPage); rd.forward(request, response); } else { logger.debug("doFilter() - Continue with filter chain"); chain.doFilter(request, response); } }
From source file:at.gv.egiz.pdfas.web.helper.PdfAsHelper.java
public static void logAccess(HttpServletRequest request) { HttpSession session = request.getSession(); logger.info("Access to " + request.getServletPath() + " in Session: " + session.getId()); }
From source file:com.adito.boot.Util.java
/** * Rebuild the URI of the request by concatenating the servlet path and and * request parameters// ww w. ja va2s . com * * @param request request to extra path from * @return path */ public static String getOriginalRequest(HttpServletRequest request) { StringBuffer req = new StringBuffer(request.getServletPath()); if (request.getQueryString() != null && request.getQueryString().length() > 0) { req.append("?"); req.append(request.getQueryString()); } return req.toString(); }
From source file:de.micromata.genome.gwiki.web.GWikiServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (GLog.isTraceEnabled() == true) { String lopi = "Req: ctpath: " + req.getContextPath() + "; spath: " + req.getServletPath() + "; pi: " + req.getPathInfo();//from ww w . j av a2 s .c o m GLog.note(GWikiLogCategory.Wiki, lopi); } initWiki(req, resp); long start = System.currentTimeMillis(); GWikiWeb wiki = getWikiWeb(); GWikiContext ctx = new GWikiContext(wiki, this, req, resp); try { GWikiContext.setCurrent(ctx); String page = getWikiPage(ctx); final String method = req.getMethod(); if (StringUtils.equals(method, "GET") == false && StringUtils.equals(method, "POST") == false) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Gwiki Method " + method + " not supported"); return; } if (page.startsWith("static/") == true) { serveStatic(page, ctx); return; } wiki.serveWiki(page, ctx); } catch (RuntimeIOException ex) { GLog.info(GWikiLogCategory.Wiki, "IO Error serving: " + ex.getMessage(), new LogExceptionAttribute(ex)); } catch (Exception ex) { if (isIgnorableAppServeIOException(ex) == true) { GLog.note(GWikiLogCategory.Wiki, "IO Error serving: " + ex.getMessage()); } else { GLog.error(GWikiLogCategory.Wiki, "GWikiWeb serve error: " + ex.getMessage(), new LogExceptionAttribute(ex)); } } finally { LoggingServiceManager.get().getStatsDAO().addPerformance(GWikiLogCategory.Wiki, "GWikiServlet.doPost", System.currentTimeMillis() - start, 0); GWikiContext.setCurrent(null); if (daoContext != null) { daoContext.getWikiSelector().deinitWiki(this, req, resp); } } }
From source file:graphql.servlet.GraphQLServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { GraphQLContext context = createContext(Optional.of(req), Optional.of(resp)); String path = req.getPathInfo(); if (path == null) { path = req.getServletPath(); }// ww w . java 2 s .c o m if (path.contentEquals("/schema.json")) { query(CharStreams.toString( new InputStreamReader(GraphQLServlet.class.getResourceAsStream("introspectionQuery"))), null, new HashMap<>(), getSchema(), req, resp, context); } else { if (req.getParameter("q") != null) { query(req.getParameter("q"), null, new HashMap<>(), getReadOnlySchema(), req, resp, context); } else if (req.getParameter("query") != null) { Map<String, Object> variables = new HashMap<>(); if (req.getParameter("variables") != null) { variables.putAll(new ObjectMapper().readValue(req.getParameter("variables"), new TypeReference<Map<String, Object>>() { })); } String operationName = null; if (req.getParameter("operationName") != null) { operationName = req.getParameter("operationName"); } query(req.getParameter("query"), operationName, variables, getReadOnlySchema(), req, resp, context); } } }
From source file:org.openmrs.module.uiframework.FragmentActionController.java
@RequestMapping("**/*.action") public String handleUrlWithDotAction( @RequestParam(value = "returnFormat", required = false) String returnFormat, @RequestParam(value = "successUrl", required = false) String successUrl, @RequestParam(value = "failureUrl", required = false) String failureUrl, HttpServletRequest request, Model model, HttpServletResponse response) throws Exception { // everything after the contextPath, e.g. "/emr/registration/checkin.action" String path = request.getServletPath(); path = path.substring(1, path.lastIndexOf(".action")); return handlePath(path, returnFormat, successUrl, failureUrl, request, model, response); }
From source file:org.artifactory.webapp.servlet.RepoFilter.java
private boolean isGitLfsRequest(HttpServletRequest request) { String lfsApiPath = "/api/" + GitLfsResourceConstants.PATH_ROOT; String joinedRequestPath = request.getServletPath() + request.getPathInfo(); return joinedRequestPath.contains(lfsApiPath) || request.getRequestURL().toString().contains(lfsApiPath); }
From source file:org.shareok.data.webserv.UserSessionInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { try {//from w ww . ja v a 2 s . c o m String contextPath = request.getServletPath(); if (contextPath.contains("/")) { contextPath = contextPath.split("/")[1]; } if (null != contextPath && !"".equals(contextPath) && ShareokdataManager.requiredUserAuthentication(contextPath)) { SessionRepository<Session> repo = (SessionRepository<Session>) request .getAttribute(SessionRepository.class.getName()); if (contextPath.equals("register")) { if (!configService.getRegistrationConfig()) { throw new NoNewUserRegistrationException("The registraion of new users has been closed!"); } String email = (String) request.getParameter("email"); String password = pwAuthenService.hash((String) request.getParameter("password")); String userName = (String) request.getParameter("nickname"); if (null == email || "".equals(email)) { throw new UserRegisterInfoNotFoundException( "Valid email register information is required!"); } if (null == password || "".equals(password)) { throw new UserRegisterInfoNotFoundException("Valid password is required for registration!"); } /***************** * Some password validation logic here: */ HttpSession httpSession = (HttpSession) request.getSession(); ExpiringSession session = (ExpiringSession) repo.getSession(httpSession.getId()); if (null == session) { session = (ExpiringSession) repo.createSession(); } String sessionId = session.getId(); RedisUser user = redisUserService.findUserByUserEmail(email); if (null != user) { throw new RegisterUserInfoExistedException("User Email has already Existed!"); } else { user = redisUserService.getNewUser(); user.setEmail(email); user.setPassword(password); if (null == userName || userName.equals("")) { userName = email; } user.setUserName(userName); user.setSessionKey(sessionId); redisUserService.addUser(user); } setSessionUserInfo(session, httpSession, user); repo.save(session); } else if (contextPath.equals("userLogin")) { String email = (String) request.getParameter("email"); String password = (String) request.getParameter("password"); if (null == email || "".equals(email)) { throw new UserRegisterInfoNotFoundException( "Valid email information is required for logging in!"); } if (null == password || "".equals(password)) { throw new UserRegisterInfoNotFoundException("Valid password is required for logging in!"); } /***************** * Some password validation logic here: */ HttpSession httpSession = (HttpSession) request.getSession(); ExpiringSession session = (ExpiringSession) repo.getSession(httpSession.getId()); if (null == session || session.isExpired()) { session = (ExpiringSession) repo.createSession(); } String sessionId = session.getId(); RedisUser user = redisUserService.findUserByUserEmail(email); if (null == user || !pwAuthenService.authenticate(password, user.getPassword())) { throw new UserRegisterInfoNotFoundException("User information cannot be found!"); } user.setSessionKey(sessionId); redisUserService.updateUser(user); setSessionUserInfo(session, httpSession, user); httpSession.setAttribute("email", email); repo.save(session); } else if (contextPath.equals("logout")) { HttpSession session = (HttpSession) request.getSession(false); if (null != session) { ExpiringSession exSession = (ExpiringSession) repo.getSession(session.getId()); if (null != exSession) { String email = (String) session.getAttribute("email"); if (null != email) { redisUserService.invalidateUserSessionIdByEmail(email); } exSession.isExpired(); repo.delete(exSession.getId()); } session.invalidate(); } } // *** The following situation applies to authentication logic based on session information *** else { boolean sessionValidated = false; HttpSession session = (HttpSession) request.getSession(false); if (null != session) { ExpiringSession exSession = (ExpiringSession) repo.getSession(session.getId()); if (null != exSession && !exSession.isExpired()) { String email = (String) session.getAttribute("email"); if (null != email) { RedisUser userPersisted = redisUserService.findAuthenticatedUser(email, session.getId()); if (null != userPersisted) { sessionValidated = true; } } } } if (!sessionValidated) { if (null != session) { repo.delete(session.getId()); session.setAttribute(ShareokdataManager.getSessionRedisUserAttributeName(), null); session.invalidate(); } request.logout(); //request.getRequestDispatcher("/WEB-INF/jsp/logout.jsp").forward(request, response); HttpServletResponse httpReponse = (HttpServletResponse) response; httpReponse.sendRedirect("/webserv/login"); } } } else { ; } } catch (IOException ex) { request.setAttribute("errorMessage", ex.getMessage()); request.getRequestDispatcher("/WEB-INF/jsp/userError.jsp").forward(request, response); } catch (ServletException ex) { request.setAttribute("errorMessage", ex.getMessage()); request.getRequestDispatcher("/WEB-INF/jsp/userError.jsp").forward(request, response); } catch (UserRegisterInfoNotFoundException ex) { request.setAttribute("errorMessage", ex.getMessage()); request.getRequestDispatcher("/WEB-INF/jsp/userError.jsp").forward(request, response); } catch (RegisterUserInfoExistedException ex) { request.setAttribute("errorMessage", ex.getMessage()); request.getRequestDispatcher("/WEB-INF/jsp/userError.jsp").forward(request, response); } catch (NoNewUserRegistrationException ex) { request.setAttribute("errorMessage", ex.getMessage()); request.getRequestDispatcher("/WEB-INF/jsp/closedRegistration.jsp").forward(request, response); } return true; }
From source file:com.mawujun.util.web.UrlPathHelper.java
/** * Return the servlet path for the given request, regarding an include request * URL if called within a RequestDispatcher include. * <p>As the value returned by <code>request.getServletPath()</code> is already * decoded by the servlet container, this method will not attempt to decode it. * @param request current HTTP request/*from ww w.j a v a 2s . c om*/ * @return the servlet path */ public String getServletPath(HttpServletRequest request) { String servletPath = (String) request.getAttribute(WebUtils.INCLUDE_SERVLET_PATH_ATTRIBUTE); if (servletPath == null) { servletPath = request.getServletPath(); } return servletPath; }