| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.util;
|
1 |
package com.spice.profitmandi.web.util;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.util.HashSet;
|
| - |
|
4 |
import java.util.Set;
|
| - |
|
5 |
|
| 3 |
import javax.servlet.http.Cookie;
|
6 |
import javax.servlet.http.Cookie;
|
| 4 |
import javax.servlet.http.HttpServletRequest;
|
7 |
import javax.servlet.http.HttpServletRequest;
|
| 5 |
import javax.servlet.http.HttpServletResponse;
|
8 |
import javax.servlet.http.HttpServletResponse;
|
| 6 |
|
9 |
|
| 7 |
import org.slf4j.Logger;
|
10 |
import org.slf4j.Logger;
|
| 8 |
import org.slf4j.LoggerFactory;
|
11 |
import org.slf4j.LoggerFactory;
|
| 9 |
import org.springframework.stereotype.Component;
|
12 |
import org.springframework.stereotype.Component;
|
| 10 |
|
13 |
|
| 11 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 12 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
15 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
16 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 13 |
import com.spice.profitmandi.web.model.FofoDetails;
|
17 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| 14 |
|
18 |
|
| 15 |
@Component
|
19 |
@Component
|
| 16 |
public class CookiesProcessor {
|
20 |
public class CookiesProcessor {
|
| 17 |
|
21 |
|
| Line 20... |
Line 24... |
| 20 |
public FofoDetails getCookiesObject(HttpServletRequest request) throws ProfitMandiBusinessException{
|
24 |
public FofoDetails getCookiesObject(HttpServletRequest request) throws ProfitMandiBusinessException{
|
| 21 |
Cookie[] cookies = request.getCookies();
|
25 |
Cookie[] cookies = request.getCookies();
|
| 22 |
if (cookies == null){
|
26 |
if (cookies == null){
|
| 23 |
throw new ProfitMandiBusinessException("", "", "");
|
27 |
throw new ProfitMandiBusinessException("", "", "");
|
| 24 |
}
|
28 |
}
|
| 25 |
String fofoIdFound = null, emailIdFound = null;
|
29 |
String fofoIdFound = null, emailIdFound = null, roleNamesString = null;
|
| 26 |
for(Cookie cookie : cookies){
|
30 |
for(Cookie cookie : cookies){
|
| 27 |
LOGGER.info("Requested Cookie {}", cookie.getName());
|
31 |
LOGGER.info("Requested Cookie {}={}", cookie.getName(), cookie.getValue());
|
| 28 |
if(cookie.getName().equals(ProfitMandiConstants.FOFO_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
|
32 |
if(cookie.getName().equals(ProfitMandiConstants.FOFO_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
|
| 29 |
fofoIdFound = cookie.getValue();
|
33 |
fofoIdFound = cookie.getValue();
|
| 30 |
}
|
34 |
}
|
| 31 |
if(cookie.getName().equals(ProfitMandiConstants.EMAIL_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
|
35 |
if(cookie.getName().equals(ProfitMandiConstants.EMAIL_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
|
| 32 |
emailIdFound = cookie.getValue();
|
36 |
emailIdFound = cookie.getValue();
|
| 33 |
}
|
37 |
}
|
| - |
|
38 |
if(cookie.getName().equals(ProfitMandiConstants.ROLE_NAMES) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
|
| - |
|
39 |
roleNamesString = cookie.getValue();
|
| - |
|
40 |
}
|
| 34 |
if(fofoIdFound != null && emailIdFound != null){
|
41 |
if(fofoIdFound != null && emailIdFound != null && roleNamesString != null){
|
| 35 |
break;
|
42 |
break;
|
| 36 |
}
|
43 |
}
|
| 37 |
}
|
44 |
}
|
| 38 |
|
45 |
|
| 39 |
if(fofoIdFound == null || emailIdFound == null){
|
46 |
if(fofoIdFound == null || emailIdFound == null || roleNamesString == null){
|
| 40 |
LOGGER.error("Requested session is not valid");
|
47 |
LOGGER.error("Requested session is not valid");
|
| 41 |
throw new ProfitMandiBusinessException("", "", "");
|
48 |
throw new ProfitMandiBusinessException("", "", "");
|
| 42 |
}else{
|
49 |
}else{
|
| 43 |
FofoDetails fofoDetails = new FofoDetails();
|
50 |
FofoDetails fofoDetails = new FofoDetails();
|
| 44 |
fofoDetails.setFofoId(Integer.parseInt(fofoIdFound));
|
51 |
fofoDetails.setFofoId(Integer.parseInt(fofoIdFound));
|
| 45 |
fofoDetails.setEmailId(emailIdFound);
|
52 |
fofoDetails.setEmailId(emailIdFound);
|
| - |
|
53 |
String[] roleNames = roleNamesString.split(",");
|
| - |
|
54 |
Set<RoleType> roleTypes = new HashSet<>();
|
| - |
|
55 |
for(String roleName : roleNames){
|
| - |
|
56 |
RoleType roleType = RoleType.valueOf(roleName);
|
| - |
|
57 |
roleTypes.add(roleType);
|
| - |
|
58 |
}
|
| - |
|
59 |
fofoDetails.setRoleTypes(roleTypes);
|
| 46 |
return fofoDetails;
|
60 |
return fofoDetails;
|
| 47 |
}
|
61 |
}
|
| 48 |
|
62 |
|
| 49 |
}
|
63 |
}
|
| 50 |
|
64 |
|
| 51 |
public void removeCookies(HttpServletRequest request, HttpServletResponse response) throws ProfitMandiBusinessException{
|
65 |
public void removeCookies(HttpServletRequest request, HttpServletResponse response) throws ProfitMandiBusinessException{
|
| Line 62... |
Line 76... |
| 62 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, "");
|
76 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, "");
|
| 63 |
cookieEmailId.setMaxAge(0);
|
77 |
cookieEmailId.setMaxAge(0);
|
| 64 |
cookieEmailId.setDomain(request.getServerName());
|
78 |
cookieEmailId.setDomain(request.getServerName());
|
| 65 |
cookieEmailId.setPath(request.getContextPath());
|
79 |
cookieEmailId.setPath(request.getContextPath());
|
| 66 |
|
80 |
|
| - |
|
81 |
Cookie cookieRoleNames = new Cookie(ProfitMandiConstants.ROLE_NAMES, "");
|
| - |
|
82 |
cookieRoleNames.setMaxAge(0);
|
| - |
|
83 |
cookieRoleNames.setDomain(request.getServerName());
|
| - |
|
84 |
cookieRoleNames.setPath(request.getContextPath());
|
| - |
|
85 |
|
| 67 |
response.addCookie(cookieFofoId);
|
86 |
response.addCookie(cookieFofoId);
|
| 68 |
response.addCookie(cookieEmailId);
|
87 |
response.addCookie(cookieEmailId);
|
| - |
|
88 |
response.addCookie(cookieRoleNames);
|
| 69 |
}
|
89 |
}
|
| 70 |
}
|
90 |
}
|