| Line 7... |
Line 7... |
| 7 |
import in.shop2020.serving.services.UserSessionInfo;
|
7 |
import in.shop2020.serving.services.UserSessionInfo;
|
| 8 |
import in.shop2020.serving.utils.DesEncrypter;
|
8 |
import in.shop2020.serving.utils.DesEncrypter;
|
| 9 |
|
9 |
|
| 10 |
import javax.servlet.http.Cookie;
|
10 |
import javax.servlet.http.Cookie;
|
| 11 |
import javax.servlet.http.HttpServletRequest;
|
11 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
12 |
import javax.servlet.http.HttpServletResponse;
|
| 12 |
import javax.servlet.http.HttpSession;
|
13 |
import javax.servlet.http.HttpSession;
|
| 13 |
|
14 |
|
| 14 |
import org.apache.juli.logging.Log;
|
15 |
import org.apache.juli.logging.Log;
|
| 15 |
import org.apache.juli.logging.LogFactory;
|
16 |
import org.apache.juli.logging.LogFactory;
|
| 16 |
import org.apache.struts2.ServletActionContext;
|
17 |
import org.apache.struts2.ServletActionContext;
|
| Line 21... |
Line 22... |
| 21 |
public class UserInterceptor extends AbstractInterceptor {
|
22 |
public class UserInterceptor extends AbstractInterceptor {
|
| 22 |
|
23 |
|
| 23 |
/**
|
24 |
/**
|
| 24 |
*
|
25 |
*
|
| 25 |
*/
|
26 |
*/
|
| - |
|
27 |
private static final int SECONDS_IN_YEAR = 60*60*24*365;
|
| - |
|
28 |
|
| 26 |
private static final long serialVersionUID = -4125815700236506235L;
|
29 |
private static final long serialVersionUID = -4125815700236506235L;
|
| 27 |
private static Log log = LogFactory.getLog(UserInterceptor.class);
|
30 |
private static Log log = LogFactory.getLog(UserInterceptor.class);
|
| 28 |
|
31 |
|
| 29 |
public static final String USER_INFO = "userinfo";
|
32 |
public static final String USER_INFO = "userinfo";
|
| 30 |
|
33 |
|
| Line 95... |
Line 98... |
| 95 |
private void createUserCookie(long userId, boolean force) {
|
98 |
private void createUserCookie(long userId, boolean force) {
|
| 96 |
userCookie = (Cookie) cookiesMap.get("uid");
|
99 |
userCookie = (Cookie) cookiesMap.get("uid");
|
| 97 |
String encryptedUserId = desEncrypter.encrypt(userId + "");
|
100 |
String encryptedUserId = desEncrypter.encrypt(userId + "");
|
| 98 |
if(force || userCookie == null || !(encryptedUserId + "").equals(userCookie.getValue())){
|
101 |
if(force || userCookie == null || !(encryptedUserId + "").equals(userCookie.getValue())){
|
| 99 |
userCookie = new Cookie("uid", encryptedUserId);
|
102 |
userCookie = new Cookie("uid", encryptedUserId);
|
| - |
|
103 |
userCookie.setMaxAge(SECONDS_IN_YEAR); // one year
|
| - |
|
104 |
userCookie.setPath("/");
|
| - |
|
105 |
log.info("Created new cookie.");
|
| 100 |
cookiesMap.put("uid", userCookie);
|
106 |
cookiesMap.put("uid", userCookie);
|
| - |
|
107 |
HttpServletResponse response = ServletActionContext.getResponse();
|
| - |
|
108 |
response.addCookie(userCookie);
|
| 101 |
}
|
109 |
}
|
| 102 |
}
|
110 |
}
|
| 103 |
|
111 |
|
| 104 |
private UserSessionInfo createAndGetSessionFromUIDCookie(HttpSession session) {
|
112 |
private UserSessionInfo createAndGetSessionFromUIDCookie(HttpSession session) {
|
| 105 |
userCookie = (Cookie) cookiesMap.get("uid");
|
113 |
userCookie = (Cookie) cookiesMap.get("uid");
|