File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
package kr.itn.itnhub.config;
import org.springframework.stereotype.Component;
import java.security.Principal;
/**
* 기록에 남길 "작성자 이름"을 한 곳에서 정한다(요구사항 [22]).
*
* <p>예전에는 각 컨트롤러가 {@code principal.getName()}을 그대로 써서 업무메모·연락이력·
* 보고서에 로그인 아이디(admin)가 찍혔다. 지금은 설정에 넣어둔 표시 이름을 쓴다.</p>
*
* <p>나중에 담당자별 계정이 생기면 여기만 고쳐서 각자의 이름이 찍히게 하면 된다.</p>
*/
@Component
public class CurrentUser {
private final AdminProperties admin;
public CurrentUser(AdminProperties admin) {
this.admin = admin;
}
/** 기록에 남길 이름. 로그인한 사람이 관리자면 설정된 표시 이름을 쓴다. */
public String displayName(Principal principal) {
if (principal == null) {
return admin.displayNameOrUsername();
}
if (principal.getName().equals(admin.username())) {
return admin.displayNameOrUsername();
}
// 관리자 외 계정이 생기면 그 계정의 아이디를 그대로 쓴다.
return principal.getName();
}
}