你不必做任何事情。只要啓動會話的請求是https
Tomcat將會話cookie標記爲secure
。
我也看了看是否有任何正式記錄的事實,但我找不到它。但那是至少Tomcat 6.0.32及更高版本的行爲。
下面是從org/apache/catalina/connector/Request.java
的代碼,在方法的末尾,檢查是否請求是安全的,如果是,設置在cookie中的secure
標誌:
/**
* Configures the given JSESSIONID cookie.
*
* @param cookie The JSESSIONID cookie to be configured
*/
protected void configureSessionCookie(Cookie cookie) {
cookie.setMaxAge(-1);
Context ctxt = getContext();
String contextPath = null;
if (ctxt != null && !getConnector().getEmptySessionPath()) {
if (ctxt.getSessionCookiePath() != null) {
contextPath = ctxt.getSessionCookiePath();
} else {
contextPath = ctxt.getEncodedPath();
}
}
if ((contextPath != null) && (contextPath.length() > 0)) {
cookie.setPath(contextPath);
} else {
cookie.setPath("/");
}
if (ctxt != null && ctxt.getSessionCookieDomain() != null) {
cookie.setDomain(ctxt.getSessionCookieDomain());
}
if (isSecure()) {
cookie.setSecure(true);
}
}
更新:您可以手動嘗試自行使用過濾器等設置這個..你可以檢查從 set 'secure' flag to JSESSION id cookie
的例子只是想確認:在我的情況下,你的選擇(Safari的Webinspector的瀏覽器開發工具,查看您的會話cookie )會告訴你,該cookie確實是一個安全的cookie – 2013-09-20 15:28:02