This commit is contained in:
JSYOO 2021-08-31 16:25:25 +09:00
commit 29ae57d5ad
9 changed files with 90 additions and 77 deletions

View File

@ -35,11 +35,19 @@ import nlib.util.StringUtil;
public class OAuthLogin { public class OAuthLogin {
/** SNS 호출 시, URL callType 대체 문자열 */
public static final String CALL_TYPE_LOGIN = "login";
public static final String CALL_TYPE_MEMBER = "member";
private OAuth20Service oauthService; private OAuth20Service oauthService;
private OAuthVO oauthVO; private OAuthVO oauthVO;
public OAuthLogin(OAuthVO oauthVO) { public OAuthLogin(OAuthVO oauthVO, String callType) {
if(oauthVO.getService().equals("google"))
{
ScopeBuilder scope = new ScopeBuilder(); ScopeBuilder scope = new ScopeBuilder();
scope.withScope("profile"); scope.withScope("profile");
scope.withScope("openid"); scope.withScope("openid");
@ -47,24 +55,22 @@ public class OAuthLogin {
scope.withScope("https://www.googleapis.com/auth/user.phonenumbers.read"); scope.withScope("https://www.googleapis.com/auth/user.phonenumbers.read");
scope.withScope("https://www.googleapis.com/auth/user.birthday.read"); scope.withScope("https://www.googleapis.com/auth/user.birthday.read");
if(oauthVO.getService().equals("google"))
{
this.oauthService = new ServiceBuilder(oauthVO.getClientId()) this.oauthService = new ServiceBuilder(oauthVO.getClientId())
.apiSecret(oauthVO.getClientSecret()) .apiSecret(oauthVO.getClientSecret())
.callback(oauthVO.getRedirectUrl()) .callback(oauthVO.getRedirectUrl(callType))
.defaultScope(scope) .defaultScope(scope)
//.scope("profile") //.scope("profile")
.build(oauthVO.getApi20Instance()); .build(oauthVO.getApi20Instance());
}else if(oauthVO.getService().equals("kakao") || oauthVO.getService().equals("naver"))
{ } else if(oauthVO.getService().equals("kakao") || oauthVO.getService().equals("naver")) {
this.oauthService = new ServiceBuilder(oauthVO.getClientId()) this.oauthService = new ServiceBuilder(oauthVO.getClientId())
.apiSecret(oauthVO.getClientSecret()) .apiSecret(oauthVO.getClientSecret())
.callback(oauthVO.getRedirectUrl()) .callback(oauthVO.getRedirectUrl(callType))
//.scope("profile") //.scope("profile")
.build(oauthVO.getApi20Instance()); .build(oauthVO.getApi20Instance());
} }
this.oauthVO = oauthVO; this.oauthVO = oauthVO;
} }
@ -90,10 +96,10 @@ public class OAuthLogin {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(body); JsonNode rootNode = mapper.readTree(body);
if (this.oauthVO.isNaver()) {
//------------------------------------ //------------------------------------
// 네이버 (2021.08.19 KKN) // 네이버 (2021.08.19 KKN)
//------------------------------------ //------------------------------------
if (this.oauthVO.isNaver()) {
user.setSnsType(OAuthConfig.NAVER_SERVICE_NAME); user.setSnsType(OAuthConfig.NAVER_SERVICE_NAME);
JsonNode resNode = rootNode.get("response"); JsonNode resNode = rootNode.get("response");
@ -135,10 +141,10 @@ public class OAuthLogin {
user.setValidLogin(true); user.setValidLogin(true);
} }
else if (this.oauthVO.isGoogle()) {
//------------------------------------ //------------------------------------
// 구글 // 구글
//------------------------------------ //------------------------------------
else if (this.oauthVO.isGoogle()) {
user.setSnsType(OAuthConfig.GOOGLE_SERVICE_NAME); user.setSnsType(OAuthConfig.GOOGLE_SERVICE_NAME);
if (rootNode.has("sub")) if (rootNode.has("sub"))
user.setSnsId(StringUtil.getString(rootNode.get("sub").asText(), "")); user.setSnsId(StringUtil.getString(rootNode.get("sub").asText(), ""));
@ -148,10 +154,10 @@ public class OAuthLogin {
} }
else if (this.oauthVO.isKakao()) {
//------------------------------------ //------------------------------------
// 카카오 // 카카오
//------------------------------------ //------------------------------------
else if (this.oauthVO.isKakao()) {
user.setSnsType(OAuthConfig.KAKAO_SERVICE_NAME); user.setSnsType(OAuthConfig.KAKAO_SERVICE_NAME);
JsonNode resNode = rootNode.get("kakao_account"); JsonNode resNode = rootNode.get("kakao_account");
@ -170,7 +176,6 @@ public class OAuthLogin {
if (resNode.has("phone_number")) if (resNode.has("phone_number"))
user.setSnsMobileNo(StringUtil.getString(resNode.get("phone_number").asText(), "")); user.setSnsMobileNo(StringUtil.getString(resNode.get("phone_number").asText(), ""));
} }
return user; return user;

View File

@ -30,8 +30,10 @@ public class OAuthVO implements OAuthConfig {
this.clientSecret = clientSecret; this.clientSecret = clientSecret;
} }
public String getRedirectUrl() { public String getRedirectUrl(String callType) {
return redirectUrl; String retUrl = redirectUrl.replaceAll("\\{callType\\}", callType);
retUrl = retUrl.replaceAll("\\{oauthServiceName\\}", getService());
return retUrl;
} }
public void setRedirectUrl(String redirectUrl) { public void setRedirectUrl(String redirectUrl) {

View File

@ -51,19 +51,19 @@ public class NlibInterceptor extends HandlerInterceptorAdapter {
// 지방문화원 접속 정보를 세션에 담기 // 지방문화원 접속 정보를 세션에 담기
//--------------------------------------- //---------------------------------------
HttpSession session = request.getSession(); HttpSession session = request.getSession();
String curCouncilCd = (String)session.getAttribute("curCouncilCd"); log.debug("preHandle > sessionid=" + session.getId());
if(StringUtil.isEmpty(curCouncilCd)) { String councilCd = (String)session.getAttribute("councilCd");
if(StringUtil.isEmpty(councilCd)) {
// 지방문화원 코드 확인 // 지방문화원 코드 확인
String curCouncilDnsHost = StringUtil.getHostName(request.getRequestURL().toString()); String councilDnsHost = StringUtil.getHostName(request.getRequestURL().toString());
HashMap<String, String> councilInfoMap = loginService.selectCouncilInfoByDnsHost(curCouncilDnsHost); HashMap<String, String> councilInfoMap = loginService.selectCouncilInfoByDnsHost(councilDnsHost);
curCouncilCd = councilInfoMap.get("councilCd"); councilCd = councilInfoMap.get("councilCd");
if(StringUtil.equals(NlibProperty.getString(""), curCouncilCd)) { if(!StringUtil.equalsIgnoreCase(NlibProperty.getString("nlib.council.cd"), councilCd)) {
session.setAttribute("councilCd" , councilCd);
session.setAttribute("councilNm" , councilInfoMap.get("councilNm"));
session.setAttribute("councilDnsHost", councilDnsHost);
} }
session.setAttribute("curCouncilCd" , curCouncilCd);
session.setAttribute("curCouncilNm" , councilInfoMap.get("councilNm"));
session.setAttribute("curCouncilDnsHost", curCouncilDnsHost);
} }
return true; return true;

View File

@ -44,7 +44,7 @@ public class SessionConfig implements HttpSessionListener {
private static final String DELIMITER = "\t"; private static final String DELIMITER = "\t";
/* 세션별 로그인 처리 가능한 정보 목록 */ /* 세션별 로그인 처리 가능한 정보 목록 */
private static final Map<String, String> loginSessions = new ConcurrentHashMap<>(); private static final Map<String, OAuthUniversalUser> loginSessions = new ConcurrentHashMap<>();
/* 세션별 회원가입 처리 가능한 정보 목록 */ /* 세션별 회원가입 처리 가능한 정보 목록 */
private static final Map<String, OAuthUniversalUser> memberSessions = new ConcurrentHashMap<>(); private static final Map<String, OAuthUniversalUser> memberSessions = new ConcurrentHashMap<>();
@ -73,9 +73,9 @@ public class SessionConfig implements HttpSessionListener {
* @param snsType * @param snsType
* @param snsId * @param snsId
*/ */
public static void setLoginInfo(String sessionId, String snsType, String snsId) { public static void setLoginInfo(String sessionId, OAuthUniversalUser oUser) {
log.debug("setLoginInfo : " + sessionId + ", " + snsType + ", " + snsId); log.debug("setLoginInfo : " + sessionId + ", " + oUser.getSnsType() + ", " + oUser.getSnsId());
loginSessions.put(sessionId, StringUtil.getString(snsType, "NONE") + DELIMITER + StringUtil.getString(snsId, "NONE")); loginSessions.put(sessionId, oUser);
} }
/** /**
@ -87,16 +87,13 @@ public class SessionConfig implements HttpSessionListener {
* @param sessionId * @param sessionId
* @return * @return
*/ */
public static String[] getLoginInfo(String sessionId) { public static OAuthUniversalUser popLoginInfo(String sessionId) {
if(StringUtil.isEmpty(sessionId)) return null; if(StringUtil.isEmpty(sessionId)) return null;
String loginInfo = loginSessions.get(sessionId); OAuthUniversalUser ret = loginSessions.get(sessionId);
if(StringUtil.isEmpty(loginInfo)) return null;
String ret[] = loginInfo.split(DELIMITER); removeLoginInfo(sessionId);
log.debug("setLoginInfo : " + sessionId + ", " + ret[0] + ", " + ret[1]);
return ret; return ret;
} }
@ -134,9 +131,13 @@ public class SessionConfig implements HttpSessionListener {
* @param sessionId * @param sessionId
* @return * @return
*/ */
public static OAuthUniversalUser getNewMemberInfo(String sessionId) { public static OAuthUniversalUser popNewMemberInfo(String sessionId) {
if(StringUtil.isEmpty(sessionId)) return null; if(StringUtil.isEmpty(sessionId)) return null;
return memberSessions.get(sessionId);
OAuthUniversalUser ret = memberSessions.get(sessionId);
removeNewMemberInfo(sessionId);
return ret;
} }
/** /**

View File

@ -1,8 +1,14 @@
package nlib.cmm.web; package nlib.cmm.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
import org.springframework.security.web.savedrequest.RequestCache;
import org.springframework.security.web.savedrequest.SavedRequest;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -35,7 +41,15 @@ public class MainController {
private static final Logger log = LoggerFactory.getLogger(MainController.class); private static final Logger log = LoggerFactory.getLogger(MainController.class);
@RequestMapping( {"/index.do"} ) @RequestMapping( {"/index.do"} )
public String setContent(Authentication authentication, ModelMap model) { public String setContent(
HttpServletRequest req,
HttpServletResponse res,
Authentication authentication,
ModelMap model) {
// 캐쉬된 Reqeust 히스토리 삭제
RequestCache cache = new HttpSessionRequestCache();
cache.removeRequest(req, res);
log.debug((authentication == null ? "손님 메인 접속" : authentication.getName() + " 메인 접속")); log.debug((authentication == null ? "손님 메인 접속" : authentication.getName() + " 메인 접속"));
return "nlib/cmm/home"; return "nlib/cmm/home";

View File

@ -5,10 +5,7 @@ import java.util.HashMap;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.springframework.security.authentication.BadCredentialsException; import egovframework.com.ext.oauth.service.OAuthUniversalUser;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.authentication.LockedException;
import nlib.restful.service.DataApiReqVO; import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO; import nlib.restful.service.DataApiResVO;
@ -28,7 +25,7 @@ public interface LoginService
public String loginOauth(HttpServletRequest req, String oauthServiceName, String snsId, String joinCouncilCd, String councilJsessionId); public String loginOauth(HttpServletRequest req, String oauthServiceName, String snsId, String joinCouncilCd, String councilJsessionId);
public String loginCouncilSSO(HttpServletRequest req, String joinCouncilCd, String councilJsessionId); public String loginCouncilSSO(HttpServletRequest req, String councilCd, OAuthUniversalUser oUser);
public DataApiResVO logout(DataApiReqVO reqVO); public DataApiResVO logout(DataApiReqVO reqVO);

View File

@ -18,6 +18,7 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import egovframework.com.ext.oauth.service.OAuthUniversalUser;
import nlib.cmm.service.NlibProperty; import nlib.cmm.service.NlibProperty;
import nlib.cmm.session.SessionConfig; import nlib.cmm.session.SessionConfig;
import nlib.restful.service.DataApiReqVO; import nlib.restful.service.DataApiReqVO;
@ -89,7 +90,8 @@ public class LoginServiceImpl implements LoginService
} }
// 세션목록관리에 로그인 정상 가능 정보 추가 // 세션목록관리에 로그인 정상 가능 정보 추가
SessionConfig.setLoginInfo(councilJsessionId, oauthServiceName, snsId); // TODO
//SessionConfig.setLoginInfo(councilJsessionId, o);
// 회원가입정보 존재하는 SNS 아이디임을 확인 완료 // 회원가입정보 존재하는 SNS 아이디임을 확인 완료
return null; return null;
@ -102,25 +104,17 @@ public class LoginServiceImpl implements LoginService
* (non-Javadoc) * (non-Javadoc)
* @see nlib.user.service.LoginService#loginCouncilSSO(javax.servlet.http.HttpServletRequest, java.lang.String) * @see nlib.user.service.LoginService#loginCouncilSSO(javax.servlet.http.HttpServletRequest, java.lang.String)
*/ */
public String loginCouncilSSO(HttpServletRequest req, String joinCouncilCd, String councilJsessionId) { public String loginCouncilSSO(HttpServletRequest req, String councilCd, OAuthUniversalUser oUser) {
// 세션에서 로그인 처리 가능 정보 가져오기 if(oUser == null) return ERR_CODE_REQ_SNSLOGIN;
String loginInfo[] = SessionConfig.getLoginInfo(councilJsessionId);
if(loginInfo == null || loginInfo.length < 2) return ERR_CODE_REQ_SNSLOGIN;
String oauthServiceName = loginInfo[0]; if(!oUser.isValid()) return ERR_CODE_REQ_SNSLOGIN;
String snsId = loginInfo[1];
if(StringUtil.isEmpty(oauthServiceName)) // SNS 연동 사용자UID로 사용자정보 조회
return ERR_CODE_REQ_SNSLOGIN;
if(StringUtil.isEmpty(snsId))
return ERR_CODE_REQ_SNSLOGIN;
// 회원DB에서 사용자 정보 조회
NlibLoginVO nLoginParamVO = new NlibLoginVO(); NlibLoginVO nLoginParamVO = new NlibLoginVO();
nLoginParamVO.setSnsId(snsId); nLoginParamVO.setSnsId(oUser.getSnsId());
nLoginParamVO.setSnsType(oauthServiceName); nLoginParamVO.setSnsType(oUser.getSnsType());
nLoginParamVO.setJoinCouncilCd(joinCouncilCd); nLoginParamVO.setJoinCouncilCd(councilCd);
NlibLoginVO nLoginVO = loginDAO.selectLoginUserInfo(nLoginParamVO); NlibLoginVO nLoginVO = loginDAO.selectLoginUserInfo(nLoginParamVO);
if(nLoginVO == null) { if(nLoginVO == null) {
@ -139,7 +133,6 @@ public class LoginServiceImpl implements LoginService
loginDAO.insertLoginLog(nlibLoginedVO); loginDAO.insertLoginLog(nlibLoginedVO);
return null; return null;
} }
/** /**

View File

@ -26,7 +26,10 @@ login.url = /login/loginCouncil.do
# \ub85c\uadf8\uc778 \ubb38\uc81c \ubc1c\uc0dd \uc2dc, \ub2e4\uc2dc \ub9ac\ub2e4\uc774\ub809\ud2b8\ub420 \ub85c\uadf8\uc778\ud654\uba74 \uc8fc\uc18c # \ub85c\uadf8\uc778 \ubb38\uc81c \ubc1c\uc0dd \uc2dc, \ub2e4\uc2dc \ub9ac\ub2e4\uc774\ub809\ud2b8\ub420 \ub85c\uadf8\uc778\ud654\uba74 \uc8fc\uc18c
login.back.url = /login/loginForm.do login.back.url = /login/loginForm.do
# \uc9c0\ubc29\ubb38\ud654\uc6d0\uc5d0\uc11c \uc811\uc18d\uc2dc \ub9ac\ub2e4\uc774\ub809\ud2b8\ub420 URL \uc815\ubcf4 # \uc9c0\ubc29\ubb38\ud654\uc6d0\uc5d0\uc11c \uc811\uc18d\uc2dc \ub9ac\ub2e4\uc774\ub809\ud2b8\ub420 URL \uc815\ubcf4
nculture.login.redirect.url = http://nlib.nculture.org/nlib/login/loginForm.do nculture.login.redirect.uri = /login/loginForm.do
nculture.login.post.login.redirect.uri = /login/loginCouncilSSO.do
nculture.login.post.member.redirect.uri = /member/insertMemberInfoForm.do
nculture.login.preset.redirect.url = http://nlib.nculture.org/nlib/login/loginPreSet.do
#---------------------------------------- #----------------------------------------
# NLIB \uc9c0\ubc29\ubb38\ud654\uc6d0\uc815\ubcf4 # NLIB \uc9c0\ubc29\ubb38\ud654\uc6d0\uc815\ubcf4
@ -119,9 +122,6 @@ oauth2.client.provider.kakao.authorization-uri = https://kauth.kakao.com/oauth
oauth2.client.provider.kakao.token-uri = https://kauth.kakao.com/oauth/token?client_id= oauth2.client.provider.kakao.token-uri = https://kauth.kakao.com/oauth/token?client_id=
oauth2.client.provider.kakao.user-info-uri = https://kapi.kakao.com/v2/user/me oauth2.client.provider.kakao.user-info-uri = https://kapi.kakao.com/v2/user/me
# \ucf5c\ubc31 \uc8fc\uc18c (login,signUp)
oauth2.client.callback.login.url = https://nlib.nculture.org/nlib/login/{oauthServiceName}/callback.do
oauth2.client.callback.member.url = https://nlib.nculture.org/nlib/member/{oauthServiceName}/callback.do
#---------------------------------------- #----------------------------------------
# \uc190\ub2d8\uc815\ubcf4 # \uc190\ub2d8\uc815\ubcf4
#---------------------------------------- #----------------------------------------

View File

@ -7,7 +7,8 @@
<!-- HOME --> <!-- HOME -->
<% <%
String councilCd = (String)session.getAttribute("councilCd");
String councilNm = (String)session.getAttribute("councilCd");
%> %>
<sec:authorize access="isAuthenticated()"> <sec:authorize access="isAuthenticated()">
<dir id="title"><a href="javascript:void(0)" onclick="javascript:location.href='<%=session.getAttribute("councilHomeUrl") %>';">온라인자료대출관리 (<%=session.getAttribute("councilHomeUrl") %>)</a></dir> <dir id="title"><a href="javascript:void(0)" onclick="javascript:location.href='<%=session.getAttribute("councilHomeUrl") %>';">온라인자료대출관리 (<%=session.getAttribute("councilHomeUrl") %>)</a></dir>
@ -39,7 +40,7 @@
${userName}님 (${userId}) ${userName}님 (${userId})
</sec:authorize> </sec:authorize>
<sec:authorize access="not isAuthenticated()"> <sec:authorize access="not isAuthenticated()">
손님 손님 __${councilCd }---
</sec:authorize> </sec:authorize>
</li> </li>
</ul> </ul>