|
@@ -0,0 +1,100 @@
|
|
|
+package com.its.web.security;
|
|
|
+
|
|
|
+import com.its.web.dto.admin.TbWwwMemberDto;
|
|
|
+import com.its.web.mapper.its.admin.AdminMapper;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.security.core.Authentication;
|
|
|
+import org.springframework.security.core.GrantedAuthority;
|
|
|
+import org.springframework.security.web.WebAttributes;
|
|
|
+import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
|
|
+import org.springframework.security.web.authentication.WebAuthenticationDetails;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.ServletException;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@AllArgsConstructor
|
|
|
+@Service
|
|
|
+public class WebLoginSuccessHandler implements AuthenticationSuccessHandler {
|
|
|
+
|
|
|
+// private final TbUserCnncHsRepository cnncHsRepo;
|
|
|
+ private final AdminMapper mapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
|
|
|
+
|
|
|
+// String currSysTime = ItsUtils.getSysTime();
|
|
|
+ // IP, 세션 ID
|
|
|
+ WebAuthenticationDetails details = (WebAuthenticationDetails)authentication.getDetails();
|
|
|
+
|
|
|
+ // 인증 ID
|
|
|
+ String userId = authentication.getName();
|
|
|
+ log.info("login Remote-IP/Session-ID/User-ID: {}/{}/{}", details.getRemoteAddress(), details.getSessionId(), userId);
|
|
|
+
|
|
|
+ // 권한 리스트
|
|
|
+ List<GrantedAuthority> authList = new ArrayList<>(authentication.getAuthorities());
|
|
|
+ for (GrantedAuthority auth : authList) {
|
|
|
+ log.info("login Roll: {}", auth.getAuthority());
|
|
|
+ }
|
|
|
+
|
|
|
+ TbWwwMemberDto userInfr = (TbWwwMemberDto)authentication.getPrincipal();
|
|
|
+// String remoteIp = ItsUtils.getHttpServletRemoteIP(request);
|
|
|
+// TbUserCnncHs cnncHs = TbUserCnncHs.builder()
|
|
|
+// .operSystId(userInfr.getOperSystId())
|
|
|
+// .userId(userInfr.getUserId())
|
|
|
+// .loginHms(ItsUtils.getSysTime())
|
|
|
+// .logoutHms("")
|
|
|
+// .build();
|
|
|
+// this.cnncHsRepo.insertData(cnncHs.getOperSystId(), cnncHs.getLoginHms(), cnncHs.getUserId(), cnncHs.getLogoutHms());
|
|
|
+// log.info("Login History: {}, {}", cnncHs, remoteIp);
|
|
|
+//
|
|
|
+// userInfr.setLoginHms(cnncHs.getLoginHms());
|
|
|
+// userInfr.setLogoutHms("");
|
|
|
+//
|
|
|
+// String uri = WebConstants.DEFAULT_URI;
|
|
|
+// String domain = "/";
|
|
|
+//
|
|
|
+// HttpSession session = request.getSession(false); // 세션을 생성 하지 않음
|
|
|
+// if (session != null) {
|
|
|
+// log.info("Session[{}}] [{}], Login Authentication: User: {}, {}, {}, Login History: {}, {}",
|
|
|
+// session.getId(), currSysTime, userInfr.getUserId(), userInfr.getOperSystId(), userInfr.getLoginHms(), remoteIp, cnncHs.getLoginHms());
|
|
|
+// } else {
|
|
|
+// session = request.getSession(true); // 새로운 세션을 생성
|
|
|
+// session.setMaxInactiveInterval(WebConstants.MAX_INACTIVE_SESSION_TIMEOUT);
|
|
|
+// log.info("Session[{}] [{}], Login Authentication, Session Create: User: {}, {}, {}, {}, Login History: {}, {}",
|
|
|
+// session.getId(), currSysTime, userInfr.getUserId(), userInfr.getOperSystId(), userInfr.getLoginHms(), session.getMaxInactiveInterval(), remoteIp, cnncHs.getLoginHms());
|
|
|
+// }
|
|
|
+// session.setAttribute(WebConstants.USER_UUID, WebMvcConfig.encUserId(cnncHs.getUserId()));
|
|
|
+// session.setAttribute(WebConstants.USER_TIME, cnncHs.getLoginHms());
|
|
|
+// session.setAttribute(WebConstants.LOGIN_USER, userInfr);
|
|
|
+//
|
|
|
+// CookieUtils.setCookie(response, WebConstants.USER_UUID, WebMvcConfig.encUserId(cnncHs.getUserId()), 60*60, domain);
|
|
|
+// CookieUtils.setCookie(response, WebConstants.USER_TIME, cnncHs.getLoginHms(), 60*60, domain);
|
|
|
+// CookieUtils.setCookie(response, WebConstants.USER_OPER_SYST_ID, userInfr.getOperSystId(), 60*60, domain);
|
|
|
+
|
|
|
+// clearAuthenticationAttributes(request);
|
|
|
+// response.sendRedirect(uri);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 로그인 성공시 로그인 실패 시 작성한 에러 세션 지우기
|
|
|
+ * @param request
|
|
|
+ */
|
|
|
+ protected void clearAuthenticationAttributes(HttpServletRequest request) {
|
|
|
+ HttpSession session = request.getSession(false);
|
|
|
+ //log.error("clearAuthenticationAttributes: {}", session);
|
|
|
+ if (session == null) {
|
|
|
+ log.warn("session already cleared.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
|
|
|
+ }
|
|
|
+}
|