Example usage for javax.servlet.http HttpServletResponse SC_MOVED_TEMPORARILY

List of usage examples for javax.servlet.http HttpServletResponse SC_MOVED_TEMPORARILY

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_MOVED_TEMPORARILY.

Prototype

int SC_MOVED_TEMPORARILY

To view the source code for javax.servlet.http HttpServletResponse SC_MOVED_TEMPORARILY.

Click Source Link

Document

Status code (302) indicating that the resource has temporarily moved to another location, but that future references should still use the original URI to access the resource.

Usage

From source file:org.wso2.carbon.identity.sso.cas.response.HttpCASResponseFactory.java

private HttpIdentityResponse.HttpIdentityResponseBuilder sendResponse(IdentityResponse identityResponse) {
    CASLoginResponse loginResponse = ((CASLoginResponse) identityResponse);
    HttpIdentityResponse.HttpIdentityResponseBuilder builder = new HttpIdentityResponse.HttpIdentityResponseBuilder();
    Cookie cookie = loginResponse.getCasCookie();
    String serviceTicketId = loginResponse.getServiceTicketId();
    String redirectUrl = loginResponse.getRedirectUrl();
    Map<String, String[]> queryParams = new HashMap();
    queryParams.put(CASConstants.CASSSOConstants.SERVICE_TICKET_ARGUMENT, new String[] { serviceTicketId });
    builder.addCookie(cookie);/*from   w  ww.ja  v a2 s  .  c  o m*/
    builder.setParameters(queryParams);
    builder.setRedirectURL(redirectUrl);
    builder.setStatusCode(HttpServletResponse.SC_MOVED_TEMPORARILY);
    return builder;
}

From source file:org.wso2.carbon.identity.sso.cas.response.HttpSAMLResponseFactory.java

private HttpIdentityResponse.HttpIdentityResponseBuilder sendNotification(IdentityResponse identityResponse) {
    SAMLErrorResponse errorResponse = ((SAMLErrorResponse) identityResponse);
    HttpIdentityResponse.HttpIdentityResponseBuilder builder = new HttpIdentityResponse.HttpIdentityResponseBuilder();
    String redirectURL = CASSSOUtil.getNotificationEndpoint();
    Map<String, String[]> queryParams = new HashMap();

    //TODO Send status codes rather than full messages in the GET request
    try {/*from w w w .j a  v  a2s  .c o m*/
        queryParams.put(CASSSOConstants.STATUS,
                new String[] { URLEncoder.encode(errorResponse.getStatus(), StandardCharsets.UTF_8.name()) });
        queryParams.put(CASSSOConstants.STATUS_MSG, new String[] {
                URLEncoder.encode(errorResponse.getMessageLog(), StandardCharsets.UTF_8.name()) });

        if (StringUtils.isNotEmpty(errorResponse.getErrorResponse())) {
            queryParams.put(CASSSOConstants.SAML_RESP, new String[] {
                    URLEncoder.encode(errorResponse.getErrorResponse(), StandardCharsets.UTF_8.name()) });
        }

        if (StringUtils.isNotEmpty(errorResponse.getAcsUrl())) {
            queryParams.put(CASSSOConstants.SERVICE, new String[] {
                    URLEncoder.encode(errorResponse.getAcsUrl(), StandardCharsets.UTF_8.name()) });
        }
    } catch (UnsupportedEncodingException e) {

    }
    builder.setStatusCode(HttpServletResponse.SC_MOVED_TEMPORARILY);
    builder.setParameters(queryParams);
    builder.setRedirectURL(redirectURL);
    return builder;
}

From source file:org.wso2.carbon.identity.sso.cas.saml.response.HttpCASSAMLResponseFactory.java

private HttpIdentityResponse.HttpIdentityResponseBuilder sendResponse(IdentityResponse identityResponse) {
    CASLoginResponse loginResponse = ((CASLoginResponse) identityResponse);
    HttpIdentityResponse.HttpIdentityResponseBuilder builder = new HttpIdentityResponse.HttpIdentityResponseBuilder();
    Cookie cookie = loginResponse.getCasCookie();
    String serviceTicketId = loginResponse.getServiceTicketId();
    String redirectUrl = loginResponse.getRedirectUrl();
    Map<String, String[]> queryParams = new HashMap();
    queryParams.put(CASSSOConstants.SERVICE_TICKET_ARGUMENT, new String[] { serviceTicketId });
    builder.addCookie(cookie);//from  w w  w  .java  2s .co  m
    builder.setParameters(queryParams);
    builder.setRedirectURL(redirectUrl);
    builder.setStatusCode(HttpServletResponse.SC_MOVED_TEMPORARILY);
    return builder;
}

From source file:org.wso2.carbon.identity.sso.saml.cloud.request.SAMLIdentityRequestFactory.java

