상이 도메인 로그인 세션처리 - 중간백업

This commit is contained in:
KNKIM 2021-08-20 17:46:20 +09:00
parent 3cc150fc42
commit d985bebb79
8 changed files with 277 additions and 2 deletions

View File

@ -54,6 +54,7 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/js/**") .antMatchers("/js/**")
.antMatchers("/temp/**") .antMatchers("/temp/**")
.antMatchers("/favicon/**") .antMatchers("/favicon/**")
.antMatchers("/homes/**")
; ;
} }
@ -83,6 +84,7 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/inform/**").permitAll() .antMatchers("/inform/**").permitAll()
.antMatchers("/alert/**").permitAll() .antMatchers("/alert/**").permitAll()
.antMatchers("/code/**").permitAll() .antMatchers("/code/**").permitAll()
.antMatchers("/homes/**").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
.and().formLogin() .and().formLogin()
.loginPage("/login/loginForm.do") .loginPage("/login/loginForm.do")

View File

@ -73,6 +73,60 @@ public class LoginServiceImpl implements LoginService
} }
/* SNS 연동 SSO를 통한 로그인 처리한다.
*
* return값이 null인 경우, 정상적인 로그인 처리 완료
* null이 아닌 경우, REDIRECT되어야 하는 URL(오류 코드 포함)
*
*/
// public String loginOauth(HttpServletRequest req, String snsUserId) {
//
// // SNS 연동 사용자UID로 사용자정보 조회
// if(StringUtil.isEmpty(snsUserId)) return "/login/loginForm.do?error=req-sns-sso";
//
// NlibLoginVO nLoginVO = loginDAO.selectLoginUserInfo(snsUserId);
//
// if(nLoginVO == null) {
// return "/login/loginForm.do?error=new-membership";
// }
//
// // 아이디와 패스워드로, Security 알아 있는 token 객체로 변경한다.
// UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(nLoginVO.getLoginUserId(), nLoginVO.getUserPwd());
//
// try {
// // AuthenticationManager token 넘기면 UserDetailsService 받아 처리하도록 한다.
// Authentication authentication = authenticationManager.authenticate(token);
//
// // AuthKey 등록
// SecUserVO userVO = (SecUserVO)authentication.getPrincipal();
// userVO.getAndCreateAuthKey(req.getSession().getId()); // SET AUTHKEY
//
// // 실제 SecurityContext authentication 정보를 등록한다.
// SecurityContextHolder.getContext().setAuthentication(authentication);
//
// // TODO : 로그인 로그 정보를 통합자료시스템에 전송한다.
// userVO.setAccIp(req.getRemoteAddr());
// userVO.setLoginSucsYn("Y");
// loginDAO.insertLoginLog(userVO);
//
// } catch (DisabledException e) {
// e.printStackTrace();
// return "/login/loginForm.do?error=locked";
// } catch (LockedException e) {
// e.printStackTrace();
// return "/login/loginForm.do?error=disable";
// } catch (BadCredentialsException e) {
// e.printStackTrace();
// return "/login/loginForm.do?error=invalid-password";
// } catch (Exception e) {
// e.printStackTrace();
// return "/login/loginForm.do?error=other&message=" + e.toString();
// }
//
// return null;
// }
//
/* SNS 연동 SSO를 통한 로그인 처리한다. /* SNS 연동 SSO를 통한 로그인 처리한다.
* *
* return값이 null인 경우, 정상적인 로그인 처리 완료 * return값이 null인 경우, 정상적인 로그인 처리 완료
@ -93,6 +147,59 @@ public class LoginServiceImpl implements LoginService
// 아이디와 패스워드로, Security 알아 있는 token 객체로 변경한다. // 아이디와 패스워드로, Security 알아 있는 token 객체로 변경한다.
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(nLoginVO.getLoginUserId(), nLoginVO.getUserPwd()); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(nLoginVO.getLoginUserId(), nLoginVO.getUserPwd());
try {
// AuthenticationManager token 넘기면 UserDetailsService 받아 처리하도록 한다.
Authentication authentication = authenticationManager.authenticate(token);
// AuthKey 등록
SecUserVO userVO = (SecUserVO)authentication.getPrincipal();
userVO.getAndCreateAuthKey(req.getSession().getId()); // SET AUTHKEY
// 실제 SecurityContext authentication 정보를 등록한다.
SecurityContextHolder.getContext().setAuthentication(authentication);
// TODO : 로그인 로그 정보를 통합자료시스템에 전송한다.
userVO.setAccIp(req.getRemoteAddr());
userVO.setLoginSucsYn("Y");
loginDAO.insertLoginLog(userVO);
} catch (DisabledException e) {
e.printStackTrace();
return "/login/loginForm.do?error=locked";
} catch (LockedException e) {
e.printStackTrace();
return "/login/loginForm.do?error=disable";
} catch (BadCredentialsException e) {
e.printStackTrace();
return "/login/loginForm.do?error=invalid-password";
} catch (Exception e) {
e.printStackTrace();
return "/login/loginForm.do?error=other&message=" + e.toString();
}
return null;
}
/* SNS 연동 SSO를 통한 로그인 처리한다.
*
* return값이 null인 경우, 정상적인 로그인 처리 완료
* null이 아닌 경우, REDIRECT되어야 하는 URL(오류 코드 포함)
*
*/
public String loginSSO(HttpServletRequest req, String snsUserId) {
// SNS 연동 사용자UID로 사용자정보 조회
if(StringUtil.isEmpty(snsUserId)) return "/login/loginForm.do?error=req-sns-sso";
NlibLoginVO nLoginVO = loginDAO.selectLoginUserInfo(snsUserId);
if(nLoginVO == null) {
return "/login/loginForm.do?error=new-membership";
}
// 아이디와 패스워드로, Security 알아 있는 token 객체로 변경한다.
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(nLoginVO.getLoginUserId(), nLoginVO.getUserPwd());
try { try {
// AuthenticationManager token 넘기면 UserDetailsService 받아 처리하도록 한다. // AuthenticationManager token 넘기면 UserDetailsService 받아 처리하도록 한다.
Authentication authentication = authenticationManager.authenticate(token); Authentication authentication = authenticationManager.authenticate(token);

View File

@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude.Include;
@ -145,6 +146,8 @@ public class LoginController {
log.debug("kakaoLogin.getOAuthURL() = "+kakaoLogin.getOAuthURL()); log.debug("kakaoLogin.getOAuthURL() = "+kakaoLogin.getOAuthURL());
model.addAttribute("kakaoUrl", kakaoLogin.getOAuthURL()); model.addAttribute("kakaoUrl", kakaoLogin.getOAuthURL());
model.addAttribute("coutTest", "서울시 마포구");
return "nlib/login/loginForm"; return "nlib/login/loginForm";
} }
@ -362,6 +365,30 @@ public class LoginController {
return "redirect:" + redirectUrl; return "redirect:" + redirectUrl;
} }
@RequestMapping("/login/loginDept.do")
public String loginDept(
HttpServletRequest req,
HttpServletResponse res,
HttpSession session,
RedirectAttributes redirectAttrs,
ModelMap model) throws Exception {
String url = req.getRequestURL().toString();
String deptReturnUrl = url.replaceAll(req.getRequestURI(), "/");
String deptHostName = StringUtil.getHostName(url);
log.debug("REQ URL = " + url);
log.debug("deptJsessionId = " + session.getId());
log.debug("deptHostName = " + deptHostName);
log.debug("deptReturnUrl = " + deptReturnUrl);
redirectAttrs.addFlashAttribute("deptJsessionId", session.getId());
redirectAttrs.addFlashAttribute("deptHostName", deptHostName);
redirectAttrs.addFlashAttribute("deptReturnUrl", deptReturnUrl);
return "redirect:/login/loginForm.do";
}
/** /**
* 로그아웃 후의 처리를 담당한다. 스프링 시큐리티에서 로그아웃이 수행된 , 호출된다. * 로그아웃 후의 처리를 담당한다. 스프링 시큐리티에서 로그아웃이 수행된 , 호출된다.

View File

@ -1,13 +1,19 @@
package nlib.util; package nlib.util;
import java.net.URL;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Base64; import java.util.Base64;
import java.util.Base64.Decoder; import java.util.Base64.Decoder;
import java.util.Base64.Encoder; import java.util.Base64.Encoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Locale; import java.util.Locale;
import egovframework.com.utl.fcc.service.EgovStringUtil; import egovframework.com.utl.fcc.service.EgovStringUtil;
import nlib.user.web.LoginController;
/** /**
* <pre> * <pre>
@ -32,7 +38,9 @@ import egovframework.com.utl.fcc.service.EgovStringUtil;
* *
*/ */
public class StringUtil extends EgovStringUtil { public class StringUtil extends EgovStringUtil {
private static final Logger log = LoggerFactory.getLogger(StringUtil.class);
/** /**
* Null 이거나, 빈문자열(공백 포함) 경우, true를 리턴한다. * Null 이거나, 빈문자열(공백 포함) 경우, true를 리턴한다.
* *
@ -137,4 +145,31 @@ public class StringUtil extends EgovStringUtil {
Decoder decoder = Base64.getDecoder(); Decoder decoder = Base64.getDecoder();
return new String(decoder.decode(str.getBytes())); return new String(decoder.decode(str.getBytes()));
} }
/**
* URL 주소에서 호스트명을 리턴한다.
*
* 프로토콜://호스트.도메인/URI 에서 호스트명 리턴
* (ex) https://seoul.nculture.org/abc/def.do -> seoul 리턴한다.
*
* @param url
* @return
* @throws Exception
*/
public static String getHostName(String url) throws Exception {
if(isEmpty(url)) return "";
String hostName = "";
try {
final URL urlObj = new URL(url);
hostName = urlObj.getHost();
if(isEmpty(hostName)) return "";
} catch(Exception e) {
log.error("[ERROR] getHostName(..) : " + e.toString());
return "";
}
return (hostName.split("\\."))[0];
}
} }

View File

@ -67,5 +67,10 @@ message : ${message }
<input type="button" onclick="findInfo();" value="ID|비밀번호찾기"> <input type="button" onclick="findInfo();" value="ID|비밀번호찾기">
</div> </div>
<script src="https://apis.google.com/js/platform.js?onload=init" async defer></script> <script src="https://apis.google.com/js/platform.js?onload=init" async defer></script>
-------------------
<input type="text" value="<c:out value="${coutTest}" />" />
_______________
</body> </body>
</html> </html>

View File

@ -0,0 +1,45 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>마포 문화원</title>
</head>
<body>
&nbsp;<br>
&nbsp;<br>
<h1>마포 문화원</h1>
&nbsp;<br>
&nbsp;<br>
JSESSIONID = <%=session.getId() %>
&nbsp;<br>
&nbsp;<br>
<h2>로그인</h2>
<a href="/nlib/login/loginDept.do">로그인</a>
&nbsp;<br>
&nbsp;<br>
<h2>로그인이 필요한 화면 링크</h2>
<a href="/nlib/system/reloadProperties.do">프로퍼티갱신</a>
&nbsp;<br>
&nbsp;<br>
<script>
</script>
</body>
</html>

View File

@ -0,0 +1,52 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>서울 문화원</title>
</head>
<body>
&nbsp;<br>
&nbsp;<br>
<h1>서울 문화원</h1>
&nbsp;<br>
&nbsp;<br>
JSESSIONID = <%=session.getId() %>
&nbsp;<br>
&nbsp;<br>
<h2>로그인</h2>
<a href="/nlib/login/loginDept.do">로그인</a>
&nbsp;<br>
&nbsp;<br>
<h2>로그인이 필요한 화면 링크</h2>
<a href="/nlib/system/reloadProperties.do">프로퍼티갱신</a>
<%
String coutTest = "서울특별시 마포구 ";
%>
<input type="text" name="kkk" value="<c:out value="${'ab c' }" />" /> <br>
<input type="text" name="ssssss" value="<c:out value='${"서울특별시 마포구"}' />" />
&nbsp;<br>
&nbsp;<br>
<script>
</script>
</body>
</html>

View File

@ -1,2 +1,4 @@
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<jsp:forward page="/index.do"/>
hello