You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
308 lines
12 KiB
Java
308 lines
12 KiB
Java
/**
|
|
* @Class Name : AccessLoginIntercepter.java
|
|
* @Description : 권한, 접근제한, 로그등록 을 위한 controller 인터셉터
|
|
* 수정일 수정자 수정내용
|
|
* -------------------------------------------------------------
|
|
* 2013. 6. 4. woonee 최초 생성
|
|
*
|
|
*/
|
|
package xit.itgcms.util;
|
|
|
|
import java.io.IOException;
|
|
import java.io.PrintWriter;
|
|
import java.sql.SQLException;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
|
|
import egovframework.rte.psl.dataaccess.util.EgovMap;
|
|
import xit.common.model.GroupVO;
|
|
import xit.common.service.FrameworkService;
|
|
import xit.itgcms.common.MngrSessionVO;
|
|
import xit.itgcms.core.manager.service.MngrManagerService;
|
|
import xit.itgcms.core.manager.service.MngrManagerVO;
|
|
import xit.itgcms.core.mngMenuAuth.service.MngMenuAuthService;
|
|
import xit.itgcms.core.mngmenu.service.MngMenuService;
|
|
import xit.utils.CommonUtil;
|
|
import xit.vips.schedule.service.VipsScheduleService;
|
|
import xit.vips.schedule.web.VipsScheduleController;
|
|
|
|
@Service
|
|
public class AccessLogIntercepter extends HandlerInterceptorAdapter {
|
|
|
|
/** MngrGroupService */
|
|
@Resource(name = "mngMenuService")
|
|
private MngMenuService mngMenuService;
|
|
@Resource(name = "mngrManagerService")
|
|
private MngrManagerService mngrManagerService;
|
|
@Resource(name = "frameworkService")
|
|
private FrameworkService frameworkService;
|
|
@Resource(name = "vipsScheduleService")
|
|
private VipsScheduleService vipsScheduleService;
|
|
|
|
/** MngMenuAuthService */
|
|
@Resource(name = "mngMenuAuthService")
|
|
private MngMenuAuthService mngMenuAuthService;
|
|
|
|
public Logger LOGGER = Logger.getLogger(this.getClass());
|
|
|
|
@Override
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
// 요청 URL
|
|
String url = request.getRequestURI();
|
|
String referer = request.getHeader("referer");
|
|
LOGGER.info("==========check");
|
|
// 로그인 시 에는 통과하도록
|
|
if (url.substring(0,6).equals("/login")||url.contains("/mobile/notify/rest/"))
|
|
return true;
|
|
if (url.contains("/mngr_input_popup.do")&&("".equals(referer)||null==referer||referer.contains("/login/login.do"))){
|
|
return true;
|
|
}
|
|
if (url.contains("/mngr_input_popup_image.do")&&("".equals(referer)||null==referer||referer.contains("/mngr_input_popup.do"))){
|
|
return true;
|
|
}
|
|
if(url.contains("/mngr_edit_popup.do")
|
|
||url.startsWith("/cmmn/popup/")
|
|
||url.startsWith("/cmmn/process/")
|
|
||url.startsWith("/cmmn/find/")
|
|
||url.startsWith("/cmmn/exists/")
|
|
){
|
|
if(!("".equals(CommUtil.getMngrMemId())||CommUtil.getMngrMemId()==null))
|
|
return true;
|
|
}
|
|
if(url.contains("/mngr_proc.do")
|
|
||url.contains("/comm_juso_popup.do")
|
|
||url.contains("/manager/comm_mngr_checkid.ajax")){
|
|
return true;
|
|
}
|
|
|
|
// 세션값이 존재하면 통과 없으면 로그인 페이지로
|
|
LOGGER.info("interceptor start !!");
|
|
if(CommUtil.getMngrSessionVO() == null) {
|
|
/*PrintWriter writer=response.getWriter();
|
|
response.setCharacterEncoding("UTF-8");
|
|
response.setContentType("text/html; charset=UTF-8");
|
|
writer.println("<script type='text/javascript'>alert('로그인이 필요합니다.'); location.href='/login/login.do';</script>");*/
|
|
|
|
|
|
response.sendRedirect("/login/login.do");
|
|
return false;
|
|
|
|
// this.setDevSession(request);
|
|
}
|
|
|
|
/**
|
|
* URL 규칙에 따라 권한을 체크한다.
|
|
* 1. common 으로 시작하는 것은 체크하지 않는다.
|
|
* 2. 프로세스 중 comm 이 들어가면 체크하지 않는다.
|
|
* 3. 1,2를 제외한 모든 URL은 권한체크를 한다.
|
|
* 리스트:list, 등록:input, 수정:edit, 상세:view, 답변:reply, 다운로드:down, 업로드:upload, 출력:print
|
|
* 슈퍼(총괄)관리자는 권한체크를 하지 않는다.
|
|
*/
|
|
|
|
if(!"99".equals(CommUtil.getMngrSessionVO().getMngAuth())){ //슈퍼관리자 체크
|
|
|
|
String[] arrUrl = url.split("\\.")[0].split("/");
|
|
String[] chkUrl = arrUrl[arrUrl.length - 1].split("_");
|
|
|
|
String jobSort = chkUrl[0];
|
|
String authChkUrl = "/";
|
|
for(int i=1; i < arrUrl.length-1; i++) {
|
|
authChkUrl += arrUrl[i] + "/";
|
|
}
|
|
authChkUrl += jobSort;
|
|
|
|
if (arrUrl[1].equals("common") || arrUrl[1].equals("jfile")) {
|
|
return true;
|
|
}else if (chkUrl[0].equals("comm") || chkUrl[0].equals("main")) {
|
|
return true;
|
|
}else { // 메뉴권한을 가져와서 해당 권한이 있는지 체크한다.
|
|
|
|
boolean auth = false;
|
|
|
|
HashMap<String,Object> commandMap = new HashMap<String,Object>();
|
|
commandMap.put("mng_id", CommUtil.getMngrMemId());
|
|
commandMap.put("authChkUrl", authChkUrl);
|
|
EgovMap authInfo = mngMenuAuthService.selectAuthInfoById(commandMap);
|
|
if(authInfo != null) {
|
|
String authAct = chkUrl[1];
|
|
|
|
if("list".equals(authAct) && "Y".equals(authInfo.get("readAuth"))) {
|
|
auth = true;
|
|
}
|
|
else if("input".equals(authAct) && "Y".equals(authInfo.get("writeAuth"))) {
|
|
auth = true;
|
|
}
|
|
else if("edit".equals(authAct) && "Y".equals(authInfo.get("updateAuth"))) {
|
|
auth = true;
|
|
}
|
|
else if("view".equals(authAct) && "Y".equals(authInfo.get("readAuth"))) {
|
|
auth = true;
|
|
}
|
|
else if("reply".equals(authAct) && "Y".equals(authInfo.get("writeAuth"))) {
|
|
auth = true;
|
|
}
|
|
else if("down".equals(authAct) && "Y".equals(authInfo.get("downAuth"))) {
|
|
auth = true;
|
|
}
|
|
else if("upload".equals(authAct) && "Y".equals(authInfo.get("uploadAuth"))) {
|
|
auth = true;
|
|
}
|
|
else if("print".equals(authAct) && "Y".equals(authInfo.get("printAuth"))) {
|
|
auth = true;
|
|
}
|
|
else if("proc".equals(authAct)) {
|
|
String mode = request.getParameter("mode") == null ? "" : request.getParameter("mode");
|
|
LOGGER.info(mode);
|
|
if (mode.equals("insert")||mode.equals("change")) {
|
|
if ("Y".equals(authInfo.get("writeAuth")))
|
|
auth = true;
|
|
} else if (mode.equals("update")||mode.equals("approval")
|
|
||mode.equals("volunlevy")||mode.equals("rmvolunlevy") //volunlevy:자납부과,rmvolunlevy:자납부과삭제
|
|
||mode.equals("anytmlevy")||mode.equals("rmanytmlevy") //anytmlevy:수시부과,anytmlevy:수시부과삭제
|
|
||mode.equals("addrciv")||mode.equals("rmrciv") //addrciv:수납등록,rmrciv:수납취소
|
|
//운행정지 업무관련 권한추가
|
|
||mode.equals("disableDriveSave")||mode.equals("disableDriveDelete") //disableDriveSave,disableDriveDelete:운행정지 상태값 변경
|
|
) {
|
|
if ("Y".equals(authInfo.get("updateAuth")))
|
|
auth = true;
|
|
} else if (mode.equals("delete")) {
|
|
if ("Y".equals(authInfo.get("deleteAuth")))
|
|
auth = true;
|
|
} else if (mode.equals("reply")) {
|
|
if ("Y".equals(authInfo.get("writeAuth")))
|
|
auth = true;
|
|
}
|
|
}
|
|
}
|
|
LOGGER.info(auth);
|
|
|
|
if (!auth) {
|
|
response.setCharacterEncoding("UTF-8");
|
|
response.setContentType("text/html; charset=UTF-8");
|
|
PrintWriter writer=response.getWriter();
|
|
if(url.contains("ajax")) {
|
|
writer.println("false");
|
|
}else if(url.contains("popup")) {
|
|
writer.println("<script type='text/javascript'>alert('해당 권한이 없습니다.'); self.close();</script>");
|
|
}else if("true".equalsIgnoreCase(request.getHeader("AJAX"))){
|
|
writer.println("해당 권한이 없습니다");
|
|
}else {
|
|
writer.println("<script type='text/javascript'>alert('해당 권한이 없습니다.'); history.go(-1);</script>");
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 레이아웃 구성을 위해 권한에 해당되는 메뉴목록을 가져온다.
|
|
*/
|
|
@SuppressWarnings({ "unused", "unchecked" })
|
|
@Override
|
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView mv) throws Exception
|
|
{
|
|
// 요청 URL
|
|
String url = request.getRequestURI();
|
|
if (!url.contains("proc") && !url.contains("popup") && !url.contains("ajax") && !url.contains("comm") && !(url.contains("/category")&&url.contains("_down_excel"))) {
|
|
// 메뉴 목록을 가져와서 뷰에 던져준다.
|
|
HashMap<String,Object> commandMap = new HashMap<String,Object>();
|
|
if(!"vips".equals(CommUtil.getMngrMemId())){
|
|
commandMap.put("mng_id", CommUtil.getMngrMemId());
|
|
}
|
|
List<EgovMap> allMenuList = mngMenuService.selectMenuInfoList(commandMap);
|
|
|
|
String[] arrUrl = url.split("/");
|
|
String[] jobUrl = arrUrl[arrUrl.length-1].split("_");
|
|
String jobSort = jobUrl[0];
|
|
String chkUrl = "/";
|
|
for(int i=1; i < arrUrl.length-1; i++) {
|
|
chkUrl += arrUrl[i] + "/";
|
|
}
|
|
chkUrl += jobSort;
|
|
Map<String, Object> urlInfoMap = null;
|
|
for(int i=0; i < allMenuList.size(); i++) {
|
|
Map<String, Object> tmpMap = allMenuList.get(i);
|
|
if (tmpMap.get("menuUrl").toString().contains(chkUrl)) {
|
|
String[] arrPath = tmpMap.get("menuPath").toString().split("_");
|
|
tmpMap.put("secondMenu", arrPath[1]);
|
|
mv.addObject("urlInfoMap", tmpMap);
|
|
}
|
|
}
|
|
|
|
mv.addObject("allMenuList", allMenuList);
|
|
|
|
/**
|
|
* 사이드바 접기/펼치기 상태값 설정
|
|
*/
|
|
String sidebar_stts = request.getParameter("sidebar_stts")==null?"active":request.getParameter("sidebar_stts");
|
|
if("/main/main.do".equals(url)) sidebar_stts = "";
|
|
mv.addObject("sidebar_stts", sidebar_stts);
|
|
|
|
/**
|
|
* 롤링 공지사항
|
|
*/
|
|
if(CommonUtil.isEmpty(VipsScheduleController.ARR_ROLLING_NOTICE))
|
|
VipsScheduleController.ARR_ROLLING_NOTICE = vipsScheduleService.findRollingNotices();
|
|
mv.addObject("arr_rolling_notice", VipsScheduleController.ARR_ROLLING_NOTICE);
|
|
}
|
|
LOGGER.info("interceptor complete !!");
|
|
}
|
|
|
|
|
|
private void setDevSession(HttpServletRequest request) throws IOException, SQLException {
|
|
MngrManagerVO loginManagerVO = new MngrManagerVO();
|
|
loginManagerVO.setId("vips");
|
|
loginManagerVO = mngrManagerService.mngrManagerView(loginManagerVO);
|
|
|
|
loginManagerVO.setMngId("vips");
|
|
loginManagerVO.setMngName("슈퍼관리자");
|
|
loginManagerVO.setMngEmail("vips@xit.co.kr");
|
|
loginManagerVO.setMngPhone("000-0000-0000");
|
|
loginManagerVO.setAuthIdx("0");
|
|
loginManagerVO.setMngType("1");
|
|
loginManagerVO.setMngPower("99");
|
|
loginManagerVO.setMngAuth("99");
|
|
|
|
|
|
|
|
MngrSessionVO mngrSessionVO = new MngrSessionVO();
|
|
mngrSessionVO.setId(loginManagerVO.getMngId());
|
|
mngrSessionVO.setName(loginManagerVO.getMngName());
|
|
mngrSessionVO.setEmail(loginManagerVO.getMngEmail());
|
|
mngrSessionVO.setPhone(loginManagerVO.getMngPhone());
|
|
mngrSessionVO.setGroup(loginManagerVO.getGroupCode());;
|
|
mngrSessionVO.setPosition(loginManagerVO.getPositionCode());
|
|
mngrSessionVO.setAuthority(loginManagerVO.getAuthIdx());
|
|
mngrSessionVO.setType(loginManagerVO.getMngType());
|
|
//mngrSessionVO.setMngPower(loginManagerVO.getMngPower());
|
|
mngrSessionVO.setGroupName(loginManagerVO.getGroupCodeName());
|
|
mngrSessionVO.setPositionName(loginManagerVO.getPositionCodeName());
|
|
mngrSessionVO.setMngAuth(loginManagerVO.getMngAuth());
|
|
mngrSessionVO.setDeptCode(loginManagerVO.getDeptCode());
|
|
mngrSessionVO.setDeptName(loginManagerVO.getDeptName());
|
|
GroupVO groupVO = new GroupVO();
|
|
groupVO.setG_code(loginManagerVO.getGroupCode());
|
|
mngrSessionVO.setSearchRange(frameworkService.findGroup(groupVO).getSearch_range());
|
|
//mngrSessionVO.setLicenseType(licenseVO.getValue(3).toString());
|
|
mngrSessionVO.setAtdrc_cd(loginManagerVO.getAtdrcCd()); //자치구코드
|
|
|
|
|
|
HttpSession session = request.getSession();
|
|
session.setAttribute("mngrSessionVO", mngrSessionVO);
|
|
}
|
|
}
|