org.eclipse.jetty.util.MultiMap Java Examples

The following examples show how to use org.eclipse.jetty.util.MultiMap. 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: PHttpServerRequest.java    From jphp with Apache License 2.0 6 votes vote down vote up
@Signature
public Memory queryParameters() {
    request.getParameterMap();

    MultiMap<String> parameters = request.getQueryParameters();

    if (parameters != null) {
        ArrayMemory result = ArrayMemory.createHashed(parameters.size());

        for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
            List<String> value = entry.getValue();

            if (value == null || value.isEmpty()) {
                result.putAsKeyString(entry.getKey(), Memory.NULL);
            } else if (value.size() == 1) {
                result.putAsKeyString(entry.getKey(), StringMemory.valueOf(value.get(0)));
            } else {
                result.putAsKeyString(entry.getKey(), ArrayMemory.ofStringCollection(value));
            }
        }

        return result;
    } else {
        return new ArrayMemory().toConstant();
    }
}
 
Example #2
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void saveRequest() {
    // remember the current URI
    HttpSession session = myRequest.getSession();
    synchronized (session) {
        // But only if it is not set already, or we save every uri that leads to a login form redirect
        if (session.getAttribute(FormAuthenticator.__J_URI) == null) {
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            session.setAttribute(FormAuthenticator.__J_URI, buf.toString());
            session.setAttribute(JettyHttpFacade.__J_METHOD, myRequest.getMethod());

            if ("application/x-www-form-urlencoded".equals(myRequest.getContentType()) && "POST".equalsIgnoreCase(myRequest.getMethod())) {
                MultiMap<String> formParameters = extractFormParameters(myRequest);
                MultivaluedHashMap<String, String> map = new MultivaluedHashMap<String, String>();
                for (String key : formParameters.keySet()) {
                    for (Object value : formParameters.getValues(key)) {
                        map.add(key, (String) value);
                    }
                }
                session.setAttribute(CACHED_FORM_PARAMETERS, map);
            }
        }
    }
}
 
Example #3
Source File: OAuth2InteractiveAuthenticatorTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private Map<String, String> getRedirectParameters(final String redirectLocation)
{

    final MultiMap<String> parameterMap = new MultiMap<>();
    HttpURI httpURI = new HttpURI(redirectLocation);
    httpURI.decodeQueryTo(parameterMap);
    Map<String,String> parameters = new HashMap<>(parameterMap.size());
    for (Map.Entry<String, List<String>> paramEntry : parameterMap.entrySet())
    {
        assertEquals(String.format("param '%s' specified more than once", paramEntry.getKey()),
                            (long) 1,
                            (long) paramEntry.getValue().size());

        parameters.put(paramEntry.getKey(), paramEntry.getValue().get(0));
    }
    return parameters;
}
 
Example #4
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void saveRequest() {
    // remember the current URI
    HttpSession session = myRequest.getSession();
    synchronized (session) {
        // But only if it is not set already, or we save every uri that leads to a login form redirect
        if (session.getAttribute(FormAuthenticator.__J_URI) == null) {
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            session.setAttribute(FormAuthenticator.__J_URI, buf.toString());
            session.setAttribute(JettyHttpFacade.__J_METHOD, myRequest.getMethod());

            if ("application/x-www-form-urlencoded".equals(myRequest.getContentType()) && "POST".equalsIgnoreCase(myRequest.getMethod())) {
                MultiMap<String> formParameters = extractFormParameters(myRequest);
                MultivaluedHashMap<String, String> map = new MultivaluedHashMap<String, String>();
                for (String key : formParameters.keySet()) {
                    for (Object value : formParameters.getValues(key)) {
                        map.add(key, (String) value);
                    }
                }
                session.setAttribute(CACHED_FORM_PARAMETERS, map);
            }
        }
    }
}
 
