| Line 6... |
Line 6... |
| 6 |
import javax.servlet.http.Cookie;
|
6 |
import javax.servlet.http.Cookie;
|
| 7 |
import javax.servlet.http.HttpServletRequest;
|
7 |
import javax.servlet.http.HttpServletRequest;
|
| 8 |
import javax.servlet.http.HttpServletResponse;
|
8 |
import javax.servlet.http.HttpServletResponse;
|
| 9 |
|
9 |
|
| 10 |
import org.apache.commons.lang3.StringUtils;
|
10 |
import org.apache.commons.lang3.StringUtils;
|
| 11 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 12 |
import org.apache.logging.log4j.LogManager;
|
11 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
12 |
import org.apache.logging.log4j.Logger;
|
| 13 |
import org.springframework.stereotype.Component;
|
13 |
import org.springframework.stereotype.Component;
|
| 14 |
|
14 |
|
| 15 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
15 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 16 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
16 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 17 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
- |
|
| 18 |
import com.spice.profitmandi.web.model.LoginDetails;
|
17 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 19 |
|
18 |
|
| 20 |
@Component
|
19 |
@Component
|
| 21 |
public class CookiesProcessor {
|
20 |
public class CookiesProcessor {
|
| 22 |
|
21 |
|
| 23 |
private static final Logger LOGGER = LogManager.getLogger(CookiesProcessor.class);
|
22 |
private static final Logger LOGGER = LogManager.getLogger(CookiesProcessor.class);
|
| 24 |
|
23 |
|
| 25 |
public LoginDetails getCookiesObject(HttpServletRequest request) throws ProfitMandiBusinessException{
|
24 |
public LoginDetails getCookiesObject(HttpServletRequest request) throws ProfitMandiBusinessException{
|
| 26 |
Cookie[] cookies = request.getCookies();
|
25 |
Cookie[] cookies = request.getCookies();
|
| 27 |
if (cookies == null){
|
26 |
if (cookies == null){
|
| 28 |
throw new ProfitMandiBusinessException("", "", "");
|
27 |
throw new ProfitMandiBusinessException("cookies", "", "GE_1008");
|
| 29 |
}
|
28 |
}
|
| 30 |
String fofoIdFound = null, emailIdFound = null, roleNamesString = null;
|
29 |
String fofoIdFound = null, emailIdFound = null, roleIdsString = null;
|
| 31 |
for(Cookie cookie : cookies){
|
30 |
for(Cookie cookie : cookies){
|
| 32 |
LOGGER.info("Requested Cookie {}={}", cookie.getName(), cookie.getValue());
|
31 |
LOGGER.info("Requested Cookie {}={}", cookie.getName(), cookie.getValue());
|
| 33 |
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()){
|
| 34 |
fofoIdFound = cookie.getValue();
|
33 |
fofoIdFound = cookie.getValue();
|
| 35 |
}
|
34 |
}
|
| 36 |
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()){
|
| 37 |
emailIdFound = cookie.getValue();
|
36 |
emailIdFound = cookie.getValue();
|
| 38 |
}
|
37 |
}
|
| 39 |
if(cookie.getName().equals(ProfitMandiConstants.ROLE_NAMES) && cookie.getValue() != null){
|
38 |
if(cookie.getName().equals(ProfitMandiConstants.ROLE_IDS) && cookie.getValue() != null){
|
| 40 |
roleNamesString = cookie.getValue();
|
39 |
roleIdsString = cookie.getValue();
|
| 41 |
//LOGGER.info("roleNameString is {}", roleNamesString);
|
40 |
//LOGGER.info("roleNameString is {}", roleNamesString);
|
| 42 |
}
|
41 |
}
|
| 43 |
if(fofoIdFound != null && emailIdFound != null && roleNamesString != null){
|
42 |
if(fofoIdFound != null && emailIdFound != null && roleIdsString != null){
|
| 44 |
break;
|
43 |
break;
|
| 45 |
}
|
44 |
}
|
| 46 |
}
|
45 |
}
|
| 47 |
|
46 |
|
| 48 |
if(fofoIdFound == null || emailIdFound == null || roleNamesString == null){
|
47 |
if(fofoIdFound == null || emailIdFound == null || roleIdsString == null){
|
| 49 |
LOGGER.info("roleNameString is {}", roleNamesString);
|
48 |
LOGGER.info("roleIdString is {}", roleIdsString);
|
| 50 |
LOGGER.info("fofoIdFound is {}", fofoIdFound);
|
49 |
LOGGER.info("fofoIdFound is {}", fofoIdFound);
|
| 51 |
LOGGER.info("emailIdFound is {}", emailIdFound);
|
50 |
LOGGER.info("emailIdFound is {}", emailIdFound);
|
| 52 |
LOGGER.error("Requested session is not valid");
|
51 |
LOGGER.error("Requested session is not valid");
|
| 53 |
throw new ProfitMandiBusinessException("", "", "");
|
52 |
throw new ProfitMandiBusinessException("cookies", "", "GE_1008");
|
| 54 |
}else {
|
53 |
}else {
|
| 55 |
LoginDetails fofoDetails = new LoginDetails();
|
54 |
LoginDetails fofoDetails = new LoginDetails();
|
| 56 |
fofoDetails.setFofoId(Integer.parseInt(fofoIdFound));
|
55 |
fofoDetails.setFofoId(Integer.parseInt(fofoIdFound));
|
| 57 |
fofoDetails.setEmailId(emailIdFound);
|
56 |
fofoDetails.setEmailId(emailIdFound);
|
| 58 |
String[] roleNames = StringUtils.split(roleNamesString, ",");
|
57 |
String[] roleIdStrings = StringUtils.split(roleIdsString, ",");
|
| 59 |
Set<RoleType> roleTypes = new HashSet<>();
|
58 |
Set<Integer> roleIds = new HashSet<>();
|
| 60 |
for(String roleName : roleNames){
|
59 |
for(String roleId : roleIdStrings){
|
| 61 |
RoleType roleType = RoleType.valueOf(roleName);
|
60 |
roleIds.add(Integer.valueOf(roleId));
|
| 62 |
roleTypes.add(roleType);
|
- |
|
| 63 |
}
|
61 |
}
|
| 64 |
fofoDetails.setRoleTypes(roleTypes);
|
62 |
fofoDetails.setRoleIds(roleIds);
|
| 65 |
return fofoDetails;
|
63 |
return fofoDetails;
|
| 66 |
}
|
64 |
}
|
| 67 |
|
65 |
|
| 68 |
}
|
66 |
}
|
| 69 |
|
67 |
|
| Line 81... |
Line 79... |
| 81 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, "");
|
79 |
Cookie cookieEmailId = new Cookie(ProfitMandiConstants.EMAIL_ID, "");
|
| 82 |
cookieEmailId.setMaxAge(0);
|
80 |
cookieEmailId.setMaxAge(0);
|
| 83 |
cookieEmailId.setDomain(request.getServerName());
|
81 |
cookieEmailId.setDomain(request.getServerName());
|
| 84 |
cookieEmailId.setPath(request.getContextPath());
|
82 |
cookieEmailId.setPath(request.getContextPath());
|
| 85 |
|
83 |
|
| 86 |
Cookie cookieRoleNames = new Cookie(ProfitMandiConstants.ROLE_NAMES, "");
|
84 |
Cookie cookieRoleNames = new Cookie(ProfitMandiConstants.ROLE_IDS, "");
|
| 87 |
cookieRoleNames.setMaxAge(0);
|
85 |
cookieRoleNames.setMaxAge(0);
|
| 88 |
cookieRoleNames.setDomain(request.getServerName());
|
86 |
cookieRoleNames.setDomain(request.getServerName());
|
| 89 |
cookieRoleNames.setPath(request.getContextPath());
|
87 |
cookieRoleNames.setPath(request.getContextPath());
|
| 90 |
|
88 |
|
| 91 |
Cookie cookieFofoFlag = new Cookie(ProfitMandiConstants.FOFO_FLAG, "");
|
89 |
Cookie cookieFofoFlag = new Cookie(ProfitMandiConstants.FOFO_FLAG, "");
|