Improve code.
This commit is contained in:
parent
fc37f74a5a
commit
a591ae7b74
1 changed files with 20 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue