Commit bc6d769f authored by Liang Ding's avatar Liang Ding

🎨 #12932 Cookie

parent 2ade309f
...@@ -127,6 +127,7 @@ public class IndexProcessor { ...@@ -127,6 +127,7 @@ public class IndexProcessor {
cookie = new Cookie(Common.COOKIE_NAME_MOBILE_SKIN, specifiedSkin); cookie = new Cookie(Common.COOKIE_NAME_MOBILE_SKIN, specifiedSkin);
} }
cookie.setMaxAge(60 * 60); // 1 hour cookie.setMaxAge(60 * 60); // 1 hour
cookie.setPath("/");
response.addCookie(cookie); response.addCookie(cookie);
Skins.fillLangs(preference.optString(Option.ID_C_LOCALE_STRING), (String) context.attr(Keys.TEMAPLTE_DIR_NAME), dataModel); Skins.fillLangs(preference.optString(Option.ID_C_LOCALE_STRING), (String) context.attr(Keys.TEMAPLTE_DIR_NAME), dataModel);
......
...@@ -166,9 +166,11 @@ public class SkinConsole { ...@@ -166,9 +166,11 @@ public class SkinConsole {
final Response response = context.getResponse(); final Response response = context.getResponse();
final Cookie skinDirNameCookie = new Cookie(Common.COOKIE_NAME_SKIN, skin.getString(Option.ID_C_SKIN_DIR_NAME)); final Cookie skinDirNameCookie = new Cookie(Common.COOKIE_NAME_SKIN, skin.getString(Option.ID_C_SKIN_DIR_NAME));
skinDirNameCookie.setMaxAge(60 * 60); // 1 hour skinDirNameCookie.setMaxAge(60 * 60); // 1 hour
skinDirNameCookie.setPath("/");
response.addCookie(skinDirNameCookie); response.addCookie(skinDirNameCookie);
final Cookie mobileSkinDirNameCookie = new Cookie(Common.COOKIE_NAME_MOBILE_SKIN, skin.getString(Option.ID_C_MOBILE_SKIN_DIR_NAME)); final Cookie mobileSkinDirNameCookie = new Cookie(Common.COOKIE_NAME_MOBILE_SKIN, skin.getString(Option.ID_C_MOBILE_SKIN_DIR_NAME));
mobileSkinDirNameCookie.setMaxAge(60 * 60); // 1 hour mobileSkinDirNameCookie.setMaxAge(60 * 60); // 1 hour
mobileSkinDirNameCookie.setPath("/");
response.addCookie(mobileSkinDirNameCookie); response.addCookie(mobileSkinDirNameCookie);
ret.put(Keys.STATUS_CODE, true); ret.put(Keys.STATUS_CODE, true);
......
...@@ -178,12 +178,14 @@ public class StatisticMgmtService { ...@@ -178,12 +178,14 @@ public class StatisticMgmtService {
final StringBuilder builder = new StringBuilder("[").append("\"").append(request.getRequestURI()).append("\"]"); final StringBuilder builder = new StringBuilder("[").append("\"").append(request.getRequestURI()).append("\"]");
final Cookie c = new Cookie("visited", URLs.encode(builder.toString())); final Cookie c = new Cookie("visited", URLs.encode(builder.toString()));
c.setMaxAge(COOKIE_EXPIRY); c.setMaxAge(COOKIE_EXPIRY);
c.setPath("/");
response.addCookie(c); response.addCookie(c);
} else if (needToAppend) { } else if (needToAppend) {
cookieJSONArray.put(request.getRequestURI()); cookieJSONArray.put(request.getRequestURI());
final Cookie c = new Cookie("visited", URLs.encode(cookieJSONArray.toString())); final Cookie c = new Cookie("visited", URLs.encode(cookieJSONArray.toString()));
c.setMaxAge(COOKIE_EXPIRY); c.setMaxAge(COOKIE_EXPIRY);
c.setPath("/");
response.addCookie(c); response.addCookie(c);
} }
} catch (final Exception e) { } catch (final Exception e) {
...@@ -191,6 +193,7 @@ public class StatisticMgmtService { ...@@ -191,6 +193,7 @@ public class StatisticMgmtService {
final Cookie c = new Cookie("visited", ""); final Cookie c = new Cookie("visited", "");
c.setMaxAge(0); c.setMaxAge(0);
c.setPath("/");
response.addCookie(c); response.addCookie(c);
} }
......
...@@ -266,6 +266,7 @@ public final class Solos { ...@@ -266,6 +266,7 @@ public final class Solos {
final String tokenVal = cookieJSONObject.optString(Keys.TOKEN); final String tokenVal = cookieJSONObject.optString(Keys.TOKEN);
final String token = StringUtils.substringBeforeLast(tokenVal, ":"); final String token = StringUtils.substringBeforeLast(tokenVal, ":");
if (StringUtils.equals(b3Key, token)) { if (StringUtils.equals(b3Key, token)) {
login(user, response);
return user; return user;
} }
} }
...@@ -273,6 +274,8 @@ public final class Solos { ...@@ -273,6 +274,8 @@ public final class Solos {
LOGGER.log(Level.TRACE, "Parses cookie failed, clears the cookie [name=" + COOKIE_NAME + "]"); LOGGER.log(Level.TRACE, "Parses cookie failed, clears the cookie [name=" + COOKIE_NAME + "]");
final Cookie cookie = new Cookie(COOKIE_NAME, ""); final Cookie cookie = new Cookie(COOKIE_NAME, "");
cookie.setMaxAge(0); cookie.setMaxAge(0);
cookie.setPath("/");
cookie.setHttpOnly(true);
response.addCookie(cookie); response.addCookie(cookie);
} }
...@@ -296,6 +299,8 @@ public final class Solos { ...@@ -296,6 +299,8 @@ public final class Solos {
final String cookieValue = Crypts.encryptByAES(cookieJSONObject.toString(), COOKIE_SECRET); final String cookieValue = Crypts.encryptByAES(cookieJSONObject.toString(), COOKIE_SECRET);
final Cookie cookie = new Cookie(COOKIE_NAME, cookieValue); final Cookie cookie = new Cookie(COOKIE_NAME, cookieValue);
cookie.setMaxAge(COOKIE_EXPIRY); cookie.setMaxAge(COOKIE_EXPIRY);
cookie.setPath("/");
cookie.setHttpOnly(true);
response.addCookie(cookie); response.addCookie(cookie);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.WARN, "Can not write cookie", e); LOGGER.log(Level.WARN, "Can not write cookie", e);
...@@ -313,6 +318,8 @@ public final class Solos { ...@@ -313,6 +318,8 @@ public final class Solos {
if (null != response) { if (null != response) {
final Cookie cookie = new Cookie(COOKIE_NAME, ""); final Cookie cookie = new Cookie(COOKIE_NAME, "");
cookie.setMaxAge(0); cookie.setMaxAge(0);
cookie.setPath("/");
cookie.setHttpOnly(true);
response.addCookie(cookie); response.addCookie(cookie);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment