Ejemplo n.º 1
0
  private boolean authenticate(HttpServerRequest request) {
    String authString = request.headers().get(HttpHeaders.AUTHORIZATION);

    if (authString == null) return false;

    String[] basicAuth = StringUtils.splitByWholeSeparator(authString, "Basic "); // $NON-NLS-1$

    if (basicAuth.length == 1) {
      return basicAuth(request, basicAuth[0]);
    }

    return false;
  }
  /**
   * Does something with a session id. It will use the session id provided by the client inside the
   * http server request. If it cannot find it, it will create a new session.
   *
   * @param req The http server request.
   * @param handler The handler to call with the created or found session id.
   */
  public void withSessionId(final HttpServerRequest req, final Handler<String> handler) {
    String value = req.headers().get("Cookie");
    if (value != null) {
      Set<Cookie> cookies = new CookieDecoder().decode(value);
      for (final Cookie cookie : cookies) {
        if (cookieField.equals(cookie.getName())) {
          handler.handle(cookie.getValue());
          return;
        }
      }
    }

    startSession(req, handler);
  }