Example #5
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void saveRequest() {
    // remember the current URI
    HttpSession session = myRequest.getSession();
    synchronized (session) {
        // But only if it is not set already, or we save every uri that leads to a login form redirect
        if (session.getAttribute(FormAuthenticator.__J_URI) == null) {
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            session.setAttribute(FormAuthenticator.__J_URI, buf.toString());
            session.setAttribute(JettyHttpFacade.__J_METHOD, myRequest.getMethod());

            if ("application/x-www-form-urlencoded".equals(myRequest.getContentType()) && "POST".equalsIgnoreCase(myRequest.getMethod())) {
                MultiMap<String> formParameters = extractFormParameters(myRequest);
                MultivaluedHashMap<String, String> map = new MultivaluedHashMap<String, String>();
                for (String key : formParameters.keySet()) {
                    for (Object value : formParameters.getValues(key)) {
                        map.add(key, (String) value);
                    }
                }
                session.setAttribute(CACHED_FORM_PARAMETERS, map);
            }
        }
    }
}
 
Example #6
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void saveRequest() {
    // remember the current URI
    HttpSession session = myRequest.getSession();
    synchronized (session) {
        // But only if it is not set already, or we save every uri that leads to a login form redirect
        if (session.getAttribute(FormAuthenticator.__J_URI) == null) {
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            session.setAttribute(FormAuthenticator.__J_URI, buf.toString());
            session.setAttribute(JettyHttpFacade.__J_METHOD, myRequest.getMethod());

            if ("application/x-www-form-urlencoded".equals(myRequest.getContentType()) && "POST".equalsIgnoreCase(myRequest.getMethod())) {
                MultiMap<String> formParameters = extractFormParameters(myRequest);
                MultivaluedHashMap<String, String> map = new MultivaluedHashMap<String, String>();
                for (String key : formParameters.keySet()) {
                    for (Object value : formParameters.getValues(key)) {
                        map.add(key, (String) value);
                    }
                }
                session.setAttribute(CACHED_FORM_PARAMETERS, map);
            }
        }
    }
}
 
Example #7
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void saveRequest() {
    // remember the current URI
    HttpSession session = myRequest.getSession();
    synchronized (session) {
        // But only if it is not set already, or we save every uri that leads to a login form redirect
        if (session.getAttribute(FormAuthenticator.__J_URI) == null) {
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            session.setAttribute(FormAuthenticator.__J_URI, buf.toString());
            session.setAttribute(JettyHttpFacade.__J_METHOD, myRequest.getMethod());

            if ("application/x-www-form-urlencoded".equals(myRequest.getContentType()) && "POST".equalsIgnoreCase(myRequest.getMethod())) {
                MultiMap<String> formParameters = extractFormParameters(myRequest);
                MultivaluedHashMap<String, String> map = new MultivaluedHashMap<String, String>();
                for (String key : formParameters.keySet()) {
                    for (Object value : formParameters.getValues(key)) {
                        map.add(key, (String) value);
                    }
                }
                session.setAttribute(CACHED_FORM_PARAMETERS, map);
            }
        }
    }
}
 
Example #8
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 #9
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void saveRequest() {
    // remember the current URI
    HttpSession session = myRequest.getSession();
    synchronized (session) {
        // But only if it is not set already, or we save every uri that leads to a login form redirect
        if (session.getAttribute(FormAuthenticator.__J_URI) == null) {
            StringBuffer buf = myRequest.getRequestURL();
            if (myRequest.getQueryString() != null)
                buf.append("?").append(myRequest.getQueryString());
            session.setAttribute(FormAuthenticator.__J_URI, buf.toString());
            session.setAttribute(JettyHttpFacade.__J_METHOD, myRequest.getMethod());

            if ("application/x-www-form-urlencoded".equals(myRequest.getContentType()) && "POST".equalsIgnoreCase(myRequest.getMethod())) {
                MultiMap<String> formParameters = extractFormParameters(myRequest);
                MultivaluedHashMap<String, String> map = new MultivaluedHashMap<String, String>();
                for (String key : formParameters.keySet()) {
                    for (Object value : formParameters.getValues(key)) {
                        map.add(key, (String) value);
                    }
                }
                session.setAttribute(CACHED_FORM_PARAMETERS, map);
            }
        }
    }
}
 
