Java Code Examples for org.eclipse.jetty.util.MultiMap#add()

The following examples show how to use org.eclipse.jetty.util.MultiMap#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppEngineAuthenticationTest.java    From appengine-java-vm-runtime with Apache License 2.0 6 votes vote down vote up
public void testUserRequired_PreserveQueryParams() throws Exception {
  String path = "/user/blah";
  
  Request request = new Request(null, null);
  // request.setServerPort(9999);
      HttpURI uri  =new HttpURI("http", SERVER_NAME,9999, path,"foo=baqr","foo=bar","foo=barff");
  HttpFields httpf = new HttpFields();
  MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
  request.setMetaData(metadata);
  MultiMap<String> queryParameters = new MultiMap<> ();
  queryParameters.add("ffo", "bar");
  request.setQueryParameters(queryParameters);
      request = spy(request);

 /// request.setAuthority(SERVER_NAME,9999);
  request.setQueryString("foo=bar");
  Response response = mock(Response.class);
  String output = runRequest2(path, request, response);
  // Verify that the servlet never was run (there is no output).
  assertEquals("", output);
  // Verify that the request was redirected to the login url.
  String loginUrl = UserServiceFactory.getUserService()
      .createLoginURL(String.format("http://%s%s?foo=bar", SERVER_NAME + ":9999", path));
  verify(response).sendRedirect(loginUrl);
}
 
Example 2
Source File: HttpRequestBasedCallbackHandlerTest.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public void testBindsUsernameAndPassword() throws IOException, UnsupportedCallbackException {
  MultiMap<String> args = new MultiMap<String>();
  args.add("address", "[email protected]");
  args.add("password", "internet");

  CallbackHandler handler = new HttpRequestBasedCallbackHandler(args);
  Callback[] callbacks =
      new Callback[] {new NameCallback("ignored"), new PasswordCallback("ignored", false),};

  handler.handle(callbacks);

  assertEquals("[email protected]", ((NameCallback) callbacks[0]).getName());
  assertEquals("internet", new String(((PasswordCallback) callbacks[1]).getPassword()));
}
 
Example 3
Source File: HttpRequestBasedCallbackHandlerTest.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
public void testBindsUsernameAndPassword() throws IOException, UnsupportedCallbackException {
  MultiMap<String> args = new MultiMap<String>();
  args.add("address", "[email protected]");
  args.add("password", "internet");

  CallbackHandler handler = new HttpRequestBasedCallbackHandler(args);
  Callback[] callbacks =
      new Callback[] {new NameCallback("ignored"), new PasswordCallback("ignored", false),};

  handler.handle(callbacks);

  assertEquals("[email protected]", ((NameCallback) callbacks[0]).getName());
  assertEquals("internet", new String(((PasswordCallback) callbacks[1]).getPassword()));
}
 
