add: support for httponly and secure cookies

This commit is contained in:
Tobi Schäfer 2016-12-09 23:49:23 +01:00
parent 2a41085419
commit c468e8e865
3 changed files with 31 additions and 2 deletions

View file

@ -29,6 +29,8 @@ public final class CookieTrans implements Serializable {
String path; String path;
String domain; String domain;
int days = -1; int days = -1;
boolean secure;
boolean httpOnly;
CookieTrans(String name, String value) { CookieTrans(String name, String value) {
this.name = name; this.name = name;
@ -96,6 +98,22 @@ public final class CookieTrans implements Serializable {
return domain; return domain;
} }
public boolean isSecure() {
return secure;
}
void isSecure(boolean secure) {
this.secure = secure;
}
public boolean isHttpOnly() {
return httpOnly;
}
void isHttpOnly(boolean httpOnly) {
this.httpOnly = httpOnly;
}
/** /**
* *
* *
@ -127,6 +145,9 @@ public final class CookieTrans implements Serializable {
c.setDomain(defaultDomain); c.setDomain(defaultDomain);
} }
c.setHttpOnly(httpOnly);
c.setSecure(secure);
return c; return c;
} }
} }

View file

@ -999,6 +999,14 @@ public final class ResponseTrans extends Writer implements Serializable {
c.setDays(days); c.setDays(days);
c.setPath(path); c.setPath(path);
c.setDomain(domain); c.setDomain(domain);
if (!"false".equalsIgnoreCase(app.getProperty("cookies.httpOnly"))) {
c.isHttpOnly(true);
}
if ("true".equalsIgnoreCase(app.getProperty("cookies.secure"))) {
c.isSecure(true);
}
} }
/** /**

View file

@ -589,10 +589,10 @@ public abstract class AbstractServletClient extends HttpServlet {
// lowercase domain for IE // lowercase domain for IE
buffer.append("; Domain=").append(domain.toLowerCase()); buffer.append("; Domain=").append(domain.toLowerCase());
} }
if (!"false".equalsIgnoreCase(app.getProperty("httpOnlySessionCookie"))) { if (!"false".equalsIgnoreCase(app.getProperty("cookies.httpOnly"))) {
buffer.append("; HttpOnly"); buffer.append("; HttpOnly");
} }
if ("true".equalsIgnoreCase(app.getProperty("secureSessionCookie"))) { if ("true".equalsIgnoreCase(app.getProperty("cookies.secure"))) {
buffer.append("; Secure"); buffer.append("; Secure");
} }
response.addHeader("Set-Cookie", buffer.toString()); response.addHeader("Set-Cookie", buffer.toString());