diff --git a/src/main/java/nlib/security/SpringSecurityConfig.java b/src/main/java/nlib/security/SpringSecurityConfig.java index eab90855..0e796bdb 100644 --- a/src/main/java/nlib/security/SpringSecurityConfig.java +++ b/src/main/java/nlib/security/SpringSecurityConfig.java @@ -54,6 +54,7 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers("/js/**") .antMatchers("/temp/**") .antMatchers("/favicon/**") + .antMatchers("/homes/**") ; } @@ -83,6 +84,7 @@ public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers("/inform/**").permitAll() .antMatchers("/alert/**").permitAll() .antMatchers("/code/**").permitAll() + .antMatchers("/homes/**").permitAll() .anyRequest().authenticated() .and().formLogin() .loginPage("/login/loginForm.do") diff --git a/src/main/java/nlib/user/service/impl/LoginServiceImpl.java b/src/main/java/nlib/user/service/impl/LoginServiceImpl.java index aec851e7..3305d0e7 100644 --- a/src/main/java/nlib/user/service/impl/LoginServiceImpl.java +++ b/src/main/java/nlib/user/service/impl/LoginServiceImpl.java @@ -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를 통한 로그인 처리한다. * * return값이 null인 경우, 정상적인 로그인 처리 완료 @@ -93,6 +147,59 @@ public class LoginServiceImpl implements LoginService // 아이디와 패스워드로, 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를 통한 로그인 처리한다. + * + * 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 { // AuthenticationManager 에 token 을 넘기면 UserDetailsService 가 받아 처리하도록 한다. Authentication authentication = authenticationManager.authenticate(token); diff --git a/src/main/java/nlib/user/web/LoginController.java b/src/main/java/nlib/user/web/LoginController.java index a058421a..8b93be46 100644 --- a/src/main/java/nlib/user/web/LoginController.java +++ b/src/main/java/nlib/user/web/LoginController.java @@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -145,6 +146,8 @@ public class LoginController { log.debug("kakaoLogin.getOAuthURL() = "+kakaoLogin.getOAuthURL()); model.addAttribute("kakaoUrl", kakaoLogin.getOAuthURL()); + model.addAttribute("coutTest", "서울시 마포구"); + return "nlib/login/loginForm"; } @@ -362,6 +365,30 @@ public class LoginController { 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"; + } /** * 로그아웃 후의 처리를 담당한다. 스프링 시큐리티에서 로그아웃이 수행된 후, 호출된다. diff --git a/src/main/java/nlib/util/StringUtil.java b/src/main/java/nlib/util/StringUtil.java index eaf66979..e9c3bc50 100644 --- a/src/main/java/nlib/util/StringUtil.java +++ b/src/main/java/nlib/util/StringUtil.java @@ -1,13 +1,19 @@ package nlib.util; +import java.net.URL; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Base64; import java.util.Base64.Decoder; import java.util.Base64.Encoder; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.Locale; import egovframework.com.utl.fcc.service.EgovStringUtil; +import nlib.user.web.LoginController; /** *
@@ -32,7 +38,9 @@ import egovframework.com.utl.fcc.service.EgovStringUtil;
  *
  */
 public class StringUtil extends EgovStringUtil {
-
+	
+	private static final Logger log = LoggerFactory.getLogger(StringUtil.class);
+	
 	/**
 	 * Null 이거나, 빈문자열(공백 포함)인 경우, true를 리턴한다.
 	 * 
@@ -137,4 +145,31 @@ public class StringUtil extends EgovStringUtil {
 		Decoder decoder = Base64.getDecoder();
 		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];
+	}
 }
diff --git a/src/main/webapp/WEB-INF/jsp/nlib/login/loginForm.jsp b/src/main/webapp/WEB-INF/jsp/nlib/login/loginForm.jsp
index 06169234..4746cccf 100644
--- a/src/main/webapp/WEB-INF/jsp/nlib/login/loginForm.jsp
+++ b/src/main/webapp/WEB-INF/jsp/nlib/login/loginForm.jsp
@@ -67,5 +67,10 @@ message : ${message }
     
 
 
+-------------------
+" />
+_______________
+
+
 
 
\ No newline at end of file
diff --git a/src/main/webapp/homes/mapo.jsp b/src/main/webapp/homes/mapo.jsp
new file mode 100644
index 00000000..a7a218a0
--- /dev/null
+++ b/src/main/webapp/homes/mapo.jsp
@@ -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"%>
+
+
+
+
+
+
+마포 문화원
+
+
+
+ 

+ +

마포 문화원

+ + 

+ +JSESSIONID = <%=session.getId() %> + + 

+ +

로그인

+로그인 + + 

+ +

로그인이 필요한 화면 링크

+프로퍼티갱신 + + 

+ + + + + diff --git a/src/main/webapp/homes/seoul.jsp b/src/main/webapp/homes/seoul.jsp new file mode 100644 index 00000000..d351a4f0 --- /dev/null +++ b/src/main/webapp/homes/seoul.jsp @@ -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"%> + + + + + + +서울 문화원 + + + + 

+ +

서울 문화원

+ + + 

+ +JSESSIONID = <%=session.getId() %> + + 

+ +

로그인

+로그인 + + 

+ +

로그인이 필요한 화면 링크

+프로퍼티갱신 + +<% +String coutTest = "서울특별시 마포구 "; +%> +" />
+" /> + + 

+ + + + + diff --git a/src/main/webapp/login/index.jsp b/src/main/webapp/login/index.jsp index a8c362b1..1d3f2449 100644 --- a/src/main/webapp/login/index.jsp +++ b/src/main/webapp/login/index.jsp @@ -1,2 +1,4 @@ <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> - \ No newline at end of file + + +hello \ No newline at end of file