Example 4
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public boolean restoreRequest() {
    HttpSession session = myRequest.getSession(false);
    if (session == null) return false;
    synchronized (session) {
        String j_uri = (String) session.getAttribute(FormAuthenticator.__J_URI);
        if (j_uri != null) {
            // check if the request is for the same url as the original and restore
            // params if it was a post
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            if (j_uri.equals(buf.toString())) {
                String method = (String)session.getAttribute(JettyHttpFacade.__J_METHOD);
                myRequest.setMethod(method);
                MultivaluedHashMap<String, String> j_post = (MultivaluedHashMap<String, String>) session.getAttribute(CACHED_FORM_PARAMETERS);
                if (j_post != null) {
                    myRequest.setContentType("application/x-www-form-urlencoded");
                    MultiMap<String> map = new MultiMap<String>();
                    for (String key : j_post.keySet()) {
                        for (String val : j_post.getList(key)) {
                            map.add(key, val);
                        }
                    }
                    restoreFormParameters(map, myRequest);
                }
                session.removeAttribute(FormAuthenticator.__J_URI);
                session.removeAttribute(JettyHttpFacade.__J_METHOD);
                session.removeAttribute(FormAuthenticator.__J_POST);
            }
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public boolean restoreRequest() {
    HttpSession session = myRequest.getSession(false);
    if (session == null) return false;
    synchronized (session) {
        String j_uri = (String) session.getAttribute(FormAuthenticator.__J_URI);
        if (j_uri != null) {
            // check if the request is for the same url as the original and restore
            // params if it was a post
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            if (j_uri.equals(buf.toString())) {
                String method = (String)session.getAttribute(JettyHttpFacade.__J_METHOD);
                myRequest.setMethod(method);
                MultivaluedHashMap<String, String> j_post = (MultivaluedHashMap<String, String>) session.getAttribute(CACHED_FORM_PARAMETERS);
                if (j_post != null) {
                    myRequest.setContentType("application/x-www-form-urlencoded");
                    MultiMap<String> map = new MultiMap<String>();
                    for (String key : j_post.keySet()) {
                        for (String val : j_post.getList(key)) {
                            map.add(key, val);
                        }
                    }
                    restoreFormParameters(map, myRequest);
                }
                session.removeAttribute(FormAuthenticator.__J_URI);
                session.removeAttribute(JettyHttpFacade.__J_METHOD);
                session.removeAttribute(FormAuthenticator.__J_POST);
            }
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public boolean restoreRequest() {
    HttpSession session = myRequest.getSession(false);
    if (session == null) return false;
    synchronized (session) {
        String j_uri = (String) session.getAttribute(FormAuthenticator.__J_URI);
        if (j_uri != null) {
            // check if the request is for the same url as the original and restore
            // params if it was a post
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            if (j_uri.equals(buf.toString())) {
                String method = (String)session.getAttribute(JettyHttpFacade.__J_METHOD);
                myRequest.setMethod(HttpMethod.valueOf(method.toUpperCase()), method);
                MultivaluedHashMap<String, String> j_post = (MultivaluedHashMap<String, String>) session.getAttribute(CACHED_FORM_PARAMETERS);
                if (j_post != null) {
                    myRequest.setContentType("application/x-www-form-urlencoded");
                    MultiMap<String> map = new MultiMap<String>();
                    for (String key : j_post.keySet()) {
                        for (String val : j_post.getList(key)) {
                            map.add(key, val);
                        }
                    }
                    restoreFormParameters(map, myRequest);
                }
                session.removeAttribute(FormAuthenticator.__J_URI);
                session.removeAttribute(JettyHttpFacade.__J_METHOD);
                session.removeAttribute(FormAuthenticator.__J_POST);
            }
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public boolean restoreRequest() {
    HttpSession session = myRequest.getSession(false);
    if (session == null) return false;
    synchronized (session) {
        String j_uri = (String) session.getAttribute(FormAuthenticator.__J_URI);
        if (j_uri != null) {
            // check if the request is for the same url as the original and restore
            // params if it was a post
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            if (j_uri.equals(buf.toString())) {
                String method = (String)session.getAttribute(JettyHttpFacade.__J_METHOD);
                myRequest.setMethod(method);
                MultivaluedHashMap<String, String> j_post = (MultivaluedHashMap<String, String>) session.getAttribute(CACHED_FORM_PARAMETERS);
                if (j_post != null) {
                    myRequest.setContentType("application/x-www-form-urlencoded");
                    MultiMap<String> map = new MultiMap<String>();
                    for (String key : j_post.keySet()) {
                        for (String val : j_post.getList(key)) {
                            map.add(key, val);
                        }
                    }
                    restoreFormParameters(map, myRequest);
                }
                session.removeAttribute(FormAuthenticator.__J_URI);
                session.removeAttribute(JettyHttpFacade.__J_METHOD);
                session.removeAttribute(FormAuthenticator.__J_POST);
            }
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public boolean restoreRequest() {
    HttpSession session = myRequest.getSession(false);
    if (session == null) return false;
    synchronized (session) {
        String j_uri = (String) session.getAttribute(FormAuthenticator.__J_URI);
        if (j_uri != null) {
            // check if the request is for the same url as the original and restore
            // params if it was a post
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            if (j_uri.equals(buf.toString())) {
                String method = (String)session.getAttribute(JettyHttpFacade.__J_METHOD);
                myRequest.setMethod(method);
                MultivaluedHashMap<String, String> j_post = (MultivaluedHashMap<String, String>) session.getAttribute(CACHED_FORM_PARAMETERS);
                if (j_post != null) {
                    myRequest.setContentType("application/x-www-form-urlencoded");
                    MultiMap<String> map = new MultiMap<String>();
                    for (String key : j_post.keySet()) {
                        for (String val : j_post.getList(key)) {
                            map.add(key, val);
                        }
                    }
                    restoreFormParameters(map, myRequest);
                }
                session.removeAttribute(FormAuthenticator.__J_URI);
                session.removeAttribute(JettyHttpFacade.__J_METHOD);
                session.removeAttribute(FormAuthenticator.__J_POST);
            }
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public boolean restoreRequest() {
    HttpSession session = myRequest.getSession(false);
    if (session == null) return false;
    synchronized (session) {
        String j_uri = (String) session.getAttribute(FormAuthenticator.__J_URI);
        if (j_uri != null) {
            // check if the request is for the same url as the original and restore
            // params if it was a post
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            if (j_uri.equals(buf.toString())) {
                String method = (String)session.getAttribute(JettyHttpFacade.__J_METHOD);
                myRequest.setMethod(HttpMethod.valueOf(method.toUpperCase()), method);
                MultivaluedHashMap<String, String> j_post = (MultivaluedHashMap<String, String>) session.getAttribute(CACHED_FORM_PARAMETERS);
                if (j_post != null) {
                    myRequest.setContentType("application/x-www-form-urlencoded");
                    MultiMap<String> map = new MultiMap<String>();
                    for (String key : j_post.keySet()) {
                        for (String val : j_post.getList(key)) {
                            map.add(key, val);
                        }
                    }
                    restoreFormParameters(map, myRequest);
                }
                session.removeAttribute(FormAuthenticator.__J_URI);
                session.removeAttribute(JettyHttpFacade.__J_METHOD);
                session.removeAttribute(FormAuthenticator.__J_POST);
            }
            return true;
        }
    }
    return false;
}