@Override
  protected void afterHandle(Request request, Response response) {
    super.afterHandle(request, response);
    Cookie cookie = request.getCookies().getFirst("Credentials");

    if (request.getClientInfo().isAuthenticated() && (cookie == null)) {
      String identifier = request.getChallengeResponse().getIdentifier();
      String secret = new String(request.getChallengeResponse().getSecret());
      CookieSetting cookieSetting = new CookieSetting("Credentials", identifier + "=" + secret);
      cookieSetting.setAccessRestricted(true);
      cookieSetting.setPath("/");
      cookieSetting.setComment("Unsecured cookie based authentication");
      cookieSetting.setMaxAge(30);
      response.getCookieSettings().add(cookieSetting);
    }
  }
Esempio n. 2
0
  private void setHeader(Response ares) {
    Series<Header> headers =
        (Series<Header>) ares.getAttributes().get(RadonAttributeKey.ATTRIBUTE_HEADERS);
    if (headers != null) {
      for (Header header : headers) {
        header(header.getName(), header.getValue());
      }
    }

    Series<CookieSetting> cookies = ares.getCookieSettings();
    for (CookieSetting c : cookies) {
      cookie(new Cookie(c.getVersion(), c.getName(), c.getValue(), c.getPath(), c.getDomain()));
    }

    status(ares.getStatus().getCode());
    if (ares.getLocationRef() != null) {
      header(HeaderConstants.HEADER_LOCATION, ares.getLocationRef().toString());
    }
  }