List of usage examples for javax.servlet.http HttpServletResponse sendRedirect
public void sendRedirect(String location) throws IOException;
From source file:com.agiletec.aps.tags.ExecWidgetTag.java
/** * Invoke the widget configured in the page. * * @throws JspException In case of errors in this method or in the included * JSPs//from www. j av a 2 s . co m */ @Override public int doEndTag() throws JspException { ServletRequest req = this.pageContext.getRequest(); RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX); try { reqCtx.addExtraParam(SystemConstants.EXTRAPAR_HEAD_INFO_CONTAINER, new HeadInfoContainer()); IPage page = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE); String[] widgetOutput = new String[page.getWidgets().length]; reqCtx.addExtraParam("ShowletOutput", widgetOutput); this.buildWidgetOutput(page, widgetOutput); String redirect = (String) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXTERNAL_REDIRECT); if (null != redirect) { HttpServletResponse response = (HttpServletResponse) this.pageContext.getResponse(); response.sendRedirect(redirect); return SKIP_PAGE; } this.pageContext.popBody(); } catch (Throwable t) { String msg = "Error detected during widget preprocessing"; ApsSystemUtils.logThrowable(t, this, "doEndTag", msg); throw new JspException(msg, t); } return super.doEndTag(); }
From source file:fr.aliasource.webmail.server.LemonSSOProvider.java
@Override public boolean redirectToSSOServer(String myUrl, Map<String, String> p, HttpServletRequest req, HttpServletResponse resp) { String url = p.get(SSO_SERVER_URL) + "?action=ticket&service=" + myUrl; try {//from w w w.ja v a 2 s .c o m logger.info("Redirecting to sso server: " + url); resp.sendRedirect(url); } catch (IOException e) { logger.error("Error redirecting to sso server", e); } wentToSSO = true; return true; }
From source file:org.shareok.data.webserv.filters.UserSessionFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try {/*ww w . java2 s . co m*/ HttpServletRequest httpRequest = (HttpServletRequest) request; String contextPath = httpRequest.getServletPath(); if (contextPath.contains("/")) { contextPath = contextPath.split("/")[1]; } //.getContextPath(); if (null != contextPath && !"".equals(contextPath) && ShareokdataManager.requiredUserAuthentication(contextPath)) { SessionRepository<Session> repo = (SessionRepository<Session>) httpRequest .getAttribute(SessionRepository.class.getName()); if (contextPath.equals("register")) { String email = (String) httpRequest.getParameter("email"); String password = (String) httpRequest.getParameter("password"); String userName = (String) httpRequest.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: */ ExpiringSession session = (ExpiringSession) repo.createSession(); session.setMaxInactiveIntervalInSeconds(600); String sessionId = session.getId(); RedisUser user = redisUserService.findUserByUserEmail(email); if (null != user && password.equals(user.getPassword())) { session.setAttribute(ShareokdataManager.getSessionRedisUserAttributeName(), user); user.setSessionKey(sessionId); user.setUserName(userName); redisUserService.updateUser(user); } else if (null == user) { ApplicationContext context = new ClassPathXmlApplicationContext("redisContext.xml"); user = (RedisUser) context.getBean("redisUser"); user.setEmail(email); user.setPassword(password); user.setSessionKey(sessionId); redisUserService.addUser(user); } else if (null != user && !password.equals(user.getPassword())) { throw new UserRegisterInfoNotFoundException( "Your login information does not match our records!`"); } session.setAttribute(ShareokdataManager.getSessionRedisUserAttributeName(), user); repo.save(session); chain.doFilter(request, response); // HttpServletResponse httpReponse = (HttpServletResponse)response; // httpReponse.sendRedirect("/webserv/home"); } else { boolean sessionValidated = false; HttpSession session = (HttpSession) httpRequest.getSession(false); if (null != session) { ExpiringSession exSession = (ExpiringSession) repo.getSession(session.getId()); if (null != exSession) { RedisUser user = (RedisUser) session .getAttribute(ShareokdataManager.getSessionRedisUserAttributeName()); if (null != user) { RedisUser userPersisted = redisUserService.findAuthenticatedUser(user.getEmail(), session.getId()); if (null != userPersisted) { sessionValidated = true; } } } } if (!sessionValidated) { if (null != session) { repo.delete(session.getId()); session.setAttribute(ShareokdataManager.getSessionRedisUserAttributeName(), null); session.invalidate(); } httpRequest.logout(); //request.getRequestDispatcher("/WEB-INF/jsp/logout.jsp").forward(request, response); HttpServletResponse httpReponse = (HttpServletResponse) response; httpReponse.sendRedirect("/webserv/login"); } else { chain.doFilter(request, response); } } } else { chain.doFilter(request, response); } } catch (IOException ex) { request.setAttribute("errorMessage", ex); request.getRequestDispatcher("/WEB-INF/jsp/userError.jsp").forward(request, response); } catch (ServletException ex) { request.setAttribute("errorMessage", ex); request.getRequestDispatcher("/WEB-INF/jsp/userError.jsp").forward(request, response); } catch (UserRegisterInfoNotFoundException ex) { request.setAttribute("errorMessage", ex); request.getRequestDispatcher("/WEB-INF/jsp/userError.jsp").forward(request, response); } }
From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.LoginServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {/*w w w .j ava 2 s .c om*/ User user = (User) req.getAttribute("user"); user.setLastLogin(new Date()); this.servicesClient.updateUser(user, user.getId()); resp.sendRedirect(req.getContextPath() + "/index.jsp"); } catch (ClientException e) { Status responseStatus = e.getResponseStatus(); if (responseStatus == Status.FORBIDDEN) { HttpSession session = req.getSession(false); if (session != null) { session.invalidate(); } resp.sendError(HttpStatus.SC_FORBIDDEN); } else { throw new ServletException(e); } } }
From source file:com.r3bl.controller.LoginInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String uri = request.getRequestURI(); if (uri.contains("dashboard")) { Usuario u = (Usuario) request.getSession().getAttribute("usuarioLogado"); if (u == null) { response.sendRedirect(request.getContextPath() + "/login"); return false; }/* w w w.j a v a 2 s. c om*/ } return true; }
From source file:com.starr.smartbuilds.controller.AuthController.java
@RequestMapping(method = { RequestMethod.POST }) public String addUser(@ModelAttribute("auth") AuthService auth, Model model, HttpServletRequest req, HttpServletResponse resp) throws IOException { User user = auth.checkAuth(userDAO); HttpSession session = req.getSession(); if (user != null) { // session.setAttribute("user", user); resp.sendRedirect("./"); } else {//from w ww . j av a 2 s. c o m model.addAttribute("authMsg", "<a href='./auth'>Log in</a>"); model.addAttribute("exitReg", "<a href='./reg'>Register</a>"); model.addAttribute("result", "<font color='red'><b>Wrong email or password!</b></font>"); } return "authorization"; }
From source file:org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationEntryPoint.java
protected void commenceLoginRedirect(HttpServletRequest request, HttpServletResponse response) throws IOException { String contextAwareLoginUri = request.getContextPath() + loginUri; log.debug("Redirecting to login URI {}", contextAwareLoginUri); response.sendRedirect(contextAwareLoginUri); }
From source file:net.e2.bw.idreg.OIDCService.java
/** * Invalidates the user http session.//from w ww .j a v a2 s . co m * * @param response the servlet response * @throws IOException */ @RequestMapping(value = "/logout") public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException { if (request.getSession() != null) { request.getSession().invalidate(); } response.sendRedirect("/"); }
From source file:vmware.au.se.sqlfireweb.controller.HistoryController.java
@RequestMapping(value = "/history", method = RequestMethod.GET) public String showHistory(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/sqlfireweb/login"); return null; }// w w w . j a v a2 s. com logger.debug("Received request to show command history"); UserPref userPref = (UserPref) session.getAttribute("prefs"); String histAction = request.getParameter("histAction"); if (histAction != null) { logger.debug("histAction = " + histAction); // clear history session.setAttribute("history", new LinkedList()); model.addAttribute("historyremoved", "Succesfully cleared history list"); } LinkedList historyList = (LinkedList) session.getAttribute("history"); int maxsize = userPref.getHistorySize(); model.addAttribute("historyList", historyList.toArray()); model.addAttribute("historysize", historyList.size()); // This will resolve to /WEB-INF/jsp/history.jsp return "history"; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginRedirector.java
public void redirectLoggedInUser(HttpServletResponse response) throws IOException { try {/*from www. j av a 2 s.c o m*/ DisplayMessage.setMessage(request, assembleWelcomeMessage()); response.sendRedirect(getRedirectionUriForLoggedInUser()); } catch (IOException e) { log.debug("Problem with re-direction", e); response.sendRedirect(getApplicationHomePageUrl()); } }