public static void addFlash(Response response, String message, Kind kind) { dropboxes.put(nextdrop,new Flash(message, kind)); Series<CookieSetting> cookies = response.getCookieSettings(); CookieSetting flashdrop = null; for(CookieSetting cs : cookies) { if(cs.getName().equals("flashdrop")) { flashdrop = cs; } } if(flashdrop == null) { cookies.add(new CookieSetting("flashdrop",Long.toString(nextdrop))); } else { flashdrop.setValue(flashdrop.getValue()+","+Long.toString(nextdrop)); } nextdrop++; }
/** * Converts the Restlet CookieSettings to a JAX-RS NewCookie. * * @param cookieSetting * @return the JAX-RS NewCookie * @throws IllegalArgumentException */ public static NewCookie toJaxRsNewCookie(CookieSetting cookieSetting) throws IllegalArgumentException { if (cookieSetting == null) { return null; } return new NewCookie(cookieSetting.getName(), cookieSetting.getValue(), cookieSetting.getPath(), cookieSetting.getDomain(), cookieSetting.getVersion(), cookieSetting.getComment(), cookieSetting.getMaxAge(), cookieSetting.isSecure()); }
@Override public String toString() { return "CookieSetting [accessRestricted=" + accessRestricted + ", comment=" + comment + ", maxAge=" + maxAge + ", secure=" + secure + ", domain=" + getDomain() + ", name=" + getName() + ", path=" + getPath() + ", value=" + getValue() + ", version=" + getVersion() + "]"; }
@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); } }
CookieSetting result = new CookieSetting(pair.getName(), pair.getValue()); result.setPath(pair.getValue()); } else if (pair.getName().equalsIgnoreCase(NAME_SET_DOMAIN)) { result.setDomain(pair.getValue()); } else if (pair.getName().equalsIgnoreCase(NAME_SET_COMMENT)) { result.setComment(pair.getValue()); } else if (pair.getName().equalsIgnoreCase(NAME_SET_COMMENT_URL)) { result.setMaxAge(-1); } else if (pair.getName().equalsIgnoreCase(NAME_SET_EXPIRES)) { Date expires = DateUtils.parse(pair.getValue(), FORMAT_RFC_1036); final Date current = new Date(System.currentTimeMillis()); if (DateUtils.after(current, expires)) { result.setMaxAge((int) ((expires.getTime() - current.getTime()) / 1000)); } else { result.setMaxAge(0); result.setMaxAge(Integer.valueOf(pair.getValue())); } catch (NumberFormatException numberFormatException) { result.setMaxAge(Integer.MAX_VALUE); Context.getCurrentLogger() .warning( result.setSecure(true); result.setAccessRestricted(true);
@Override public CookieSetting createEntry(String name, String value) { return new CookieSetting(name, value); }
/** {@inheritDoc} */ @Override public int hashCode() { return SystemUtils.hashCode(super.hashCode(), getComment(), getMaxAge(), isSecure()); }
credentialsCookie = new CookieSetting(this.getCookieName(), null); credentialsCookie.setAccessRestricted(true); credentialsCookie.setPath(p == null ? "/" : p);
@Override public String getName() { return target.getName(); }
@Override public String getValue() { return target.getValue(); }
@Override public boolean getSecure() { return target.isSecure(); }
@Override public int getExpiry() { return target.getMaxAge(); }
@Override public void setExpiry(int expiry) { target.setMaxAge(expiry); }
@Override public String getDomain() { return target.getDomain(); }
@Override public String getPath() { return target.getPath(); }
@Override public int getVersion() { return target.getVersion(); }
/** * Converts the Restlet {@link CookieSetting} to a JAX-RS {@link NewCookie}. * * @param cookieSetting * The Restlet cookie setting. * @return The JAX-RS NewCookie * @throws IllegalArgumentException */ public static NewCookie toNewCookie(CookieSetting cookieSetting) throws IllegalArgumentException { if (cookieSetting == null) { return null; } return new NewCookie(cookieSetting.getName(), cookieSetting.getValue(), cookieSetting.getPath(), cookieSetting.getDomain(), cookieSetting.getVersion(), cookieSetting.getComment(), cookieSetting.getMaxAge(), cookieSetting.isSecure()); }
@Override public String toString() { return "CookieSetting [accessRestricted=" + accessRestricted + ", comment=" + comment + ", maxAge=" + maxAge + ", secure=" + secure + ", domain=" + getDomain() + ", name=" + getName() + ", path=" + getPath() + ", value=" + getValue() + ", version=" + getVersion() + "]"; }
@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); } }