@Override
public HttpIdentityResponse.HttpIdentityResponseBuilder handleException(FrameworkClientException exception,
        HttpServletRequest request, HttpServletResponse response) {

    HttpIdentityResponse.HttpIdentityResponseBuilder builder = new HttpIdentityResponse.HttpIdentityResponseBuilder();
    String redirectURL = SAMLSSOUtil.getNotificationEndpoint();
    Map<String, String[]> queryParams = new HashMap();
    //TODO Send status codes rather than full messages in the GET request
    try {/*from  w  w w.ja  v a2 s  .co m*/
        queryParams.put(SAMLSSOConstants.STATUS,
                new String[] { URLEncoder.encode(((SAML2ClientException) exception).getExceptionStatus(),
                        StandardCharsets.UTF_8.name()) });
        queryParams.put(SAMLSSOConstants.STATUS_MSG,
                new String[] { URLEncoder.encode(((SAML2ClientException) exception).getExceptionMessage(),
                        StandardCharsets.UTF_8.name()) });
        if (exception.getMessage() != null) {
            queryParams.put(SAMLSSOConstants.SAML_RESP,
                    new String[] { URLEncoder.encode(exception.getMessage(), StandardCharsets.UTF_8.name()) });
        }
        if (((SAML2ClientException) exception).getACSUrl() != null) {
            queryParams.put(SAMLSSOConstants.ASSRTN_CONSUMER_URL, new String[] { URLEncoder
                    .encode(((SAML2ClientException) exception).getACSUrl(), StandardCharsets.UTF_8.name()) });
        }
        builder.setParameters(queryParams);
    } catch (UnsupportedEncodingException e) {
        if (log.isDebugEnabled()) {
            log.debug("Error while encoding query parameters.", e);
        }
    }
    builder.setRedirectURL(redirectURL);
    builder.setStatusCode(HttpServletResponse.SC_MOVED_TEMPORARILY);
    return builder;
}

From source file:org.wso2.carbon.identity.sso.saml.cloud.response.HttpSAMLResponseFactory.java

private HttpIdentityResponse.HttpIdentityResponseBuilder sendNotification(IdentityResponse identityResponse) {
    SAMLErrorResponse errorResponse = ((SAMLErrorResponse) identityResponse);
    HttpIdentityResponse.HttpIdentityResponseBuilder builder = new HttpIdentityResponse.HttpIdentityResponseBuilder();
    String redirectURL = SAMLSSOUtil.getNotificationEndpoint();
    Map<String, String[]> queryParams = new HashMap();

    //TODO Send status codes rather than full messages in the GET request
    try {//from  w  w w . j av  a 2  s.co  m
        queryParams.put(SAMLSSOConstants.STATUS,
                new String[] { URLEncoder.encode(errorResponse.getStatus(), StandardCharsets.UTF_8.name()) });
        queryParams.put(SAMLSSOConstants.STATUS_MSG, new String[] {
                URLEncoder.encode(errorResponse.getMessageLog(), StandardCharsets.UTF_8.name()) });

        if (StringUtils.isNotEmpty(errorResponse.getErrorResponse())) {
            queryParams.put(SAMLSSOConstants.SAML_RESP, new String[] {
                    URLEncoder.encode(errorResponse.getErrorResponse(), StandardCharsets.UTF_8.name()) });
        }

        if (StringUtils.isNotEmpty(errorResponse.getAcsUrl())) {
            queryParams.put(SAMLSSOConstants.ASSRTN_CONSUMER_URL, new String[] {
                    URLEncoder.encode(errorResponse.getAcsUrl(), StandardCharsets.UTF_8.name()) });
        }
    } catch (UnsupportedEncodingException e) {

    }
    builder.setStatusCode(HttpServletResponse.SC_MOVED_TEMPORARILY);
    builder.setParameters(queryParams);
    builder.setRedirectURL(redirectURL);
    return builder;
}

From source file:org.xchain.namespaces.servlet.RedirectCommand.java

public boolean execute(JXPathContext context) throws Exception {
    HttpServletResponse response = getResponse(context);
    response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
    response.setHeader("Location", getPath(context));

    return false;
}

From source file:org.zdevra.guice.mvc.security.controller.SecureRoleControllerTest.java

@Test
public void shouldDenyRoleNotAuthenticatedAndAllowCorrectUser() throws IOException, ServletException {

    HttpMethod method = doRequest("http://localhost:9191/auth/invalidate");
    method = doRequest("http://localhost:9191/secure/something");

    int code = method.getStatusCode();

    System.out.println("code:" + code);
    assertThat(code, is(HttpServletResponse.SC_MOVED_TEMPORARILY));

    method = doRequest("http://localhost:9191/auth/authenticate");

    method = doRequest("http://localhost:9191/secure/something");
    code = method.getStatusCode();/*from  w  w w . j  a  va2s . c om*/
    assertThat(code, is(HttpServletResponse.SC_OK));
    assertThat(method.getPath(), is("/secure/something"));
    System.out.println("code:" + code);

}

From source file:test.integ.be.fedict.eid.idp.OpenIDTest.java

