login 수정(1)

This commit is contained in:
김현욱
2025-11-25 15:51:25 +09:00
parent 2903f1c6e6
commit 2a5c9b03c3
11 changed files with 288 additions and 101 deletions

View File

@@ -35,36 +35,65 @@ public class MngrAuthInterceptor implements HandlerInterceptor{
return true;
}
AnonymousUser user = MemberJwtContextHolder.getMemberInfo();
AuthVO authVO = new AuthVO();
//쿠키 쇼핑몰 코드 조회
String cookieAuthSopmalCd = CookieUtils.getCookieValue("authSopmalCd", request);
logger.debug("cookieAuthSopmalCd param1 :: {}", cookieAuthSopmalCd);
if(!"".equals(cookieAuthSopmalCd) && cookieAuthSopmalCd != null){
authVO.setSopmalCd(cookieAuthSopmalCd);
}
//관리자 권한 조회
boolean authChk = mngrAuthChk(request, response, user, authVO);
//쿠키 쇼핑몰 코드 없을 경우 쿠키 생성 및 쇼핑몰코드 변수저장
if (!StringUtils.hasText(cookieAuthSopmalCd)) {
//통합관리자인경우
if ("ADMIN".equals(RealmContextHolder.getSopmalCdRealm())) {
logger.debug("SopmalCdRealm ADMIN!");
CookieUtils.createCookie("authSopmalCd", "SYS", "/", true, request, response);
cookieAuthSopmalCd = "SYS";
} else {
/*쿠키에 authSopmalCd가 없으면 초기화*/
if(StringUtil.isEmpty(cookieAuthSopmalCd)){
CookieUtils.createCookie("authSopmalCd", RealmContextHolder.getSopmalCdRealm(), "/", true, request, response);
cookieAuthSopmalCd = RealmContextHolder.getSopmalCdRealm();
}
}
/*쿠키에 authSopmalCd가 없으면 초기화*/
if(StringUtil.isEmpty(cookieAuthSopmalCd)){
logger.debug("cookieAuthSopmalCd isEmpty");
// CookieUtils.createCookie("authSopmalCd", RealmContextHolder.getSopmalCdRealm(), "/", true, request, response);
// cookieAuthSopmalCd = RealmContextHolder.getSopmalCdRealm();
CookieUtils.createCookie("authSopmalCd", authVO.getSopmalCd(), "/", true, request, response);
cookieAuthSopmalCd = authVO.getSopmalCd();
}
} else {
if(!cookieAuthSopmalCd.equals(authVO.getSopmalCd())) {
logger.debug("cookieAuthSopmalCd is Diff.");
CookieUtils.createCookie("authSopmalCd", authVO.getSopmalCd(), "/", true, request, response);
cookieAuthSopmalCd = authVO.getSopmalCd();
}
}
AnonymousUser user = MemberJwtContextHolder.getMemberInfo();
logger.debug("cookieAuthSopmalCd param2 :: {}", cookieAuthSopmalCd);
// AnonymousUser user = MemberJwtContextHolder.getMemberInfo();
//
//
// //관리자 권한 조회
// boolean authChk = mngrAuthChk(request, response, user);
//관리자 권한 조회
boolean authChk = mngrAuthChk(request, response, user);
// CookieUtils.createCookie("authSopmalCd", authSopmalCd, "/", true, request, response);
// cookieAuthSopmalCd = CookieUtils.getCookieValue("authSopmalCd", request);
//해당 페이지에 접근권한이 없으면 alert
boolean result = false;
if (authChk) {
AuthVO authVO = new AuthVO();
// AuthVO authVO = new AuthVO();
authVO.setMngrInnb(user.getUserInnb());
authVO.setSopmalCd(cookieAuthSopmalCd);
authVO.setSysDvCd(user.getSysDvCd());
@@ -101,9 +130,9 @@ public class MngrAuthInterceptor implements HandlerInterceptor{
* @param response res
* @param user 유저정보
*/
private boolean mngrAuthChk (HttpServletRequest request, HttpServletResponse response, AnonymousUser user){
private boolean mngrAuthChk (HttpServletRequest request, HttpServletResponse response, AnonymousUser user, AuthVO authVO){
//권한 리스트 조회
AuthVO authVO = new AuthVO();
// AuthVO authVO = new AuthVO();
authVO.setMngrInnb(user.getUserInnb());
List<String> sopmalList = authService.selectAuthorSopmalList(authVO);
logger.debug("sopmalList {}", sopmalList);
@@ -118,15 +147,22 @@ public class MngrAuthInterceptor implements HandlerInterceptor{
authSopmalCd = queryString;
} else {
//쿠키에 권한 리스트중 첫번째 쇼핑몰 param 저장
if (!sopmalList.isEmpty()) {
authSopmalCd = sopmalList.get(0);
if("".equals(authVO.getSopmalCd()) || authVO.getSopmalCd() == null){
//쿠키에 권한 리스트중 첫번째 쇼핑몰 param 저장
if (!sopmalList.isEmpty()) {
authSopmalCd = sopmalList.get(0);
} else {
return false;
}
} else {
return false;
authSopmalCd = authVO.getSopmalCd();
}
}
logger.debug("authSopmalCd set :: {}", authSopmalCd);
authVO.setSopmalCd(authSopmalCd);
CookieUtils.createCookie("authSopmalCd", authSopmalCd, "/", true, request, response);
return true;

View File

@@ -6,6 +6,7 @@ import com.wb.domainserver.interceptor.wrapper.MultipleReadableRequestWrapper;
import com.wb.domainserver.realm.util.UrlExtractor;
import com.wb.domainserver.security.authentication.AnonymousUser;
import com.wb.domainserver.security.authentication.MemberJwtContextHolder;
import com.wb.domainserver.util.CookieUtils;
import com.wb.domainserver.util.string.StringUtil;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
@@ -214,25 +215,30 @@ public class MngrLoggingInterceptor implements HandlerInterceptor {
logVo.setMngrTyCd(mngrTy);
logVo.setMngrInnb(user.getUserInnb());
logger.debug("request.getRequestURI :: {}", request.getRequestURI());
String authSopmalCd = "";
//관리자 메인 진입시 쇼핑몰 선택했을 경우(로그인시)
if( "/mngr/main".equals(request.getRequestURI()) && !StringUtil.isEmpty(request.getParameter("authSopmalCd"))){
if( ("/mngr/login/loginCheck".equals(request.getRequestURI()) || "/mngr/main".equals(request.getRequestURI())) && !StringUtil.isEmpty(request.getParameter("authSopmalCd"))){
authSopmalCd = request.getParameter("authSopmalCd");
}
//이후 사이트 이동시
if(request.getCookies() != null){
for(Cookie cookie : request.getCookies()){
if(cookie.getName().equals("authSopmalCd")){
authSopmalCd = cookie.getValue();
break;
logger.debug("request.getParamete authSopmalCd :: {}", authSopmalCd);
CookieUtils.createCookie("authSopmalCd", authSopmalCd, "/", true, request, response);
} else {
//이후 사이트 이동시
if(request.getCookies() != null){
for(Cookie cookie : request.getCookies()){
if(cookie.getName().equals("authSopmalCd")){
authSopmalCd = cookie.getValue();
logger.debug("cookie.getValue authSopmalCd :: {}", authSopmalCd);
break;
}
}
}
}
logger.debug("insertMngrAccessLog setSopmalCd :: {}", authSopmalCd);
logVo.setSopmalCd(authSopmalCd);

View File

@@ -4,6 +4,8 @@ import com.wb.domainserver.domain.admin.sys.author.service.BOMaAuthorService;
import com.wb.domainserver.domain.admin.sys.author.vo.BOMaAuthorVO;
import com.wb.domainserver.domain.admin.sys.menu.service.BOMaMenuService;
import com.wb.domainserver.domain.admin.sys.menu.vo.BOMaMenuVO;
import com.wb.domainserver.domain.auth.service.AuthService;
import com.wb.domainserver.domain.auth.vo.AuthVO;
import com.wb.domainserver.domain.gcone.mbr.mbr.service.BOMbrService;
import com.wb.domainserver.domain.gcone.mbr.mbr.vo.BOMbrVO;
import com.wb.domainserver.realm.RealmContextHolder;
@@ -24,6 +26,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MngrMenuInterceptor implements HandlerInterceptor {
@@ -33,6 +36,9 @@ public class MngrMenuInterceptor implements HandlerInterceptor {
@Autowired
private BOMaMenuService menuService;
@Autowired
private AuthService authService;
@Autowired
private BOMaAuthorService boMaAuthorService;
@@ -129,23 +135,53 @@ public class MngrMenuInterceptor implements HandlerInterceptor {
//관리자 메인 진입시 쇼핑몰 선택했을 경우(로그인시)
if( "/mngr/main".equals(request.getRequestURI()) && !StringUtil.isEmpty(request.getParameter("authSopmalCd"))){
cookieAuthSopmalCd = request.getParameter("authSopmalCd");
}
logger.debug("cookieAuthSopmalCd param3 :: {}", cookieAuthSopmalCd);
} else {
if (request.getCookies() != null) {
if (request.getCookies() != null) {
Cookie[] cookies = request.getCookies();
Cookie[] cookies = request.getCookies();
for(Cookie cookie : cookies) {
if("authSopmalCd".equals(cookie.getName())){
cookieAuthSopmalCd = cookie.getValue();
break;
for(Cookie cookie : cookies) {
if("authSopmalCd".equals(cookie.getName())){
cookieAuthSopmalCd = cookie.getValue();
break;
}
}
}
logger.debug("cookieAuthSopmalCd param4 :: {}", cookieAuthSopmalCd);
}
if(!StringUtils.hasText(cookieAuthSopmalCd)){
cookieAuthSopmalCd = RealmContextHolder.getSopmalCdRealm();
// cookieAuthSopmalCd = RealmContextHolder.getSopmalCdRealm();
AuthVO authVO = new AuthVO();
authVO.setMngrInnb(mngr.getUserInnb());
List<String> sopmalList = authService.selectAuthorSopmalList(authVO);
logger.debug("sopmalList_menu {}", sopmalList);
//로그인 요청 쇼핑몰 param 조회
String queryString = request.getParameter("authSopmalCd");
logger.debug("authSopmalCd queryString :: {}", queryString);
//권한 리스트에 로그인 요청 쇼핑몰 param이 포함되면
String authSopmalCd = "";
if (!StringUtil.isEmpty(queryString) && sopmalList.contains(queryString)) {
// 로그인 요청 쇼핑몰 param 저장
authSopmalCd = queryString;
} else {
//쿠키에 권한 리스트중 첫번째 쇼핑몰 param 저장
if (!sopmalList.isEmpty()) {
authSopmalCd = sopmalList.get(0);
} else {
authSopmalCd = RealmContextHolder.getSopmalCdRealm();
}
}
cookieAuthSopmalCd = authSopmalCd;
request.setAttribute("authSopmalCd", authSopmalCd);
}
logger.debug("cookieAuthSopmalCd param5 :: {}", cookieAuthSopmalCd);
vo.setSopmalCd(cookieAuthSopmalCd);