Search in sources :

Example 11 with RouterCookie

use of org.webpieces.ctx.api.RouterCookie in project webpieces by deanhiller.

the class CookieTranslator method scopeToCookie.

private RouterCookie scopeToCookie(CookieScopeImpl scopeData) throws UnsupportedEncodingException {
    Map<String, String> mapData = scopeData.getMapData();
    RouterCookie cookie = createBase(scopeData.getName(), null);
    StringBuilder data = translateValuesToCookieFormat(mapData);
    String value = data.toString();
    if (scopeData instanceof SecureCookie) {
        SecretKeyInfo key = config.getSecretKey();
        String sign = security.sign(key, value);
        cookie.value = VERSION + "-" + sign + ":" + value;
    } else {
        cookie.value = VERSION + ":" + value;
    }
    if (cookie.value.length() > 4050)
        throw new CookieTooLargeException("Your webserver has put too many things into the session cookie and" + " browser will end up ignoring the cookie so we exception here to let you " + "know.  Length of JUST the value(not whole cookie)=" + cookie.value.length() + "\ncookie value=" + cookie.value);
    return cookie;
}
Also used : CookieTooLargeException(org.webpieces.router.api.exceptions.CookieTooLargeException) RouterCookie(org.webpieces.ctx.api.RouterCookie) SecretKeyInfo(org.webpieces.util.security.SecretKeyInfo) SecureCookie(org.webpieces.router.impl.ctx.SecureCookie)

Example 12 with RouterCookie

use of org.webpieces.ctx.api.RouterCookie in project webpieces by deanhiller.

the class CookieTranslator method addScopeToCookieIfExist.

public void addScopeToCookieIfExist(List<RouterCookie> cookies, CookieScope cookie1) {
    if (!(cookie1 instanceof CookieScopeImpl))
        throw new IllegalArgumentException("Cookie is not the right data type=" + cookie1.getClass() + " needs to be of type " + CookieScopeImpl.class);
    CookieScopeImpl data = (CookieScopeImpl) cookie1;
    if (data.isNeedCreateSetCookie()) {
        if (log.isDebugEnabled())
            log.debug("translating cookie=" + cookie1.getName() + " to send to browser");
        RouterCookie cookie = translateScopeToCookie(data);
        cookies.add(cookie);
    } else if (data.isNeedCreateDeleteCookie()) {
        if (log.isDebugEnabled())
            log.debug("creating delete cookie for " + cookie1.getName() + " to send to browser");
        RouterCookie cookie = createDeleteCookie(data.getName());
        cookies.add(cookie);
    } else {
        if (log.isDebugEnabled())
            log.debug("not sending any cookie to browser for cookie=" + cookie1.getName());
    }
}
Also used : CookieScopeImpl(org.webpieces.router.impl.ctx.CookieScopeImpl) RouterCookie(org.webpieces.ctx.api.RouterCookie)

Aggregations

RouterCookie (org.webpieces.ctx.api.RouterCookie)12 HashMap (java.util.HashMap)3 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)2 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)2 SecureCookie (org.webpieces.router.impl.ctx.SecureCookie)2 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)1 DateTime (org.joda.time.DateTime)1 BadCookieException (org.webpieces.router.api.exceptions.BadCookieException)1 CookieTooLargeException (org.webpieces.router.api.exceptions.CookieTooLargeException)1 CookieScopeImpl (org.webpieces.router.impl.ctx.CookieScopeImpl)1 SecretKeyInfo (org.webpieces.util.security.SecretKeyInfo)1