Example #10
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 #11
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 #12
Source File: HttpRequestBasedCallbackHandlerTest.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
public void testCallbackThrowsHandlingUnsupportedCallback() throws IOException {
  CallbackHandler handler = new HttpRequestBasedCallbackHandler(new MultiMap<String>());

  try {
    handler.handle(new Callback[] {new Callback() {}});
    fail("Should have thrown due to unsupported callback");
  } catch (UnsupportedCallbackException e) {
    // Pass.
  }
}
 
Example #13
Source File: PhpPrettyCalculate.java    From TestingApp with Apache License 2.0 5 votes vote down vote up
public String post(){

        MultiMap<String> params = new MultiMap<String>();
        UrlEncoded.decodeTo(req.body(), params, "UTF-8");

        return getPage( params.get("number1").get(0),
                        params.get("function").get(0),
                        params.get("number2").get(0));
    }
 
Example #14
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 #15
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 #16
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 #17
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 #18
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 #19
Source File: PHttpServerRequest.java    From jphp with Apache License 2.0 5 votes vote down vote up
@Signature
public String query(String name) {
    request.getParameterMap();
    MultiMap<String> queryParameters = request.getQueryParameters();

    if (queryParameters != null) {
        return queryParameters.getString(name);
    } else {
        return null;
    }
}
 
Example #20
Source File: PhpCalculate.java    From TestingApp with Apache License 2.0 5 votes vote down vote up
public String post(){

        MultiMap<String> params = new MultiMap<String>();
        UrlEncoded.decodeTo(req.body(), params, "UTF-8");

        return getPage( params.get("number1").get(0),
                        params.get("function").get(0),
                        params.get("number2").get(0));
    }
 
Example #21
Source File: AuthenticationServlet.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private LoginContext login(BufferedReader body) throws IOException, LoginException {
  try {
    Subject subject = new Subject();

    String parametersLine = body.readLine();
    // Throws UnsupportedEncodingException.
    byte[] utf8Bytes = parametersLine.getBytes("UTF-8");

    CharsetDecoder utf8Decoder = Charset.forName("UTF-8").newDecoder();
    utf8Decoder.onMalformedInput(CodingErrorAction.IGNORE);
    utf8Decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);

    // Throws CharacterCodingException.
    CharBuffer parsed = utf8Decoder.decode(ByteBuffer.wrap(utf8Bytes));
    parametersLine = parsed.toString();

    MultiMap<String> parameters = new UrlEncoded(parametersLine);
    CallbackHandler callbackHandler = new HttpRequestBasedCallbackHandler(parameters);

    LoginContext context = new LoginContext("Wave", subject, callbackHandler, configuration);

    // If authentication fails, login() will throw a LoginException.
    context.login();
    return context;
  } catch (CharacterCodingException cce) {
    throw new LoginException("Character coding exception (not utf-8): "
        + cce.getLocalizedMessage());
  } catch (UnsupportedEncodingException uee) {
    throw new LoginException("ad character encoding specification: " + uee.getLocalizedMessage());
  }
}
 
Example #22
Source File: HttpRequestBasedCallbackHandlerTest.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public void testCallbackThrowsHandlingUnsupportedCallback() throws IOException {
  CallbackHandler handler = new HttpRequestBasedCallbackHandler(new MultiMap<String>());

  try {
    handler.handle(new Callback[] {new Callback() {}});
    fail("Should have thrown due to unsupported callback");
  } catch (UnsupportedCallbackException e) {
    // Pass.
  }
}
 
Example #23
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 #24
Source File: HttpRequest.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static Map<String, List<String>> getUriQueryParameters(URI uri) {
    MultiMap<String> queryParameters = new MultiMap<>();
    new HttpURI(uri).decodeQueryTo(queryParameters);

    // Do a deep copy so we do not leak Jetty classes outside
    Map<String, List<String>> deepCopiedQueryParameters = new HashMap<>();
    for (Map.Entry<String, List<String>> entry : queryParameters.entrySet()) {
        deepCopiedQueryParameters.put(entry.getKey(), new ArrayList<>(entry.getValue()));
    }
    return deepCopiedQueryParameters;
}
 
Example #25
Source File: PasswordRobot.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies user credentials.
 * 
 * @param oldPassword the password to verify.
 * @param participantId the participantId of the user.
 * @throws LoginException if the user provided incorrect password.
 */
