로그인로그 생성 작업중.
parent
71e513dd68
commit
4b9d5a065f
|
|
@ -67,7 +67,7 @@ function UserInfoModal({savedInfo, reloadFunction}){
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(resp) => {
|
(resp) => {
|
||||||
debugger
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.dbnt.kcscbackend.admin.logs.entity;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.hibernate.annotations.DynamicInsert;
|
||||||
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@Entity
|
||||||
|
@NoArgsConstructor
|
||||||
|
@DynamicInsert
|
||||||
|
@DynamicUpdate
|
||||||
|
@Table(name = "th_login_log")
|
||||||
|
public class ThLoginLog {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "ll_seq")
|
||||||
|
private Long llSeq;
|
||||||
|
|
||||||
|
@Column(name = "user_id")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
@Column(name = "access_dt")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime accessDt;
|
||||||
|
|
||||||
|
@Column(name = "ip_address")
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
|
@Column(name = "session_id")
|
||||||
|
private String sessionId;
|
||||||
|
|
||||||
|
@Column(name = "access_type")
|
||||||
|
private String accessType;
|
||||||
|
}
|
||||||
|
|
@ -10,7 +10,6 @@ import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|
@ -22,13 +21,20 @@ import java.awt.*;
|
||||||
@Table(name = "tn_daily_user_log")
|
@Table(name = "tn_daily_user_log")
|
||||||
public class TnDailyUserConnLog {
|
public class TnDailyUserConnLog {
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "dul_seq")
|
@Column(name = "dul_seq")
|
||||||
private Long dulSeq;
|
private Long dulSeq;
|
||||||
|
|
||||||
@Column(name = "log_cnt")
|
|
||||||
private Long logCnt;
|
|
||||||
|
|
||||||
@Column(name = "log_dt")
|
@Column(name = "log_dt")
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private LocalDate logDt;
|
private LocalDate logDt;
|
||||||
|
|
||||||
|
@Column(name = "log_cnt")
|
||||||
|
private Long logCnt;
|
||||||
|
|
||||||
|
@Column(name = "mobile_cnt")
|
||||||
|
private Long mobileCnt;
|
||||||
|
|
||||||
|
@Column(name = "pc_cnt")
|
||||||
|
private Long pcCnt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PrivacyLogsRepository extends JpaRepository<ThPrivacyLog, String> {
|
public interface PrivacyLogsRepository extends JpaRepository<ThPrivacyLog, Long> {
|
||||||
List<ThPrivacyLog> findAllByOrderByUplSeqDesc();
|
List<ThPrivacyLog> findAllByOrderByUplSeqDesc();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.dbnt.kcscbackend.admin.logs.repository;
|
||||||
|
|
||||||
|
import com.dbnt.kcscbackend.admin.logs.entity.ThLoginLog;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ThLoginLogRepository extends JpaRepository<ThLoginLog, Long> {
|
||||||
|
|
||||||
|
List<ThLoginLog> findByUserIdAndAccessDtAfter(String userId, LocalDateTime accessDt);
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,9 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface UserLogsRepository extends JpaRepository<TnDailyUserConnLog, Long> {
|
public interface UserLogsRepository extends JpaRepository<TnDailyUserConnLog, Long> {
|
||||||
|
|
||||||
|
|
@ -21,5 +23,5 @@ public interface UserLogsRepository extends JpaRepository<TnDailyUserConnLog, Lo
|
||||||
+ "ORDER BY log_dt asc", nativeQuery = true)
|
+ "ORDER BY log_dt asc", nativeQuery = true)
|
||||||
List<Object[]> selectCountUser(@Param("startDate") String startDate, @Param("endDate") String endDate);
|
List<Object[]> selectCountUser(@Param("startDate") String startDate, @Param("endDate") String endDate);
|
||||||
|
|
||||||
|
Optional<TnDailyUserConnLog> findByLogDt(LocalDate logDt);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
package com.dbnt.kcscbackend.admin.logs.service;
|
package com.dbnt.kcscbackend.admin.logs.service;
|
||||||
|
|
||||||
|
import com.dbnt.kcscbackend.admin.logs.entity.ThLoginLog;
|
||||||
import com.dbnt.kcscbackend.admin.logs.entity.ThPrivacyLog;
|
import com.dbnt.kcscbackend.admin.logs.entity.ThPrivacyLog;
|
||||||
|
import com.dbnt.kcscbackend.admin.logs.entity.TnDailyUserConnLog;
|
||||||
import com.dbnt.kcscbackend.admin.logs.repository.PrivacyLogsRepository;
|
import com.dbnt.kcscbackend.admin.logs.repository.PrivacyLogsRepository;
|
||||||
|
import com.dbnt.kcscbackend.admin.logs.repository.ThLoginLogRepository;
|
||||||
|
import com.dbnt.kcscbackend.admin.logs.repository.UserLogsRepository;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
|
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -17,6 +22,8 @@ import java.util.Map;
|
||||||
public class AdminLogsService extends EgovAbstractServiceImpl {
|
public class AdminLogsService extends EgovAbstractServiceImpl {
|
||||||
|
|
||||||
private final PrivacyLogsRepository privacyLogsRepository;
|
private final PrivacyLogsRepository privacyLogsRepository;
|
||||||
|
private final ThLoginLogRepository loginLogRepository;
|
||||||
|
private final UserLogsRepository userLogsRepository;
|
||||||
|
|
||||||
public Map<String, Object> selectPrivacyList() {
|
public Map<String, Object> selectPrivacyList() {
|
||||||
Map<String, Object> resultMap = new HashMap<>();
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
|
|
@ -46,4 +53,44 @@ public class AdminLogsService extends EgovAbstractServiceImpl {
|
||||||
log.setTargetUserId(targetUserId);
|
log.setTargetUserId(targetUserId);
|
||||||
privacyLogsRepository.save(log);
|
privacyLogsRepository.save(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void insertLoginLog(String userId, String ipAddress, String accessToken, String accessType, String webType){
|
||||||
|
ThLoginLog loginLog = new ThLoginLog();
|
||||||
|
loginLog.setUserId(userId);
|
||||||
|
loginLog.setIpAddress(ipAddress);
|
||||||
|
loginLog.setSessionId(accessToken);
|
||||||
|
loginLog.setAccessType(accessType);
|
||||||
|
loginLog.setAccessDt(LocalDateTime.now());
|
||||||
|
loginLogRepository.save(loginLog);
|
||||||
|
|
||||||
|
// 로그인 기록이면 tn_daily_yser_log 카운트 조정
|
||||||
|
if(accessType.equals("Y")){
|
||||||
|
//오늘 일자 로그 조회
|
||||||
|
TnDailyUserConnLog userConnLog = userLogsRepository.findByLogDt(LocalDate.now()).orElse(null);
|
||||||
|
if(userConnLog==null){
|
||||||
|
userConnLog = new TnDailyUserConnLog();
|
||||||
|
userConnLog.setLogDt(LocalDate.now());
|
||||||
|
userConnLog.setLogCnt(0L);
|
||||||
|
userConnLog.setMobileCnt(0L);
|
||||||
|
userConnLog.setPcCnt(0L);
|
||||||
|
}
|
||||||
|
if(webType.equals("PC")){
|
||||||
|
userConnLog.setPcCnt(userConnLog.getPcCnt()+1);
|
||||||
|
}else{
|
||||||
|
userConnLog.setMobileCnt(userConnLog.getMobileCnt()+1);
|
||||||
|
}
|
||||||
|
//같은 일자 로그인 기록 확인
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
now = now.minusHours(now.getHour());
|
||||||
|
now = now.minusMinutes(now.getMinute());
|
||||||
|
now = now.minusSeconds(now.getSecond());
|
||||||
|
List<ThLoginLog> todayLoginLog = loginLogRepository.findByUserIdAndAccessDtAfter(userId, now);
|
||||||
|
if(todayLoginLog.size()==0){
|
||||||
|
userConnLog.setLogCnt(userConnLog.getLogCnt()+1);
|
||||||
|
}
|
||||||
|
userLogsRepository.save(userConnLog);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dbnt.kcscbackend.config.security;
|
package com.dbnt.kcscbackend.config.security;
|
||||||
|
|
||||||
|
import com.dbnt.kcscbackend.admin.logs.service.AdminLogsService;
|
||||||
import com.dbnt.kcscbackend.auth.entity.UserInfo;
|
import com.dbnt.kcscbackend.auth.entity.UserInfo;
|
||||||
import com.dbnt.kcscbackend.config.common.ResponseCode;
|
import com.dbnt.kcscbackend.config.common.ResponseCode;
|
||||||
import com.dbnt.kcscbackend.config.egov.EgovProperties;
|
import com.dbnt.kcscbackend.config.egov.EgovProperties;
|
||||||
|
|
@ -31,6 +32,7 @@ import java.util.List;
|
||||||
public class CustomUrlAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
|
public class CustomUrlAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
|
||||||
|
|
||||||
private final EgovJwtTokenUtil jwtTokenUtil;
|
private final EgovJwtTokenUtil jwtTokenUtil;
|
||||||
|
private final AdminLogsService adminLogsService;
|
||||||
private RequestCache requestCache = new HttpSessionRequestCache();
|
private RequestCache requestCache = new HttpSessionRequestCache();
|
||||||
|
|
||||||
private static final List<String> adminIpList = Arrays.asList(EgovProperties.getProperty("Globals.admin.allow-ip").split(","));
|
private static final List<String> adminIpList = Arrays.asList(EgovProperties.getProperty("Globals.admin.allow-ip").split(","));
|
||||||
|
|
@ -53,12 +55,14 @@ public class CustomUrlAuthenticationSuccessHandler extends SimpleUrlAuthenticati
|
||||||
securityUser = (UserInfo) principal;
|
securityUser = (UserInfo) principal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String accessIp = ClientUtils.getRemoteIP(request);
|
||||||
|
|
||||||
// application/json(ajax) 요청일 경우 아래의 처리!
|
// application/json(ajax) 요청일 경우 아래의 처리!
|
||||||
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
|
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
|
||||||
MediaType jsonMimeType = MediaType.APPLICATION_JSON;
|
MediaType jsonMimeType = MediaType.APPLICATION_JSON;
|
||||||
HashMap<String, Object> resultMap = new HashMap<>();
|
HashMap<String, Object> resultMap = new HashMap<>();
|
||||||
|
|
||||||
/*if(securityUser.getUserId().equals("admin") && !adminIpList.contains(ClientUtils.getRemoteIP(request))){
|
/*if(securityUser.getUserId().equals("admin") && !adminIpList.contains(accessIp)){
|
||||||
resultMap.put("resultCode", ResponseCode.FAILED.getCode());
|
resultMap.put("resultCode", ResponseCode.FAILED.getCode());
|
||||||
resultMap.put("resultMessage", "관리자 계정은 지정된 아이피에서만 접속할 수 있습니다.\n필요한 경우 관리자에게 요청하십시오.\n접속자 아이피: "+ClientUtils.getRemoteIP(request));
|
resultMap.put("resultMessage", "관리자 계정은 지정된 아이피에서만 접속할 수 있습니다.\n필요한 경우 관리자에게 요청하십시오.\n접속자 아이피: "+ClientUtils.getRemoteIP(request));
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -78,6 +82,9 @@ public class CustomUrlAuthenticationSuccessHandler extends SimpleUrlAuthenticati
|
||||||
resultMap.put("accessToken", accessToken);
|
resultMap.put("accessToken", accessToken);
|
||||||
resultMap.put("refreshToken", refreshToken);
|
resultMap.put("refreshToken", refreshToken);
|
||||||
|
|
||||||
|
//로그인 로그 기록
|
||||||
|
adminLogsService.insertLoginLog(securityUser.getUserId(), accessIp, accessToken, "Y", ClientUtils.getWebType(request));
|
||||||
|
|
||||||
if (jsonConverter.canWrite(resultMap.getClass(), jsonMimeType)) {
|
if (jsonConverter.canWrite(resultMap.getClass(), jsonMimeType)) {
|
||||||
jsonConverter.write(resultMap, jsonMimeType, new ServletServerHttpResponse(response));
|
jsonConverter.write(resultMap, jsonMimeType, new ServletServerHttpResponse(response));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dbnt.kcscbackend.config.security;
|
package com.dbnt.kcscbackend.config.security;
|
||||||
|
|
||||||
|
import com.dbnt.kcscbackend.admin.logs.service.AdminLogsService;
|
||||||
import com.dbnt.kcscbackend.config.jwt.EgovJwtTokenUtil;
|
import com.dbnt.kcscbackend.config.jwt.EgovJwtTokenUtil;
|
||||||
import com.dbnt.kcscbackend.config.jwt.JwtAuthenticationEntryPoint;
|
import com.dbnt.kcscbackend.config.jwt.JwtAuthenticationEntryPoint;
|
||||||
import com.dbnt.kcscbackend.config.jwt.JwtAuthenticationFilter;
|
import com.dbnt.kcscbackend.config.jwt.JwtAuthenticationFilter;
|
||||||
|
|
@ -49,6 +50,7 @@ public class SecurityConfig {
|
||||||
private UserDetailsService loginService;
|
private UserDetailsService loginService;
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
private final EgovJwtTokenUtil egovJwtTokenUtil;
|
private final EgovJwtTokenUtil egovJwtTokenUtil;
|
||||||
|
private final AdminLogsService adminLogsService;
|
||||||
|
|
||||||
//Http Methpd : Get 인증예외 List
|
//Http Methpd : Get 인증예외 List
|
||||||
private String[] AUTH_GET_WHITELIST = {
|
private String[] AUTH_GET_WHITELIST = {
|
||||||
|
|
@ -145,7 +147,7 @@ public class SecurityConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JsonAuthenticationFilter jsonUsernamePasswordAuthenticationFilter() {
|
public JsonAuthenticationFilter jsonUsernamePasswordAuthenticationFilter() {
|
||||||
JsonAuthenticationFilter jsonAuthenticationFilter = new JsonAuthenticationFilter(objectMapper, new CustomUrlAuthenticationSuccessHandler(egovJwtTokenUtil), loginFailureHandler());
|
JsonAuthenticationFilter jsonAuthenticationFilter = new JsonAuthenticationFilter(objectMapper, new CustomUrlAuthenticationSuccessHandler(egovJwtTokenUtil, adminLogsService), loginFailureHandler());
|
||||||
jsonAuthenticationFilter.setAuthenticationManager(authenticationManager());
|
jsonAuthenticationFilter.setAuthenticationManager(authenticationManager());
|
||||||
return jsonAuthenticationFilter;
|
return jsonAuthenticationFilter;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,20 @@ public class ClientUtils {
|
||||||
|
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getWebType(HttpServletRequest request) {
|
||||||
|
String filter = "iphone|ipod|android|windows ce|blackberry|symbian|windows phone|webos|opera mini|opera mobi|polaris|iemobile|lgtelecom|nokia|sonyericsson|lg|samsung";
|
||||||
|
String filters[] = filter.split("\\|");
|
||||||
|
String webType = "";
|
||||||
|
|
||||||
|
for(String tmp : filters){
|
||||||
|
if (request.getHeader("User-Agent").toLowerCase().contains(tmp)) {
|
||||||
|
webType = "MOBILE";
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
webType = "PC";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return webType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue