728x90
반응형
1. UserDetails 에 추가 정보 저장
public class CustomUserDetails implements UserDetails {
Account user;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
ArrayList<GrantedAuthority> auth = new ArrayList<GrantedAuthority>();
auth.add(new SimpleGrantedAuthority(AUTHORITY));
return auth;
}
@Override
public String getUsername() {
return user.getName();
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return user.getEnabled();
}
@Override
public String getEnglishname() {
return user.getEnglishName();
}
}
2. Thymeleaf 를 이용하여 뷰에 보여주기
<!DOCTYPE html>
<html lang="ko"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<div sec:authorize="isAuthenticated()">
<th:block th:if="${#authentication.getPrincipal().getEngName().isEmpty()}">
<span sec:authentication="principal.engName"></span><br>
</th:block>
</div>
</html>
728x90
반응형
'Web 개발 > Java, SpringBoot, JPA' 카테고리의 다른 글
[JPA] ConstraintViolationException (0) | 2021.07.26 |
---|---|
[JPA]Error creating bean with name 'springSecurityFilterChain' defined in class path resource (0) | 2021.07.01 |
[JPA] 로그인한 사용자 정보 가져오기 (0) | 2021.06.30 |
[jQuery] val(), html() 차이 (0) | 2021.06.29 |
[JPA/Thymeleaf] An error happened during template parsing (0) | 2021.06.27 |