Improve code.

This commit is contained in:
Christian P. MOMON 2013-08-24 11:47:38 +02:00
parent fc37f74a5a
commit a591ae7b74

View file

@ -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);