List of usage examples for javax.servlet.http HttpServletResponse SC_MOVED_TEMPORARILY
int SC_MOVED_TEMPORARILY
To view the source code for javax.servlet.http HttpServletResponse SC_MOVED_TEMPORARILY.
Click Source Link
From source file:io.mapzone.controller.vm.http.LoginProvision.java
@Override public Status execute() throws Exception { checked.set(this); // check authToken AuthTokenValidator atv = new AuthTokenValidator(() -> projectUow(), request.get()); if (atv.checkAuthToken()) { String clientHost = request.get().getRemoteHost(); log.info("AuthToken: valid, for client: " + clientHost); registerUser(clientHost, response.get()); // who we are? does arena need a user? return OK_STATUS; }/*from w w w .ja va 2 s .c om*/ // cookie -> OK Optional<Cookie> cookie = Arrays.stream(request.get().getCookies()) .filter(c -> c.getName().equals(COOKIE_NAME)).findAny(); if (cookie.isPresent()) { String userId = loggedIn.get(cookie.get().getValue()); if (userId != null) { return OK_STATUS; } } // check /dashboard login Optional<LoginCookie> loginCookie = LoginCookie.access(request.get(), response.get()).findAndUpdate(); if (loginCookie.isPresent()) { registerUser((String) loginCookie.get().user.get().id(), response.get()); return OK_STATUS; } // no cookie -> /login String requestUrl = Joiner.on("").skipNulls().join(request.get().getServletPath(), request.get().getPathInfo(), "?", request.get().getQueryString()); String handlerId = LoginAppDesign.registerHandler(user -> { try { registerUser((String) user.id(), RWT.getResponse()); UIUtils.exec("window.location=\"", requestUrl, "\";"); } catch (Exception e) { throw new RuntimeException(e); } }); // http://stackoverflow.com/questions/30844807/can-a-redirect-to-relative-path-be-sent-from-java-servlet-api // response.get().sendRedirect( "../../../login?id=" + handlerId ); response.get().setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.get().setHeader("Location", "../../../login?id=" + handlerId); throw new ProvisionRuntimeException(); }
From source file:net.fenyo.mail4hotspot.web.GMailOAuthStep1Servlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/*from w w w.j a va 2s . co m*/ if (request.getPathInfo().equals("/step1")) { // final String uuid = request.getParameter("uuid"); final String nonce = nonce(); final String now = now(); log.debug("nonce=" + nonce); log.debug("now=" + now); final String base_string = "GET&" + urlEncode("https://www.google.com/accounts/OAuthGetRequestToken") + "&" + urlEncode("oauth_callback=" + urlEncode(base + "oauth/step2") + "&oauth_consumer_key=www.vpnoverdns.com&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_version=1.0&scope=" + urlEncode("https://mail.google.com/")); log.debug("digestencoded=" + urlEncode(hmac(consumer_secret + "&", base_string))); final String url = "https://www.google.com/accounts/OAuthGetRequestToken?oauth_consumer_key=www.vpnoverdns.com&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_version=1.0&oauth_callback=" + urlEncode(base + "oauth/step2") + "&scope=" + urlEncode("https://mail.google.com/") + "&oauth_signature=" + urlEncode(hmac(consumer_secret + "&", base_string)); final String reply = Browser.getHtml(url, null); // request_token est URL encoded final String request_token = parseReply("oauth_token", reply); // request_token_secret est URL encoded final String request_token_secret = parseReply("oauth_token_secret", reply); log.debug("oauthtoken=" + request_token); log.debug("oauthtokensecret=" + request_token_secret); if (request_token == null || request_token_secret == null) { log.error("token error: token=" + request_token + " - token_secret=" + request_token_secret); return; } map_request_token.put(urlDecode(request_token), urlDecode(request_token_secret)); response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=" + request_token); final PrintWriter out = response.getWriter(); out.println( "<html><body>click <a href='https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=" + request_token + "'>here</a></body></html>"); } if (request.getPathInfo().equals("/step2")) { final String verifier = request.getParameter("oauth_verifier"); // request_token n'est pas URL encoded final String request_token = request.getParameter("oauth_token"); // request_token_secret n'est pas URL encoded final String request_token_secret = map_request_token.get(request_token); log.debug("oauthtoken=" + request_token); log.debug("oauthtokensecret=" + request_token_secret); log.debug("verifier=" + verifier); String nonce = nonce(); String now = now(); log.debug("nonce=" + nonce); log.debug("now=" + now); String base_string = "GET&" + urlEncode("https://www.google.com/accounts/OAuthGetAccessToken") + "&" + urlEncode("oauth_consumer_key=www.vpnoverdns.com&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_token=" + urlEncode(request_token) + "&oauth_verifier=" + urlEncode(verifier) + "&oauth_version=1.0"); log.debug("digestencoded=" + urlEncode(hmac(consumer_secret + "&" + request_token_secret, base_string))); String url = "https://www.google.com/accounts/OAuthGetAccessToken?oauth_consumer_key=www.vpnoverdns.com&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_token=" + urlEncode(request_token) + "&oauth_verifier=" + urlEncode(verifier) + "&oauth_version=1.0&oauth_signature=" + urlEncode(hmac(consumer_secret + "&" + request_token_secret, base_string)); final String reply = Browser.getHtml(url, null); // access token est URL encoded final String access_token = parseReply("oauth_token", reply); // access_token_secret est URL encoded final String access_token_secret = parseReply("oauth_token_secret", reply); log.debug("oauthaccesstoken=" + access_token); log.debug("oauthaccesstokensecret=" + access_token_secret); nonce = nonce(); now = now(); log.debug("nonce=" + nonce); log.debug("now=" + now); base_string = "GET&" + urlEncode("https://mail.google.com/mail/b/alexandre.fenyo2@gmail.com/imap/") + "&" + urlEncode("oauth_consumer_key=www.vpnoverdns.com&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_token=" + access_token + "&oauth_version=1.0"); // oauth_token=\"$oauthaccesstoken\",oauth_version=\"1.0\",oauth_signature=\"$digestencoded\"" | read URL log.debug("digestencoded=" + urlEncode(hmac(consumer_secret + "&" + urlDecode(access_token_secret), base_string))); url = "GET https://mail.google.com/mail/b/alexandre.fenyo2@gmail.com/imap/ oauth_consumer_key=\"www.vpnoverdns.com\",oauth_nonce=\"" + nonce + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" + now + "\",oauth_token=\"" + access_token + "\",oauth_version=\"1.0\",oauth_signature=\"" + urlEncode(hmac(consumer_secret + "&" + urlDecode(access_token_secret), base_string)) + "\""; log.debug(org.apache.commons.codec.binary.Base64.encodeBase64String(url.getBytes("UTF-8"))); } } catch (InvalidKeyException ex) { log.error(ex.toString()); } catch (NoSuchAlgorithmException ex) { log.error(ex.toString()); } }
From source file:application.controllers.admin.EditEmotion.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String linkImage = uploadNewImage(request, response); EmotionBOImpl emotionBoImpl = new EmotionBOImpl(); // emotionSelected.description = description; // emotionSelected.groupEmotionId = groupEmotionId; // emotionSelected.linkImage = linkImage; // emotionSelected.description = request.getParameter("description"); // emotionSelected.linkImage = request.getParameter("imageURL"); // emotionSelected.groupEmotionId = Integer.parseInt(request.getParameter("groupEmotion")); //edit link image and groupEmotionId if (!emotionBoImpl.editEmotion(emotionSelected)) { //if error show view error View layout = new View("Index.xtm"); View view = new View("admin", "EditEmotion.xtm"); view.setVariable("errorExist", "Error when edit emotion"); String content = view.render(); layout.setVariable("content", content); String mainView = layout.render(); response.getWriter().write(mainView); }/*from w ww . j a v a 2s . c om*/ String newURL = response.encodeRedirectURL( Registry.get("Host") + "/groupEmotion/emotion?groupId=" + emotionSelected.groupEmotionId); response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", newURL); response.setContentType("text/html"); }
From source file:com.google.ie.common.openid.appengine.Openid4javaFetcher.java
private static boolean isRedirect(int responseCode) { switch (responseCode) { case HttpServletResponse.SC_MOVED_PERMANENTLY: case HttpServletResponse.SC_MOVED_TEMPORARILY: case HttpServletResponse.SC_SEE_OTHER: case HttpServletResponse.SC_TEMPORARY_REDIRECT: return true; default://from w w w .j a v a2s.c om return false; } }
From source file:net.fenyo.mail4hotspot.web.YahooOAuthStep1Servlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/* w w w . j a v a 2s . co m*/ if (request.getPathInfo().equals("/step1")) { // final String uuid = request.getParameter("uuid"); final String nonce = nonce(); final String now = now(); log.debug("nonce=" + nonce); log.debug("now=" + now); final String base_string = "GET&" + urlEncode("https://api.login.yahoo.com/oauth/v2/get_request_token") + "&" + urlEncode("oauth_callback=" + urlEncode(base + "yoauth/step2") + "&oauth_consumer_key=" + urlEncode( "dj0yJmk9UmZhMmthTU1EcVExJmQ9WVdrOWIxZEZaMWRGTldNbWNHbzlNVGMyTmprME5qSS0mcz1jb25zdW1lcnNlY3JldCZ4PTc2") + "&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_version=1.0"); log.debug("digestencoded=" + urlEncode(hmac(consumer_secret + "&", base_string))); final String url = "https://api.login.yahoo.com/oauth/v2/get_request_token?oauth_consumer_key=" + urlEncode( "dj0yJmk9UmZhMmthTU1EcVExJmQ9WVdrOWIxZEZaMWRGTldNbWNHbzlNVGMyTmprME5qSS0mcz1jb25zdW1lcnNlY3JldCZ4PTc2") + "&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_version=1.0&oauth_callback=" + urlEncode(base + "yoauth/step2") + "&oauth_signature=" + urlEncode(hmac(consumer_secret + "&", base_string)); final String reply = Browser.getHtml(url, null); // request_token est URL encoded final String request_token = parseReply("oauth_token", reply); // request_token_secret est URL encoded final String request_token_secret = parseReply("oauth_token_secret", reply); log.debug("oauthtoken=" + request_token); log.debug("oauthtokensecret=" + request_token_secret); if (request_token == null || request_token_secret == null) { log.error("token error: token=" + request_token + " - token_secret=" + request_token_secret); return; } map_request_token.put(urlDecode(request_token), urlDecode(request_token_secret)); final String xoauth_request_auth_url = parseReply("xoauth_request_auth_url", reply); log.debug("xoauth_request_auth_url=" + xoauth_request_auth_url); response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", urlDecode(xoauth_request_auth_url)); final PrintWriter out = response.getWriter(); out.println("<html><body>click <a href='" + urlDecode(xoauth_request_auth_url) + "'>here</a></body></html>"); } if (request.getPathInfo().equals("/step2")) { final String verifier = request.getParameter("oauth_verifier"); // request_token n'est pas URL encoded final String request_token = request.getParameter("oauth_token"); // request_token_secret n'est pas URL encoded final String request_token_secret = map_request_token.get(request_token); log.debug("oauthtoken=" + request_token); log.debug("oauthtokensecret=" + request_token_secret); log.debug("verifier=" + verifier); String nonce = nonce(); String now = now(); log.debug("nonce=" + nonce); log.debug("now=" + now); String base_string = "GET&" + urlEncode("https://api.login.yahoo.com/oauth/v2/get_token") + "&" + urlEncode("oauth_consumer_key=" + urlEncode( "dj0yJmk9UmZhMmthTU1EcVExJmQ9WVdrOWIxZEZaMWRGTldNbWNHbzlNVGMyTmprME5qSS0mcz1jb25zdW1lcnNlY3JldCZ4PTc2") + "&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_token=" + urlEncode(request_token) + "&oauth_verifier=" + urlEncode(verifier) + "&oauth_version=1.0"); log.debug("digestencoded=" + urlEncode(hmac(consumer_secret + "&" + request_token_secret, base_string))); String url = "https://api.login.yahoo.com/oauth/v2/get_token?oauth_consumer_key=" + urlEncode( "dj0yJmk9UmZhMmthTU1EcVExJmQ9WVdrOWIxZEZaMWRGTldNbWNHbzlNVGMyTmprME5qSS0mcz1jb25zdW1lcnNlY3JldCZ4PTc2") + "&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_token=" + urlEncode(request_token) + "&oauth_verifier=" + urlEncode(verifier) + "&oauth_version=1.0&oauth_signature=" + urlEncode(hmac(consumer_secret + "&" + request_token_secret, base_string)); final String reply = Browser.getHtml(url, null); // access token est URL encoded final String access_token = parseReply("oauth_token", reply); // access_token_secret est URL encoded final String access_token_secret = parseReply("oauth_token_secret", reply); log.debug("oauthaccesstoken=" + access_token); log.debug("oauthaccesstokensecret=" + access_token_secret); final String xoauth_yahoo_guid = parseReply("xoauth_yahoo_guid", reply); log.debug("xoauth_yahoo_guid=" + xoauth_yahoo_guid); nonce = nonce(); now = now(); log.debug("nonce=" + nonce); log.debug("now=" + now); base_string = "GET&" + urlEncode("https://mail.google.com/mail/b/alexandre.fenyo2@gmail.com/imap/") + "&" + urlEncode("oauth_consumer_key=www.vpnoverdns.com&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_token=" + access_token + "&oauth_version=1.0"); // oauth_token=\"$oauthaccesstoken\",oauth_version=\"1.0\",oauth_signature=\"$digestencoded\"" | read URL log.debug("digestencoded=" + urlEncode(hmac(consumer_secret + "&" + urlDecode(access_token_secret), base_string))); url = "GET https://mail.google.com/mail/b/alexandre.fenyo2@gmail.com/imap/ oauth_consumer_key=\"www.vpnoverdns.com\",oauth_nonce=\"" + nonce + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" + now + "\",oauth_token=\"" + access_token + "\",oauth_version=\"1.0\",oauth_signature=\"" + urlEncode(hmac(consumer_secret + "&" + urlDecode(access_token_secret), base_string)) + "\""; log.debug(org.apache.commons.codec.binary.Base64.encodeBase64String(url.getBytes("UTF-8"))); // String url2 = // "GET https://mail.google.com/mail/b/alexandre.fenyo2@gmail.com/imap/ oauth_consumer_key=\"www.vpnoverdns.com\",oauth_nonce=\"" + // nonce + // "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" + // now + // "\",oauth_token=\"" + // access_token + // "\",oauth_version=\"1.0\",oauth_signature=\"" + // urlEncode(hmac(consumer_secret + "&" + urlDecode(access_token_secret), base_string)) +"\""; // log.debug(org.apache.commons.codec.binary.Base64.encodeBase64String(url.getBytes("UTF-8"))); } } catch (InvalidKeyException ex) { log.error(ex.toString()); } catch (NoSuchAlgorithmException ex) { log.error(ex.toString()); } }
From source file:grails.plugin.cache.web.GenericResponseWrapper.java
/** * Send the redirect. If the response is not ok, most of the logic is * bypassed and the error is sent raw. Also, the content is not cached. * * @param string the URL to redirect to// www.j a v a2 s. c om * @throws IOException */ @Override public void sendRedirect(String string) throws IOException { statusCode = HttpServletResponse.SC_MOVED_TEMPORARILY; super.sendRedirect(string); }
From source file:org.everit.authentication.http.session.ecm.tests.SessionAuthenticationComponentTest.java
private void logoutPost(final HttpContext httpContext) throws ClientProtocolException, IOException { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(logoutUrl); HttpResponse httpResponse = httpClient.execute(httpPost, httpContext); Assert.assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, httpResponse.getStatusLine().getStatusCode()); Header locationHeader = httpResponse.getFirstHeader("Location"); Assert.assertEquals(loggedOutUrl, locationHeader.getValue()); }
From source file:com.cloudbees.tomcat.valves.PrivateAppValveIntegratedTest.java
@Test public void form_authentication_scenario() throws Exception { System.out.println("form_authentication_scenario"); privateAppValve.setAuthenticationEntryPoint(PrivateAppValve.AuthenticationEntryPoint.FORM_AUTH); {// w w w .ja v a 2s.c o m // ANONYMOUS REQUEST RENDERS LOGIN FORM HttpGet request = new HttpGet("/"); HttpResponse response = httpClient.execute(httpHost, request); assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpServletResponse.SC_OK)); assertThat(response.containsHeader("WWW-Form-Authenticate"), is(true)); dumpHttpResponse(response); EntityUtils.consumeQuietly(response.getEntity()); } { // AUTHENTICATION REQUEST HttpPost request = new HttpPost(privateAppValve.getAuthenticationUri()); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("username", accessKey)); nvps.add(new BasicNameValuePair("password", secretKey)); request.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); HttpResponse response = httpClient.execute(httpHost, request); assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpServletResponse.SC_MOVED_TEMPORARILY)); dumpHttpResponse(response); EntityUtils.consumeQuietly(response.getEntity()); } { // ALREADY AUTHENTICATED REQUEST HttpGet request = new HttpGet("/"); HttpResponse response = httpClient.execute(httpHost, request); assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpServletResponse.SC_OK)); assertThat(response.containsHeader("x-response"), is(true)); dumpHttpResponse(response); EntityUtils.consumeQuietly(response.getEntity()); } }
From source file:com.platybox.app.oauth.AuthorizationController.java
private ModelAndView returnToConsumer(OAuthMessage requestMessage, HttpServletRequest request, HttpServletResponse response, OAuthAccessor accessor) throws IOException, ServletException { // send the user back to site's callBackUrl String callback = requestMessage.getParameter("oauth_callback"); if ("none".equals(callback) && accessor.consumer.callbackURL != null && accessor.consumer.callbackURL.length() > 0) { // first check if we have something in our properties file callback = accessor.consumer.callbackURL; }//from w ww. j a v a 2 s . c o m if ("none".equals(callback) && accessor.getProperty("callback_url") != null && accessor.getProperty("callback_url").toString().length() > 0) { // first check if we have something in our properties file callback = accessor.getProperty("callback_url").toString(); } if ("none".equals(callback)) { // no call back it must be a client response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.println("You have successfully authorized '" + accessor.consumer.getProperty("description") + "'. Please close this browser window and click continue" + " in the client."); out.close(); } else { // if callback is not passed in, use the callback from config if (callback == null || callback.length() <= 0) callback = accessor.consumer.callbackURL; String token = accessor.requestToken; if (token != null) { callback = OAuth.addParameters(callback, "oauth_token", token); //TODO: THIS IS a hack for spring security, this needs to be coded.t callback = OAuth.addParameters(callback, "oauth_verifier", "K32H872"); } response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", callback); } return new ModelAndView("redirect:" + callback); }
From source file:ie.wombat.rt.fireeagle.CookieConsumer.java
/** * Handle an exception that occurred while processing an HTTP request. * Depending on the exception, either send a response, redirect the client * or propagate an exception.// ww w .java2s .co m */ public static void handleException(Exception e, HttpServletRequest request, HttpServletResponse response, OAuthConsumer consumer) throws IOException, ServletException { if (e instanceof RedirectException) { RedirectException redirect = (RedirectException) e; String targetURL = redirect.getTargetURL(); if (targetURL != null) { response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", targetURL); } } else if (e instanceof OAuthProblemException) { OAuthProblemException p = (OAuthProblemException) e; String problem = p.getProblem(); if (consumer != null && RECOVERABLE_PROBLEMS.contains(problem)) { try { CookieMap cookies = new CookieMap(request, response); OAuthAccessor accessor = newAccessor(consumer, cookies); getAccessToken(request, cookies, accessor); // getAccessToken(request, consumer, // new CookieMap(request, response)); } catch (Exception e2) { handleException(e2, request, response, null); } } else { try { StringWriter s = new StringWriter(); PrintWriter pw = new PrintWriter(s); e.printStackTrace(pw); pw.flush(); p.setParameter("stack trace", s.toString()); } catch (Exception rats) { } response.setStatus(p.getHttpStatusCode()); response.resetBuffer(); request.setAttribute("OAuthProblemException", p); request.getRequestDispatcher // ("/OAuthProblemException.jsp").forward(request, response); } } else if (e instanceof IOException) { throw (IOException) e; } else if (e instanceof ServletException) { throw (ServletException) e; } else if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new ServletException(e); } }