private void verifyCredentials(String password, ParticipantId participantId)
    throws LoginException {
  MultiMap<String> parameters = new MultiMap<String>();
  parameters.putAllValues(ImmutableMap.of("password", password, "address", participantId.getAddress()));
  CallbackHandler callbackHandler = new HttpRequestBasedCallbackHandler(parameters);
  LoginContext context = new LoginContext("Wave", new Subject(), callbackHandler, configuration);
  // If authentication fails, login() will throw a LoginException.
  context.login();
}
 
Example #26
Source File: PasswordRobot.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies user credentials.
 * 
 * @param oldPassword the password to verify.
 * @param participantId the participantId of the user.
 * @throws LoginException if the user provided incorrect password.
 */
private void verifyCredentials(String password, ParticipantId participantId)
    throws LoginException {
  MultiMap<String> parameters = new MultiMap<String>();
  parameters.putAllValues(ImmutableMap.of("password", password, "address", participantId.getAddress()));
  CallbackHandler callbackHandler = new HttpRequestBasedCallbackHandler(parameters);
  LoginContext context = new LoginContext("Wave", new Subject(), callbackHandler, configuration);
  // If authentication fails, login() will throw a LoginException.
  context.login();
}
 
Example #27
Source File: JettyAdapterSessionStore.java    From keycloak with Apache License 2.0 4 votes vote down vote up
protected MultiMap<String> extractFormParameters(Request base_request) {
    MultiMap<String> formParameters = new MultiMap<String>();
    base_request.extractFormParameters(formParameters);
    return formParameters;
}
 
Example #28
Source File: PhpFormProcessor.java    From TestingApp with Apache License 2.0 4 votes vote down vote up
public String post() {

        html = new StringBuilder();

        html.append("<html><head><title>Processed Form Details</title></head>");
        html.append("<body>");

        // for backwards compatibility with PHP we should process the form fields in the order they are submitted
        String[] paramKeys = req.body().split("&");
        Set<String> theParamKeys = new LinkedHashSet<>();
        int index=0;
        for(String paramKey : paramKeys){
            int trimFrom = paramKey.indexOf("=");
            paramKeys[index] = paramKey.substring(0,trimFrom).replace("%5B%5D","[]");
            if(!theParamKeys.contains(paramKeys[index])){
                theParamKeys.add(paramKeys[index]);
            }
            index++;
        }

        //now decode the form into its name value,value pairs
        MultiMap<String> params = new MultiMap<String>();
        UrlEncoded.decodeTo(req.body(), params, "UTF-8");

        if(params.get("submitbutton")==null) {
            addLine("<p id='_valuesubmitbutton'>You did not click the submit button</p>");
        }

        addLine("<p>Submitted Values</p>");

        for(String param : theParamKeys){
            if(params.get(param) == null) {
                addLine(String.format("<p><strong>No Value for %s</strong></p>", param));
            }else{

                List<String> value = params.get(param);

                if(value.size()==0 || value.get(0).length()==0){
                    addLine(String.format("<p><strong>No Value for %s</strong></p>", param));
                }else{

                    boolean paramIsArray = param.contains("[]");
                    String paramDisplayName = param.replace("[]","");

                    addLine(String.format("<div id='_%s'>",paramDisplayName));
                    addLine(String.format("<p name='_%s'><strong>%s</strong></p>", paramDisplayName, paramDisplayName));

                    addLine("<ul>");

                    if(paramIsArray) {
                        int count=0;
                        for (String aValue : value) {
                            addLine(String.format("<li id='_value%s%d'>%s</li>", paramDisplayName, count, aValue));
                            count++;
                        }
                    }else{
                        addLine(String.format("<li id='_value%s'>%s</li>",paramDisplayName, value.get(0)));
                    }
                    addLine("</ul>");

                    addLine("</div>");
                }
            }

        }

        if(params.get("checkboxes[]")==null) {
            addLine("<p><strong>No Value for checkboxes</strong></p>");
        }

        if(params.get("multipleselect[]")==null) {
            addLine("<p><strong>No Value for multipleselect</strong></p>");
        }

        if(params.get("filename")==null) {
            addLine("<p><strong>No Value for filename</strong></p>");
        }


        if(req.queryParams("ajax")!=null){
            addLine("<a href='basic_ajax.html' id='back_to_form'>Go back to the Ajax form</a>");
        }else{
            addLine("<a href='basic_html_form.html' id='back_to_form'>Go back to the main form</a>");
        }

        html.append("</body>");
        html.append("</html>");
        return html.toString();
    }
 