@Test
public void testOpenID() throws Exception {
    LOG.debug("OpenID integration test");

    // make sure that the session cookies are passed during conversations
    // required to be able to run the Controller here
    MyCookieManager cookieManager = new MyCookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);

    // setup//from   w ww . j  a v a 2 s  .c  o  m
    this.servletTester = new ServletTester();
    ServletHolder reqServletHolder = this.servletTester.addServlet(AuthenticationRequestServlet.class,
            "/openid-request");
    reqServletHolder.setInitParameter("ParametersFromRequest", "true");
    reqServletHolder.setInitParameter("SPDestination", "http://localhost/openid-response");
    reqServletHolder.setInitParameter("UserIdentifier", "https://localhost/eid-idp/endpoints/openid-identity");
    reqServletHolder.setInitParameter("TrustServer", "true");

    ServletHolder responseServletHolder = this.servletTester.addServlet(AuthenticationResponseServlet.class,
            "/openid-response");
    responseServletHolder.setInitParameter("RedirectPage", "/target");
    responseServletHolder.setInitParameter("IdentifierSessionAttribute", "identifier");

    this.servletTester.start();
    String location = this.servletTester.createSocketConnector(true);
    LOG.debug("location: " + location);

    HttpState httpState = new HttpState();
    HttpClient httpClient = new HttpClient();
    httpClient.setState(httpState);
    httpClient.getParams()
            .setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.BROWSER_COMPATIBILITY);
    httpClient.getParams().setParameter("http.protocol.allow-circular-redirects", Boolean.TRUE);

    GetMethod getMethod = new GetMethod(location + "/openid-request?SPDestination=" + location
            + "/openid-response&UserIdentifier=https://localhost/eid-idp/endpoints/openid-identity");
    getMethod.setFollowRedirects(false);

    ProtocolSocketFactory protocolSocketFactory = new MyProtocolSocketFactory();
    Protocol myProtocol = new Protocol("https", protocolSocketFactory, 443);
    Protocol.registerProtocol("https", myProtocol);

    // operate
    int statusCode = httpClient.executeMethod(getMethod);

    // verify
    LOG.debug("status code: " + statusCode);
    assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, statusCode);
    LOG.debug("response body: " + getMethod.getResponseBodyAsString());
    Header jettySetCookieHeader = getMethod.getResponseHeader("Set-Cookie");
    String jettySessionCookieValue = jettySetCookieHeader.getValue();
    LOG.debug("jetty session cookie value: " + jettySessionCookieValue);

    String idpLocation = getMethod.getResponseHeader("Location").getValue();
    LOG.debug("IdP location: " + idpLocation);
    getMethod = new GetMethod(idpLocation);
    getMethod.setFollowRedirects(false);
    statusCode = httpClient.executeMethod(getMethod);
    assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, statusCode);
    LOG.debug("response body: " + getMethod.getResponseBodyAsString());

    String idpSessionCookieValue = getMethod.getResponseHeader("Set-Cookie").getValue();
    LOG.debug("IdP session cookie value: " + idpSessionCookieValue);
    String idpSeamLocation = getMethod.getResponseHeader("Location").getValue();
    getMethod = new GetMethod(idpSeamLocation);
    getMethod.setFollowRedirects(false);
    getMethod.addRequestHeader("Cookie", idpSessionCookieValue);
    statusCode = httpClient.executeMethod(getMethod);
    assertEquals(HttpServletResponse.SC_OK, statusCode);
    cookieManager.setSessionCookieValue(idpSessionCookieValue);

    Messages messages = new Messages(Locale.getDefault());
    Runtime runtime = new TestRuntime();
    View view = new TestView();
    Controller controller = new Controller(view, runtime, messages);

    /*
     * Context jettyContext = this.servletTester.getContext();
     * SessionHandler jettySessionHandler =
     * jettyContext.getSessionHandler(); SessionManager jettySessionManager
     * = jettySessionHandler .getSessionManager(); HashSessionManager
     * hashSessionManager = (HashSessionManager) jettySessionManager;
     * LOG.debug("# sessions: " + hashSessionManager.getSessions());
     * assertEquals(1, hashSessionManager.getSessions()); Map<String,
     * HttpSession> sessionMap = hashSessionManager .getSessionMap();
     * LOG.debug("session map: " + sessionMap); HttpSession jettyHttpSession
     * = sessionMap.values().iterator().next(); String jettySessionId =
     * jettyHttpSession.getId(); LOG.debug("jetty HTTP session id: " +
     * jettySessionId);
     */

    // operate
    controller.run();

    // httpState.addCookie(new Cookie("localhost", "JSESSIONID",
    // sessionCookie, "/eid-idp", -1, false));
    // httpClient.setState(httpState);
    LOG.debug("continue to eID IdP exit page...");
    getMethod = new GetMethod("https://localhost/eid-idp/protocol-exit");
    getMethod.addRequestHeader("Cookie", idpSessionCookieValue);
    getMethod.setFollowRedirects(false);
    statusCode = httpClient.executeMethod(getMethod);
    LOG.debug("status code: " + statusCode);
    assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, statusCode);
    String jettyResponseLocation = getMethod.getResponseHeader("Location").getValue();

    getMethod = new GetMethod(jettyResponseLocation);
    getMethod.setFollowRedirects(false);
    statusCode = httpClient.executeMethod(getMethod);
    LOG.debug("status code: " + statusCode);
    assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, statusCode);

    LOG.debug("response body: " + getMethod.getResponseBodyAsString());
}