From a591ae7b749010b866c19202c48e87e2dbd79db1 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 24 Aug 2013 11:47:38 +0200 Subject: [PATCH] Improve code. --- src/fr/devinsy/kiss4web/CookieHelper.java | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/fr/devinsy/kiss4web/CookieHelper.java b/src/fr/devinsy/kiss4web/CookieHelper.java index 33e0a6d..23559f2 100644 --- a/src/fr/devinsy/kiss4web/CookieHelper.java +++ b/src/fr/devinsy/kiss4web/CookieHelper.java @@ -12,6 +12,11 @@ import org.slf4j.LoggerFactory; */ public class CookieHelper { + public enum Scope + { + HTTP_AND_HTTPS, HTTPS_ONLY + } + static private final Logger logger = LoggerFactory.getLogger(CookieHelper.class); /** @@ -21,7 +26,7 @@ public class CookieHelper { Cookie result; - result = buildCookie(name, value, duration, false); + result = buildCookie(name, value, duration, Scope.HTTP_AND_HTTPS); // return (result); @@ -30,14 +35,26 @@ public class CookieHelper /** * */ - static public Cookie buildCookie(final String name, final String value, final int duration, final boolean isSecure) + static public Cookie buildCookie(final String name, final String value, final int duration, final Scope secure) { Cookie result; + // result = new Cookie(name, value); result.setMaxAge(duration); result.setPath("/"); - result.setSecure(isSecure); + + // + boolean secureValue; + if (secure == Scope.HTTPS_ONLY) + { + secureValue = true; + } + else + { + secureValue = false; + } + result.setSecure(secureValue); // return (result);