Example #29
Source File: PhpSearch.java    From TestingApp with Apache License 2.0 4 votes vote down vote up
public String post() {


        List<SearchUrl> urls = SearchUrls.get();


        this.html = new StringBuilder();

        MultiMap<String> params = new MultiMap<String>();
        UrlEncoded.decodeTo(req.body(), params, "UTF-8");

        List<SearchUrl> returnUrls = new ArrayList<>();

        String query = "";

        int urlsToReturn = 20;

        if (params.get("q") != null) {
            query = params.get("q").get(0);
        }

        // add the seleniumrc one to make sure that the exercises work
        SearchUrl seleniumrc = new SearchUrl("http://seleniumhq.org",
                "seleniumhq.org",
                "Selenium Remote-Control",
                "Selenium RC comes in two parts. A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them. ...");

        if (query.equalsIgnoreCase("selenium-rc")) {
            returnUrls.add(seleniumrc);
            urlsToReturn--;
        }

        // try and find some matching in the list

        for (SearchUrl sUrl : urls) {
            boolean addThis = false;

            if (sUrl.description.contains(query)) {
                addThis = true;
            }

            if (sUrl.title.contains(query)) {
                addThis = true;
            }

            if (sUrl.displayUrl.contains(query)) {
                addThis = true;
            }

            if (addThis) {
                returnUrls.add(sUrl);
                urlsToReturn--;
            }

            if (urlsToReturn == 0) {
                break;
            }
        }


        if (urlsToReturn > 0) {
            // randomly choose some urls
            while (urlsToReturn > 0) {
                int totalUrls = urls.size();
                Random r = new Random();
                int Low = 0;
                int rand = r.nextInt(totalUrls - Low) + Low;
                returnUrls.add(urls.get(rand));
                urlsToReturn--;
            }
        }


        pageHtml(query, returnUrls);

        return html.toString();
    }
 
Example #30
Source File: PhpPrettySearch.java    From TestingApp with Apache License 2.0 4 votes vote down vote up
public String post() {


        List<SearchUrl> urls = SearchUrls.get();


        this.html = new StringBuilder();

        MultiMap<String> params = new MultiMap<String>();
        UrlEncoded.decodeTo(req.body(), params, "UTF-8");

        List<SearchUrl> returnUrls = new ArrayList<>();

        String query = "";

        int urlsToReturn = 20;

        if (params.get("q") != null) {
            query = params.get("q").get(0);
        }

        // add the seleniumrc one to make sure that the exercises work
        SearchUrl seleniumrc = new SearchUrl("http://seleniumhq.org",
                "seleniumhq.org",
                "Selenium Remote-Control",
                "Selenium RC comes in two parts. A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them. ...");

        if (query.equalsIgnoreCase("selenium-rc")) {
            returnUrls.add(seleniumrc);
            urlsToReturn--;
        }

        // try and find some matching in the list

        for (SearchUrl sUrl : urls) {
            boolean addThis = false;

            if (sUrl.description.contains(query)) {
                addThis = true;
            }

            if (sUrl.title.contains(query)) {
                addThis = true;
            }

            if (sUrl.displayUrl.contains(query)) {
                addThis = true;
            }

            if (addThis) {
                returnUrls.add(sUrl);
                urlsToReturn--;
            }

            if (urlsToReturn == 0) {
                break;
            }
        }


        if (urlsToReturn > 0) {
            // randomly choose some urls
            while (urlsToReturn > 0) {
                int totalUrls = urls.size();
                Random r = new Random();
                int Low = 0;
                int rand = r.nextInt(totalUrls - Low) + Low;
                returnUrls.add(urls.get(rand));
                urlsToReturn--;
            }
        }


        return pageHtml(query, returnUrls);
    }