관리자 로그인 이력 수정
This commit is contained in:
@@ -65,17 +65,18 @@ public class AdminAuthSuccessEvent {
|
||||
"security.password.change.notify", adminUser.getRemainPasswordDays()));
|
||||
}
|
||||
|
||||
// 로그인 활성화 기록 생성
|
||||
// loggedInUserSavePortIn.connect(
|
||||
// LoggedInUserSaveCmd.builder()
|
||||
// .loggedInUserId(
|
||||
// LoggedInUserIdSaveCmd.builder()
|
||||
// .appType(AppType.ADMIN)
|
||||
// .id(authentication.getName())
|
||||
// .build())
|
||||
// .clientIP(CommonUtil.getClientIP(request))
|
||||
// .lastLoggedInAt(LocalDateTime.now())
|
||||
// .build());
|
||||
// 로그인 이력 쌓기
|
||||
loggedInUserSavePortIn.connect(
|
||||
LoggedInUserSaveCmd.builder()
|
||||
.loggedInUserId(
|
||||
LoggedInUserIdSaveCmd.builder()
|
||||
.appType(AppType.ADMIN)
|
||||
.id(authentication.getName())
|
||||
.build())
|
||||
.clientIP(CommonUtil.getClientIP(request))
|
||||
.lastLoggedInAt(LocalDateTime.now())
|
||||
.build());
|
||||
|
||||
}
|
||||
|
||||
@EventListener
|
||||
|
||||
@@ -46,6 +46,7 @@ public class AdminDetailsService implements UserDetailsService {
|
||||
adminUser.getPassword(),
|
||||
adminUser.getRoles().stream().map(CoreRole::getId).findFirst().orElse(null),
|
||||
adminUser.getRegionMainCode(),
|
||||
adminUser.getLastLoginIp(),
|
||||
!accountDisabled,
|
||||
true,
|
||||
isCredentialsNonExpired(adminUser.getPasswordUpdatedAt()),
|
||||
|
||||
@@ -10,6 +10,7 @@ public class AdminUser extends User {
|
||||
private Long seq;
|
||||
private String roleId;
|
||||
private String regionMainCode;
|
||||
private String lastLoginIp;
|
||||
private long remainPasswordDays;
|
||||
|
||||
public AdminUser(
|
||||
@@ -18,6 +19,7 @@ public class AdminUser extends User {
|
||||
String password,
|
||||
String roleId,
|
||||
String regionMainCode,
|
||||
String lastLoginIp,
|
||||
boolean enabled,
|
||||
boolean accountNonExpired,
|
||||
boolean credentialsNonExpired,
|
||||
@@ -35,6 +37,7 @@ public class AdminUser extends User {
|
||||
this.seq = seq;
|
||||
this.roleId = roleId;
|
||||
this.regionMainCode = regionMainCode;
|
||||
this.lastLoginIp = lastLoginIp;
|
||||
this.remainPasswordDays = remainPasswordDays;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,4 +53,14 @@ public class AdminUtil {
|
||||
AdminUser user = (AdminUser) authentication.getPrincipal();
|
||||
return user.getRegionMainCode().isEmpty() ? null : user.getRegionMainCode();
|
||||
}
|
||||
|
||||
public static String getLoginUserLastIp() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null || !(authentication.getPrincipal() instanceof AdminUser)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AdminUser user = (AdminUser) authentication.getPrincipal();
|
||||
return user.getLastLoginIp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,15 @@
|
||||
<insert id="insert" parameterType="app.module.core.config.adapters.persistence.entity.LoggedInUser">
|
||||
INSERT INTO logged_in_user
|
||||
(
|
||||
app_type,
|
||||
id,
|
||||
app_type,
|
||||
login_id,
|
||||
clientip,
|
||||
last_logged_in_at
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
nextval('logged_in_user_seq'),
|
||||
#{appType},
|
||||
#{id},
|
||||
#{clientIP},
|
||||
@@ -27,7 +29,7 @@
|
||||
clientip = #{clientIP},
|
||||
last_logged_in_at = #{lastLoggedInAt}
|
||||
WHERE app_type = #{appType}
|
||||
AND id = #{id}
|
||||
AND login_id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -133,7 +133,7 @@
|
||||
</ul>
|
||||
<div class="header-right">
|
||||
<p class="user"><strong sec:authentication="name">로그인 사용자명</strong>님 안녕하세요</p>
|
||||
<span class="user-ip">111.11.111.111</span>
|
||||
<span class="user-ip" th:text="${@adminUtil.getLoginUserLastIp}">111.11.111.111</span>
|
||||
<button class="btn-logout" onclick="location.href='/logout'">로그아웃</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -24,6 +24,7 @@ public class AdminView implements Serializable {
|
||||
private Boolean accountDisabled;
|
||||
private Integer loginFailCnt;
|
||||
private Boolean accountLocked;
|
||||
private String lastLoginIp;
|
||||
private LocalDateTime createdAt;
|
||||
private String createdBy;
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@@ -18,12 +18,17 @@
|
||||
a.account_disabled,
|
||||
a.login_fail_cnt,
|
||||
a.account_locked,
|
||||
liu.clientip as last_login_ip,
|
||||
a.created_at,
|
||||
a.created_by,
|
||||
a.updated_at,
|
||||
a.updated_by
|
||||
FROM admin a
|
||||
WHERE id = #{id}
|
||||
LEFT JOIN ( SELECT clientip,login_id
|
||||
FROM logged_in_user liu
|
||||
ORDER BY last_logged_in_at desc
|
||||
LIMIT 1 ) liu on liu.login_id = a.id
|
||||
WHERE a.id = #{id}
|
||||
AND a.is_deleted = false
|
||||
</select>
|
||||
|
||||
|
||||
@@ -831,23 +831,26 @@ COMMENT ON COLUMN operation_log.is_deleted IS '삭제여부';
|
||||
|
||||
-- ============================================
|
||||
-- TABLE : logged_in_user
|
||||
-- DESC : 로그인 사용자 정보 테이블
|
||||
-- DESC : 로그인 사용자 이력 테이블
|
||||
-- ============================================
|
||||
CREATE SEQUENCE logged_in_user_seq START WITH 1 INCREMENT BY 1 CACHE 1 NO CYCLE;
|
||||
CREATE TABLE logged_in_user (
|
||||
id bigint DEFAULT nextval('logged_in_user_seq') NOT NULL, -- 로그 ID (PK)
|
||||
app_type varchar(255) NOT NULL, -- 앱 타입 (FRONT / ADMIN)
|
||||
id varchar(255) NOT NULL, -- 로그인 아이디
|
||||
login_id varchar(255) NOT NULL, -- 로그인 아이디
|
||||
last_logged_in_at timestamp(6), -- 마지막 로그인 날짜
|
||||
clientip varchar(255), -- 접속 아이피
|
||||
|
||||
CONSTRAINT logged_in_user_pkey PRIMARY KEY (app_type, id),
|
||||
CONSTRAINT logged_in_user_pkey PRIMARY KEY (id),
|
||||
CONSTRAINT logged_in_user_app_type_check
|
||||
CHECK (app_type::text = ANY (ARRAY['FRONT', 'ADMIN']))
|
||||
);
|
||||
|
||||
COMMENT ON TABLE logged_in_user IS '로그인사용자정보테이블';
|
||||
COMMENT ON TABLE logged_in_user IS '로그인사용자이력테이블';
|
||||
|
||||
COMMENT ON COLUMN logged_in_user.id IS '로그 ID';
|
||||
COMMENT ON COLUMN logged_in_user.app_type IS '앱 타입';
|
||||
COMMENT ON COLUMN logged_in_user.id IS '로그인 아이디';
|
||||
COMMENT ON COLUMN logged_in_user.login_id IS '로그인 아이디';
|
||||
COMMENT ON COLUMN logged_in_user.last_logged_in_at IS '마지막 로그인 날짜';
|
||||
COMMENT ON COLUMN logged_in_user.clientip IS '접속 아이피';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user