no message

main
이범준 1 year ago
parent 02d034795c
commit 052b65d45d

@ -1,420 +0,0 @@
package cokr.xit.fims.framework.biz.cmm.web;
import cokr.xit.foundation.web.AbstractController;
import cokr.xit.fims.framework.biz.cmm.XitLoginVO;
import cokr.xit.fims.framework.biz.cmm.service.XitFrameCrudService;
import cokr.xit.fims.framework.biz.cmm.service.XitLoginService;
import cokr.xit.fims.framework.biz.mng.user.XitUserInfoVO;
import cokr.xit.fims.framework.core.constants.FrameworkConstants;
import cokr.xit.fims.framework.core.constants.FrameworkConstants.USER_SE;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import cokr.xit.fims.framework.core.utils.XitCmmnUtil;
import cokr.xit.fims.framework.support.util.AjaxUtils;
import lombok.extern.slf4j.Slf4j;
import org.egovframe.rte.fdl.security.config.SecurityConfig;
import org.egovframe.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@Slf4j
@Controller
@RequestMapping(name = "", value = "/login/")
public class XitLoginController extends AbstractController {
@Autowired
private XitLoginService xitLoginService;
@Autowired
private XitFrameCrudService xitFrameCrudService;
private String LOGIN_PAGE = "fimslogin";
private String ACCESS_DENIED_PAGE = "login/XitAccessDenied";
private String MAIN_PAGE = "/framework/biz/cmm/mainPage.do";
/**
*
*
* @param
* @return
* @throws Exception
*/
@RequestMapping(name = "", value = "/actionMain")
public String actionMain()
throws Exception {
// 1. Spring Security 사용자권한 처리
Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
if (!isAuthenticated) {
return LOGIN_PAGE;
}
return "forward:" + "/framework/biz/cmm/mainPage.do";
}
/**
* <pre>
* : ( ) .
* </pre>
*
* @param loginVO , LoginVO
* @param response ()
* @param request HttpServletRequest
* @param model
* @return
* @throws Exception String
* @author:
* @date: 2020. 3. 23.
*/
@RequestMapping(name = "", value = "/actionSecurityLogin")
public String actionSecurityLogin(@ModelAttribute("loginVO") XitLoginVO loginVO, HttpServletResponse response,
HttpServletRequest request, ModelMap model, @RequestParam Map<String, String> paraMap) throws Exception {
String message = null;
/**
*
* - URL
* :Security URL "loginUrl"() redirect
* :
*/
//비인증 상태에서 인가되지 않은 URL 호출에 대한 처리
if (XitCmmnUtil.isEmpty(paraMap)) {
return "forward:/login/accessDenied.do";
}
/**
*
*/
XitLoginVO xitLoginVO = null;
try {
// 로그인 처리
xitLoginVO = xitLoginService.actionLogin(loginVO);
} catch (Exception e) {
log.debug(String.format("로그인 처리 실패 : %s", e.getMessage()));
message = e.getMessage();
}
/**
*
*/
// 로그인 정보/정책에 따라 응답페이지 분기
if (xitLoginVO != null && xitLoginVO.getId() != null && !"".equals(xitLoginVO.getId())) {
// session Set
request.getSession().setAttribute("XitLoginSession", xitLoginVO);
// spring security 연동
UsernamePasswordAuthenticationFilter springSecurity = null;
ApplicationContext act = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());
Map<String, UsernamePasswordAuthenticationFilter> beans = act.getBeansOfType(UsernamePasswordAuthenticationFilter.class);
if (beans.size() > 0) {
springSecurity = (UsernamePasswordAuthenticationFilter) beans.values().toArray()[0];
springSecurity.setUsernameParameter("xit_security_username");
springSecurity.setPasswordParameter("xit_security_password");
springSecurity.setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher(
request.getServletContext().getContextPath() + "/xit_security_login", "POST"));
} else {
throw new IllegalStateException("No AuthenticationProcessingFilter");
}
xitLoginService.actionLoginSuccess();//로그인 Log 생성
// 2. 메인 페이지 이동
return "forward:" + "/framework/biz/cmm/mainPage.do";
} else {
model.addAttribute("message", message == null ? "로그인정보가 올바르지 않습니다." : message);
return LOGIN_PAGE;
}
}
/**
* .
*
* @return String
* @throws Exception
*/
@RequestMapping(name = "", value = "/actionLogout")
public String actionLogout(HttpServletRequest request) {
request.getSession().setAttribute("XitLoginSession", null);
ApplicationContext act = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());
SecurityConfig config = (SecurityConfig) act.getBean(SecurityConfig.class);
String logoutSuccessUrl = config.getLogoutSuccessUrl();
SecurityContext context = SecurityContextHolder.getContext();
context.setAuthentication(null);
//return "redirect:/egov_security_logout.do";
return "forward:" + logoutSuccessUrl;
}
/**
*
*
* @return String
* @throws Exception
*/
@RequestMapping(name = "", value = "accessDenied")
public void accessDenied(HttpServletRequest request, HttpServletResponse response) throws Exception {
/**
*
*/
if (AjaxUtils.isAjaxRequest(request)) { //ajax
//Response & Message Set
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
PrintWriter writer = response.getWriter();
String msg = "요청에 대한 권한이 없습니다.";
//응답
writer.println(msg);
} else { //submit
Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
//인증사용자
if (isAuthenticated) {
//응답
response.sendRedirect(FrameworkConstants.FRAMEWORK_JSP_BASE_PATH + ACCESS_DENIED_PAGE);
//미인증사용자
} else {
//Response & Message Set
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
PrintWriter writer = response.getWriter();
String msg = "요청에 대한 권한이 없습니다.";
//응답
String contextPath = request.getContextPath();
boolean isExistsContextPath = "/".equals(contextPath) ? false : true;
if (isExistsContextPath)
writer.println("<script type='text/javascript'>alert(\"" + msg + "\"); location.href='" + contextPath + "/login/actionMain.do';</script>");
else
writer.println("<script type='text/javascript'>alert(\"" + msg + "\"); location.href='/login/actionMain.do';</script>");
}
}
}
/**
* <pre> : </pre>
*
* @param page
* @param vo
* @return
* @throws Exception
* @author:
* @date: 2020. 10. 21.
*/
@RequestMapping(name = "", value = "/findIdPopup/{page}")
public ModelAndView findIdPopup(@PathVariable String page, @ModelAttribute("xitLoginVO") XitLoginVO vo) throws Exception {
ModelAndView mav = new ModelAndView();
if (page.endsWith(".do") || page.endsWith(".ajax")) {
page = page.substring(0, page.lastIndexOf("."));
}
switch (page) {
case "input": //아이디 찾기 -정보입력 페이지
mav.setViewName(FrameworkConstants.FRAMEWORK_JSP_BASE_PATH + "login/findIdFormPopup.popup");
break;
case "inputEvr": //(모든사용자)아이디 찾기 -정보입력 페이지
mav.setViewName(FrameworkConstants.FRAMEWORK_JSP_BASE_PATH + "login/findIdEvrFormPopup.popup");
break;
case "result": //아이디 찾기 -결과
XitLoginVO loginVO = xitLoginService.findId(vo);
mav.addObject("userAcnt", loginVO.getId());
mav.setViewName(FrameworkConstants.FRAMEWORK_JSP_BASE_PATH + "login/findIdResultFormPopup.popup");
break;
default:
throw new RuntimeException("유효하지 않은 요청 입니다.");
}
return mav;
}
/**
* <pre> : </pre>
*
* @param xitUserInfoVO
* @param page
* @throws IOException
* @throws SQLException
* @throws RuntimeException String
* @author:
* @date: 2020. 10. 21.
*/
@RequestMapping(name = "", value = "findPwdPopup/{page}")
public ModelAndView findPwdPopup(@ModelAttribute("xitUserInfoVO") XitUserInfoVO xitUserInfoVO, @PathVariable String page) throws RuntimeException {
ModelAndView mav = new ModelAndView();
if (page.endsWith(".do") || page.endsWith(".ajax")) {
page = page.substring(0, page.lastIndexOf("."));
}
switch (page) {
case "input": //비밀번호 찾기 -정보입력 페이지
mav.setViewName(FrameworkConstants.FRAMEWORK_JSP_BASE_PATH + "login/findPwdFormPopup.popup");
break;
case "inputEvr": //(모든사용자)비밀번호 찾기 -정보입력 페이지
mav.setViewName(FrameworkConstants.FRAMEWORK_JSP_BASE_PATH + "login/findPwdEvrFormPopup.popup");
break;
case "result": //비밀번호 찾기 -결과
mav.setViewName(FrameworkConstants.FRAMEWORK_JSP_BASE_PATH + "login/findPwdResultFormPopup.popup");
break;
default:
throw new RuntimeException("유효하지 않은 요청 입니다.");
}
return mav;
}
/**
* <pre> : CRUD </pre>
*
* @param res
* @param model
* @param session
* @param vo xitUserInfoVO
* @return
* @throws Exception
* @author:
* @date: 2020. 10. 21.
*/
@RequestMapping(name = "", value = "FindPwd_{cmd}_proc", method = RequestMethod.POST)
public void FindPwd_cmd_proc(HttpServletResponse res, Model model
, HttpSession session
, @ModelAttribute("xitLoginVO") XitLoginVO vo
, @PathVariable String cmd
, HttpServletRequest request
, HttpServletResponse response
) throws Exception {
String sLocationUrl = null;
Map<String, Object> resultMap = new HashMap<String, Object>();
switch (cmd) {
case "select": //조회
XitLoginVO loginVO = xitLoginService.findPassword(vo);
resultMap.put("result", XitCmmnUtil.isEmpty(loginVO.getId()) ? "N" : "Y");
break;
// case "insert": //등록
// break;
// case "inserts": //다건 등록
// break;
case "update": //수정
boolean result = false;
String message = null;
String failDetail = null;
try {
xitLoginService.modifyPassword(vo);
result = true;
message = "정상적으로 변경 되었습니다.";
} catch (Exception e) {
result = false;
message = "변경에 실패하였습니다.";
failDetail = e.getMessage();
}
model.addAttribute("result", result ? "Y" : "N");
model.addAttribute("message", message);
model.addAttribute("failDetail", failDetail);
model.addAttribute("tempPwd", vo.getPasswd());
sLocationUrl = "forward:/login/findPwdPopup/result.do";
break;
// case "delete": //삭제
// break;
// case "deletes": //다건 삭제
// break;
default:
new RuntimeException("유효하지 않은 요청 입니다.");
}
/**
*
*/
if (AjaxUtils.isAjaxRequest(request)) { //ajax 요청시
//반환 데이터 설정
Iterator<String> keys = resultMap.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
Object value = resultMap.get(key);
request.setAttribute(key, value);
}
request.getRequestDispatcher("/login/responseJson").forward(request, response);
} else { //submit 요청 시
XitCmmnUtil.forwardForSubmitRequest(request, response, sLocationUrl, model.asMap());
}
}
@RequestMapping(name = "", value = "responseJson", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseBody
public Map<String, Object> responseJson(HttpServletRequest request
) {
/**
*
*/
Map<String, Object> resultMap = new HashMap<String, Object>();
Object respData = request.getAttribute("result");
if (XitCmmnUtil.notEmpty(respData))
resultMap.put("result", respData);
return resultMap;
}
}

@ -72,7 +72,7 @@
</servlet-mapping> </servlet-mapping>
<welcome-file-list> <welcome-file-list>
<welcome-file>index.jsp</welcome-file> <welcome-file>/index.do</welcome-file>
</welcome-file-list> </welcome-file-list>
<login-config> <login-config>

Loading…
Cancel
Save