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