| Line 12... |
Line 12... |
| 12 |
import org.springframework.stereotype.Component;
|
12 |
import org.springframework.stereotype.Component;
|
| 13 |
|
13 |
|
| 14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 15 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
15 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 16 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
16 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 17 |
import com.spice.profitmandi.web.model.FofoDetails;
|
17 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 18 |
|
18 |
|
| 19 |
@Component
|
19 |
@Component
|
| 20 |
public class CookiesProcessor {
|
20 |
public class CookiesProcessor {
|
| 21 |
|
21 |
|
| 22 |
private static final Logger LOGGER = LoggerFactory.getLogger(CookiesProcessor.class);
|
22 |
private static final Logger LOGGER = LoggerFactory.getLogger(CookiesProcessor.class);
|
| 23 |
|
23 |
|
| 24 |
public FofoDetails getCookiesObject(HttpServletRequest request) throws ProfitMandiBusinessException{
|
24 |
public LoginDetails getCookiesObject(HttpServletRequest request) throws ProfitMandiBusinessException{
|
| 25 |
Cookie[] cookies = request.getCookies();
|
25 |
Cookie[] cookies = request.getCookies();
|
| 26 |
if (cookies == null){
|
26 |
if (cookies == null){
|
| 27 |
throw new ProfitMandiBusinessException("", "", "");
|
27 |
throw new ProfitMandiBusinessException("", "", "");
|
| 28 |
}
|
28 |
}
|
| 29 |
String fofoIdFound = null, emailIdFound = null, roleNamesString = null;
|
29 |
String fofoIdFound = null, emailIdFound = null, roleNamesString = null, fofoFlagFound = null;
|
| 30 |
for(Cookie cookie : cookies){
|
30 |
for(Cookie cookie : cookies){
|
| 31 |
LOGGER.info("Requested Cookie {}={}", cookie.getName(), cookie.getValue());
|
31 |
LOGGER.info("Requested Cookie {}={}", cookie.getName(), cookie.getValue());
|
| 32 |
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()){
|
| 33 |
fofoIdFound = cookie.getValue();
|
33 |
fofoIdFound = cookie.getValue();
|
| 34 |
}
|
34 |
}
|
| Line 36... |
Line 36... |
| 36 |
emailIdFound = cookie.getValue();
|
36 |
emailIdFound = cookie.getValue();
|
| 37 |
}
|
37 |
}
|
| 38 |
if(cookie.getName().equals(ProfitMandiConstants.ROLE_NAMES) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
|
38 |
if(cookie.getName().equals(ProfitMandiConstants.ROLE_NAMES) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
|
| 39 |
roleNamesString = cookie.getValue();
|
39 |
roleNamesString = cookie.getValue();
|
| 40 |
}
|
40 |
}
|
| - |
|
41 |
if(cookie.getName().equals(ProfitMandiConstants.FOFO_FLAG) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
|
| - |
|
42 |
fofoFlagFound = cookie.getValue();
|
| - |
|
43 |
}
|
| 41 |
if(fofoIdFound != null && emailIdFound != null && roleNamesString != null){
|
44 |
if(fofoIdFound != null && emailIdFound != null && roleNamesString != null && fofoFlagFound != null){
|
| 42 |
break;
|
45 |
break;
|
| 43 |
}
|
46 |
}
|
| 44 |
}
|
47 |
}
|
| 45 |
|
48 |
|
| 46 |
if(fofoIdFound == null || emailIdFound == null || roleNamesString == null){
|
49 |
if(fofoIdFound == null || emailIdFound == null || roleNamesString == null || fofoFlagFound == null){
|
| 47 |
LOGGER.error("Requested session is not valid");
|
50 |
LOGGER.error("Requested session is not valid");
|
| 48 |
throw new ProfitMandiBusinessException("", "", "");
|
51 |
throw new ProfitMandiBusinessException("", "", "");
|
| 49 |
}else{
|
52 |
}else{
|
| 50 |
FofoDetails fofoDetails = new FofoDetails();
|
53 |
LoginDetails fofoDetails = new LoginDetails();
|
| 51 |
fofoDetails.setFofoId(Integer.parseInt(fofoIdFound));
|
54 |
fofoDetails.setFofoId(Integer.parseInt(fofoIdFound));
|
| 52 |
fofoDetails.setEmailId(emailIdFound);
|
55 |
fofoDetails.setEmailId(emailIdFound);
|
| 53 |
String[] roleNames = roleNamesString.split(",");
|
56 |
String[] roleNames = roleNamesString.split(",");
|
| 54 |
Set<RoleType> roleTypes = new HashSet<>();
|
57 |
Set<RoleType> roleTypes = new HashSet<>();
|
| 55 |
for(String roleName : roleNames){
|
58 |
for(String roleName : roleNames){
|
| 56 |
RoleType roleType = RoleType.valueOf(roleName);
|
59 |
RoleType roleType = RoleType.valueOf(roleName);
|
| 57 |
roleTypes.add(roleType);
|
60 |
roleTypes.add(roleType);
|
| 58 |
}
|
61 |
}
|
| 59 |
fofoDetails.setRoleTypes(roleTypes);
|
62 |
fofoDetails.setRoleTypes(roleTypes);
|
| - |
|
63 |
fofoDetails.setFofo(Boolean.parseBoolean(fofoFlagFound));
|
| 60 |
return fofoDetails;
|
64 |
return fofoDetails;
|
| 61 |
}
|
65 |
}
|
| 62 |
|
66 |
|
| 63 |
}
|
67 |
}
|
| 64 |
|
68 |
|
| Line 80... |
Line 84... |
| 80 |
|
84 |
|
| 81 |
Cookie cookieRoleNames = new Cookie(ProfitMandiConstants.ROLE_NAMES, "");
|
85 |
Cookie cookieRoleNames = new Cookie(ProfitMandiConstants.ROLE_NAMES, "");
|
| 82 |
cookieRoleNames.setMaxAge(0);
|
86 |
cookieRoleNames.setMaxAge(0);
|
| 83 |
cookieRoleNames.setDomain(request.getServerName());
|
87 |
cookieRoleNames.setDomain(request.getServerName());
|
| 84 |
cookieRoleNames.setPath(request.getContextPath());
|
88 |
cookieRoleNames.setPath(request.getContextPath());
|
| - |
|
89 |
|
| - |
|
90 |
Cookie cookieFofoFlag = new Cookie(ProfitMandiConstants.FOFO_FLAG, "");
|
| - |
|
91 |
cookieFofoFlag.setMaxAge(0);
|
| - |
|
92 |
cookieFofoFlag.setDomain(request.getServerName());
|
| - |
|
93 |
cookieFofoFlag.setPath(request.getContextPath());
|
| 85 |
|
94 |
|
| 86 |
response.addCookie(cookieFofoId);
|
95 |
response.addCookie(cookieFofoId);
|
| 87 |
response.addCookie(cookieEmailId);
|
96 |
response.addCookie(cookieEmailId);
|
| 88 |
response.addCookie(cookieRoleNames);
|
97 |
response.addCookie(cookieRoleNames);
|
| - |
|
98 |
response.addCookie(cookieFofoFlag);
|
| 89 |
}
|
99 |
}
|
| 90 |
}
|
100 |
}
|