| Line 30... |
Line 30... |
| 30 |
|
30 |
|
| 31 |
public static final String USER_INFO_COOKIE_NAME = "uic";
|
31 |
public static final String USER_INFO_COOKIE_NAME = "uic";
|
| 32 |
public static final String USER_ID_COOKIE_NAME = "uid";
|
32 |
public static final String USER_ID_COOKIE_NAME = "uid";
|
| 33 |
public static final String COOKIE_DECRYPTION_STRING = "shop2020";
|
33 |
public static final String COOKIE_DECRYPTION_STRING = "shop2020";
|
| 34 |
|
34 |
|
| 35 |
private Map<String, Cookie> cookiesMap = null;
|
- |
|
| 36 |
private Cookie userCookie = null;
|
- |
|
| 37 |
private DesEncrypter desEncrypter = new DesEncrypter(COOKIE_DECRYPTION_STRING);
|
35 |
private DesEncrypter desEncrypter = new DesEncrypter(COOKIE_DECRYPTION_STRING);
|
| 38 |
|
36 |
|
| 39 |
private Cookie userinfoCookie = null;
|
- |
|
| 40 |
|
- |
|
| 41 |
private String cookieDomain = "";
|
37 |
private String cookieDomain = "";
|
| 42 |
|
38 |
|
| 43 |
public void setCookieDomain(String cookieDomain) {
|
39 |
public void setCookieDomain(String cookieDomain) {
|
| 44 |
this.cookieDomain = cookieDomain;
|
40 |
this.cookieDomain = cookieDomain;
|
| 45 |
}
|
41 |
}
|
| Line 47... |
Line 43... |
| 47 |
@Override
|
43 |
@Override
|
| 48 |
public String intercept(ActionInvocation invocation) throws Exception {
|
44 |
public String intercept(ActionInvocation invocation) throws Exception {
|
| 49 |
final Object action = invocation.getAction();
|
45 |
final Object action = invocation.getAction();
|
| 50 |
|
46 |
|
| 51 |
log.debug("inside user intercepror");
|
47 |
log.debug("inside user intercepror");
|
| 52 |
|
48 |
|
| 53 |
HttpServletRequest request = ServletActionContext.getRequest();
|
49 |
HttpServletRequest request = ServletActionContext.getRequest();
|
| 54 |
HttpSession session = request.getSession(); // Do not remove it, session id is used for session tracking.
|
50 |
HttpSession session = request.getSession(); // Do not remove it, session id is used for session tracking.
|
| 55 |
|
51 |
|
| 56 |
createCookiesMap(request);
|
52 |
Map<String, Cookie> cookiesMap = createCookiesMap(request);
|
| 57 |
|
53 |
|
| 58 |
// CreateUserInterceptor may have set the userinfo object in the request
|
54 |
// CreateUserInterceptor may have set the userinfo object in the request
|
| 59 |
// itself. If we can get the userinfo object here, we don't need to
|
55 |
// itself. If we can get the userinfo object here, we don't need to
|
| 60 |
// parse the cookies that came in with the request.
|
56 |
// parse the cookies that came in with the request.
|
| 61 |
UserSessionInfo userInfo = (UserSessionInfo) request.getAttribute(USER_INFO_COOKIE_NAME);
|
57 |
UserSessionInfo userInfo = (UserSessionInfo) request.getAttribute(USER_INFO_COOKIE_NAME);
|
| 62 |
|
58 |
|
| 63 |
userCookie = cookiesMap.get(UserInterceptor.USER_ID_COOKIE_NAME);
|
59 |
Cookie userCookie = cookiesMap.get(UserInterceptor.USER_ID_COOKIE_NAME);
|
| 64 |
userinfoCookie = cookiesMap.get(USER_INFO_COOKIE_NAME);
|
60 |
Cookie userinfoCookie = cookiesMap.get(USER_INFO_COOKIE_NAME);
|
| 65 |
|
61 |
|
| 66 |
if(userInfo == null ){
|
62 |
if(userInfo == null ){
|
| 67 |
//Okay, we didn't get the userinfo object from the request. Time to parse the UIC cookie.
|
63 |
//Okay, we didn't get the userinfo object from the request. Time to parse the UIC cookie.
|
| 68 |
if(userinfoCookie!=null){
|
64 |
if(userinfoCookie!=null){
|
| 69 |
userInfo = UserSessionInfo.getUserSessionInfoFromCookieValue(userinfoCookie.getValue());
|
65 |
userInfo = UserSessionInfo.getUserSessionInfoFromCookieValue(userinfoCookie.getValue());
|
| Line 72... |
Line 68... |
| 72 |
expireUicCookie();
|
68 |
expireUicCookie();
|
| 73 |
expireUidCookie();
|
69 |
expireUidCookie();
|
| 74 |
}
|
70 |
}
|
| 75 |
} else {
|
71 |
} else {
|
| 76 |
//No UIC cookie too. Try the old UID cookie. This method is guaranteed to return a userinfo object, cookie or not.
|
72 |
//No UIC cookie too. Try the old UID cookie. This method is guaranteed to return a userinfo object, cookie or not.
|
| 77 |
userInfo = createAndGetSessionFromUIDCookie(session);
|
73 |
userInfo = createAndGetSessionFromUIDCookie(session, cookiesMap, userCookie);
|
| 78 |
}
|
74 |
}
|
| 79 |
}
|
75 |
}
|
| 80 |
|
76 |
|
| 81 |
//Set the request attribute for access by other interceptors.
|
77 |
//Set the request attribute for access by other interceptors.
|
| 82 |
request.setAttribute(USER_INFO_COOKIE_NAME, userInfo);
|
78 |
request.setAttribute(USER_INFO_COOKIE_NAME, userInfo);
|
| Line 133... |
Line 129... |
| 133 |
* cookie domain explicitly to .saholic.com and different cookies were set
|
129 |
* cookie domain explicitly to .saholic.com and different cookies were set
|
| 134 |
* for saholic.com and www.saholic.com.
|
130 |
* for saholic.com and www.saholic.com.
|
| 135 |
*
|
131 |
*
|
| 136 |
* @param request
|
132 |
* @param request
|
| 137 |
*/
|
133 |
*/
|
| 138 |
private void createCookiesMap(HttpServletRequest request) {
|
134 |
private Map<String, Cookie> createCookiesMap(HttpServletRequest request) {
|
| 139 |
cookiesMap = new HashMap<String, Cookie>();
|
135 |
Map<String, Cookie> cookiesMap = new HashMap<String, Cookie>();
|
| 140 |
Cookie[] cookies = request.getCookies();
|
136 |
Cookie[] cookies = request.getCookies();
|
| 141 |
if(cookies==null)
|
137 |
if(cookies==null)
|
| 142 |
return;
|
138 |
return cookiesMap;
|
| 143 |
for (Cookie cookie : cookies) {
|
139 |
for (Cookie cookie : cookies) {
|
| 144 |
if (cookie.getName().equals(UserInterceptor.USER_ID_COOKIE_NAME)) {
|
140 |
if (cookie.getName().equals(UserInterceptor.USER_ID_COOKIE_NAME)) {
|
| 145 |
if (cookie.getDomain() == null || cookie.getDomain().isEmpty()
|
141 |
if (cookie.getDomain() == null || cookie.getDomain().isEmpty()
|
| 146 |
|| !cookie.getDomain().equals(this.cookieDomain))
|
142 |
|| !cookie.getDomain().equals(this.cookieDomain))
|
| 147 |
{
|
143 |
{
|
| Line 160... |
Line 156... |
| 160 |
}
|
156 |
}
|
| 161 |
}
|
157 |
}
|
| 162 |
}
|
158 |
}
|
| 163 |
cookiesMap.put(cookie.getName(), cookie);
|
159 |
cookiesMap.put(cookie.getName(), cookie);
|
| 164 |
}
|
160 |
}
|
| - |
|
161 |
return cookiesMap;
|
| 165 |
}
|
162 |
}
|
| 166 |
|
163 |
|
| 167 |
/**
|
164 |
/**
|
| 168 |
* Creates and gets session information from the UID cookie. This should be
|
165 |
* Creates and gets session information from the UID cookie. This should be
|
| 169 |
* called only when the required information couldn't be had from the UIC
|
166 |
* called only when the required information couldn't be had from the UIC
|
| Line 172... |
Line 169... |
| 172 |
* It also expires the UID cookie if it can't parse the cookie value.
|
169 |
* It also expires the UID cookie if it can't parse the cookie value.
|
| 173 |
*
|
170 |
*
|
| 174 |
* @param session
|
171 |
* @param session
|
| 175 |
* @return A user session info object.
|
172 |
* @return A user session info object.
|
| 176 |
*/
|
173 |
*/
|
| 177 |
private UserSessionInfo createAndGetSessionFromUIDCookie(HttpSession session) {
|
174 |
private UserSessionInfo createAndGetSessionFromUIDCookie(HttpSession session, Map<String, Cookie> cookiesMap, Cookie userCookie) {
|
| 178 |
userCookie = (Cookie) cookiesMap.get(UserInterceptor.USER_ID_COOKIE_NAME);
|
- |
|
| 179 |
UserSessionInfo userInfo = null;
|
175 |
UserSessionInfo userInfo = null;
|
| 180 |
if(userCookie != null){
|
176 |
if(userCookie != null){
|
| 181 |
String uidString = userCookie.getValue();
|
177 |
String uidString = userCookie.getValue();
|
| 182 |
if(uidString != null){
|
178 |
if(uidString != null){
|
| 183 |
try {
|
179 |
try {
|