List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:Controladores.AutorizadorAcesso.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object controller) throws Exception { String uri = request.getRequestURI(); if (uri.toUpperCase().contains("RESTRITO")) { if (request.getSession().getAttribute("logado") == null || (boolean) request.getSession().getAttribute("logado") == false) { if (request.getQueryString() != null) { uri += "?" + request.getQueryString(); }//from w ww .java2 s. co m request.getSession().setAttribute("endereco", uri); RequestDispatcher dispacher = request.getRequestDispatcher("exibe-login"); dispacher.forward(request, response); return false; } } return true; }
From source file:com.parallax.server.blocklyprop.servlets.NewOAuthUserServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Read out email and authentication source from session HttpSession session = req.getSession(); String email = (String) session.getAttribute("oauth-email"); String authenticator = (String) session.getAttribute("oauth-authenticator"); if (Strings.isNullOrEmpty(email) || Strings.isNullOrEmpty(authenticator)) { log.error("New OAuth request while missing info in session"); req.getRequestDispatcher("/WEB-INF/servlet/oauth/server-error.jsp").forward(req, resp); }/*w ww . j a v a 2 s. c o m*/ String screenname = req.getParameter("screenname"); if (Strings.isNullOrEmpty(screenname)) { req.setAttribute("missing-error", "Missing fields"); req.getRequestDispatcher("/WEB-INF/servlet/profile/profile.jsp").forward(req, resp); } else { try { // Create user oauthService.registerUser(email, authenticator, "en", screenname); // Authenticate user Subject currentUser = SecurityUtils.getSubject(); OAuthToken authenticationToken = new OAuthToken(email, authenticator); try { currentUser.login(authenticationToken); } catch (Throwable t) { log.error("Error while authenticating", t); } // Show confirm or straight redirect SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(req); if (savedRequest != null) { req.setAttribute("redirect", savedRequest.getRequestUrl()); } req.getRequestDispatcher("/WEB-INF/servlet/oauth/success.jsp").forward(req, resp); } catch (NonUniqueEmailException ex) { log.error("Non unique email exception", ex); req.getRequestDispatcher("/WEB-INF/servlet/oauth/server-error.jsp").forward(req, resp); } catch (ScreennameUsedException ex) { // Username already in use req.setAttribute("screenname", screenname); req.setAttribute("screenname-error", "screenname-used"); req.getRequestDispatcher("/WEB-INF/servlet/oauth/new-oauth-user.jsp").forward(req, resp); } catch (ServerException ex) { log.error("A server exception accured in the oauth authentication process", ex); req.getRequestDispatcher("/WEB-INF/servlet/oauth/server-error.jsp").forward(req, resp); } } }
From source file:com.persistent.cloudninja.controller.CloudNinjaAuthFilter.java
public void forwardToVerificationPage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String guid, String acsToken) { try {/*from www . j a va 2s. co m*/ httpServletRequest.setAttribute("guid", guid); httpServletRequest.setAttribute("acsToken", acsToken); httpServletRequest.getRequestDispatcher("/codeVerification.htm").forward(httpServletRequest, httpServletResponse); } catch (ServletException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.sarons.spring4me.web.filter.PageFilter.java
@Override protected void doService(HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterChain chain) throws IOException, ServletException { try {/*w ww. j a v a2 s .c o m*/ PageConfig pageConfig = getPageConfig(httpRequest); PageConfigUtils.setPageConfig(httpRequest, pageConfig); // this.pageRender.render(httpRequest, httpResponse); // forward this request and stop continue filter String pagePath = pageConfig.getPath() + ".page"; httpRequest.getRequestDispatcher(pagePath).forward(httpRequest, httpResponse); // } catch (PageNotFoundException e) { // chain.doFilter(httpRequest, httpResponse); } }
From source file:oracle.custom.ui.servlet.LoginServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww. j ava 2 s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); //System.out.println("User Agent " + request.getHeader("User-Agent")); try (PrintWriter out = response.getWriter()) { // if we come back here after the user is already authenticated it means // that we're looking for OAuth consent if (request.getSession().getAttribute("AUTHENTICATED") != null) { request.getRequestDispatcher("/oauthallowed.jsp").forward(request, response); } try { String tenantName = (String) DomainName.getDomainName(); String endpoint = OpenIdConfiguration.getInstance(tenantName).getAuthzEndpoint(); String clientId = CredentialsList.getCredentials().get(tenantName).getId(); StringBuffer url = request.getRequestURL(); String uri = request.getRequestURI(); String ctx = request.getContextPath(); String base = url.substring(0, url.length() - uri.length() + ctx.length()) + "/"; //String redirecturl = base + "atreturn/"; //String openIdConfig = endpoint + "?client_id=" + clientId + // "&response_type=code&redirect_uri=" + redirecturl + // "&scope=urn:opc:idm:t.user.me+openid+urn:opc:idm:__myscopes__&nonce=" + UUID.randomUUID().toString(); URIBuilder builder = new URIBuilder(endpoint); builder.addParameter("client_id", clientId); builder.addParameter("response_type", "code"); builder.addParameter("redirect_uri", base + "atreturn/"); builder.addParameter("scope", "urn:opc:idm:t.user.me openid urn:opc:idm:__myscopes__"); builder.addParameter("nonce", UUID.randomUUID().toString()); URI redirectUrl = builder.build(); System.out.println("Opend Id URL is " + redirectUrl.toString()); response.sendRedirect(redirectUrl.toString()); } catch (Exception ex) { ex.printStackTrace(); request.getRequestDispatcher("/error.jsp").forward(request, response); } } }
From source file:org.apache.niolex.config.util.LoginInterceptor.java
@Override public final boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException { CenterConnector cc = ConnectorUtil.getConnector(request); if (cc == null) { String s = request.getRequestURI(); if (s.equals(contextRoot) || s.contains("/login") || s.endsWith(".html")) { return true; }// ww w. ja v a 2s. c om if (request.getAttribute(KEY) == null) { request.setAttribute(KEY, "?????"); request.getRequestDispatcher("/login").forward(request, response); return false; } else { return true; } } else if (!cc.isWorking()) { ConnectorUtil.invalidateSession(request); request.setAttribute(KEY, "??????"); request.getRequestDispatcher("/login").forward(request, response); return false; } return true; }
From source file:cn.imethan.common.security.handle.AccessDeniedHandlerImpl.java
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { if (!response.isCommitted()) { if (errorPage != null) { // Put exception into request scope (perhaps of use to a view) request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException); // Set the 403 status code. response.setStatus(HttpServletResponse.SC_FORBIDDEN); // forward to error page. RequestDispatcher dispatcher = request.getRequestDispatcher(errorPage); dispatcher.forward(request, response); } else {/*from ww w.j av a2 s .c o m*/ response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage()); } } }
From source file:io.lavagna.web.security.login.PersonaLogin.java
@Override public boolean handleLogout(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { if ("POST".equalsIgnoreCase(req.getMethod())) { UserSession.invalidate(req, resp, userRepository); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("application/json"); JsonObject jsonObject = new JsonObject(); jsonObject.add("redirectToSelf", new JsonPrimitive(true)); resp.getWriter().write(jsonObject.toString()); } else {/*from www . java 2s. c o m*/ req.getRequestDispatcher(logoutPage).forward(req, resp); } return true; }
From source file:com.sun.socialsite.web.rest.servlets.ImageServlet.java
/** * Handles the HTTP <code>GET</code> method. * @param req servlet request/*from www.j a v a 2s. c o m*/ * @param resp servlet response */ @Override protected final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String itemName = ((req.getPathInfo() != null) ? req.getPathInfo().substring(1) : null); if (itemName != null) itemName = URLDecoder.decode(itemName, "UTF-8"); Result result = getResult(itemName); if ((result == null) || (result.imageType == null) || (result.imageType.equals(""))) { RequestDispatcher rd = req.getRequestDispatcher(defaultImage); rd.forward(req, resp); return; } long ifModifiedTime = 0L; if (req.getHeader("If-Modified-Since") != null) { try { ifModifiedTime = getDateFormat().parse(req.getHeader("If-Modified-Since")).getTime(); } catch (Throwable intentionallyIgnored) { } } // We've got an EHCache GenericResponseWrapper, it ignores date headers //resp.setDateHeader("Last-Modified", lastModifiedString); resp.setHeader("Last-Modified", getDateFormat().format(result.lastUpdate)); resp.setHeader("ETag", result.eTag); // Force clients to revalidate each time // See RFC 2616 (HTTP 1.1 spec) secs 14.21, 13.2.1 // We've got an EHCache GenericResponseWrapper, it ignores date headers //resp.setDateHeader("Expires", 0); resp.setHeader("Expires", epoch); // We may also want this (See 13.2.1 and 14.9.4) // response.setHeader("Cache-Control","must-revalidate"); if (result.lastUpdate.getTime() > ifModifiedTime || !handleConditionalGets) { resp.setContentType(result.imageType); resp.setContentLength(result.imageBytes.length); OutputStream out = resp.getOutputStream(); out.write(result.imageBytes, 0, result.imageBytes.length); out.close(); } else { resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED); } return; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.NamespacePrefixRetryController.java
public void doGet(HttpServletRequest request, HttpServletResponse response) { if (!isAuthorizedToDisplayPage(request, response, SimplePermission.USE_MISCELLANEOUS_ADMIN_PAGES.ACTION)) { return;//from w ww .j a v a 2 s . co m } //create an EditProcessObject for this and put it in the session EditProcessObject epo = super.createEpo(request); if (request.getParameter("prefix") != null) { epo.setAction("update"); request.setAttribute("_action", "update"); } else { epo.setAction("insert"); request.setAttribute("_action", "insert"); } RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("editAction", "namespacePrefixOp"); request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp"); request.setAttribute("scripts", "/templates/edit/formBasic.js"); request.setAttribute("formJsp", "/templates/edit/specific/namespacePrefix_retry.jsp"); request.setAttribute("title", "Edit Namespace Prefix Mapping"); setRequestAttributes(request, epo); try { rd.forward(request, response); } catch (Exception e) { log.error(this.getClass().getName() + " could not forward to view."); log.error(e.getMessage()); log.error(e.getStackTrace()); } }