| 22107 |
ashik.ali |
1 |
package com.spice.profitmandi.web.interceptor;
|
|
|
2 |
|
|
|
3 |
import javax.servlet.http.HttpServletRequest;
|
|
|
4 |
import javax.servlet.http.HttpServletResponse;
|
|
|
5 |
|
| 23784 |
ashik.ali |
6 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
7 |
import org.apache.logging.log4j.Logger;
|
| 22107 |
ashik.ali |
8 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
9 |
import org.springframework.stereotype.Component;
|
|
|
10 |
import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
11 |
import org.springframework.web.servlet.ModelAndView;
|
|
|
12 |
|
|
|
13 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23798 |
amit.gupta |
14 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 22139 |
amit.gupta |
15 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 22107 |
ashik.ali |
16 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
17 |
|
|
|
18 |
@Component
|
|
|
19 |
public class RoleInterceptor implements HandlerInterceptor {
|
| 23784 |
ashik.ali |
20 |
|
|
|
21 |
@Autowired
|
|
|
22 |
private RoleManager roleManager;
|
| 22107 |
ashik.ali |
23 |
|
| 23568 |
govind |
24 |
private static final Logger LOGGER = LogManager.getLogger(RoleInterceptor.class);
|
| 22107 |
ashik.ali |
25 |
|
|
|
26 |
@Autowired
|
| 22927 |
ashik.ali |
27 |
private CookiesProcessor cookiesProcessor;
|
| 22107 |
ashik.ali |
28 |
|
|
|
29 |
@Override
|
|
|
30 |
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object arg2, Exception arg3)
|
|
|
31 |
throws Exception {
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
@Override
|
|
|
35 |
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView arg3)
|
|
|
36 |
throws Exception {
|
|
|
37 |
LOGGER.info("request is received after : "+request.getRequestURL().toString());
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
@Override
|
|
|
41 |
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception {
|
| 23784 |
ashik.ali |
42 |
LOGGER.info("request is received before uri [{}], method [{}]", request.getRequestURI(), request.getMethod());
|
|
|
43 |
LoginDetails loginDetails = null;
|
| 22107 |
ashik.ali |
44 |
try {
|
| 23784 |
ashik.ali |
45 |
loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22107 |
ashik.ali |
46 |
} catch (ProfitMandiBusinessException e) {
|
|
|
47 |
LOGGER.error("Requested session is expired", e);
|
| 23784 |
ashik.ali |
48 |
throw e;
|
| 22107 |
ashik.ali |
49 |
}
|
| 23784 |
ashik.ali |
50 |
return roleManager.isAuthorizedURI(loginDetails.getRoleIds(), request.getContextPath(), request.getRequestURI(), request.getMethod());
|
| 22107 |
ashik.ali |
51 |
}
|
| 23784 |
ashik.ali |
52 |
|
|
|
53 |
|
| 22107 |
ashik.ali |
54 |
}
|