Entity as UserDetails
vo, 즉 @Entity 이면서 UserDetails 를 구현한다.
package com.example.demo.vo;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Arrays;
import java.util.Collection;
@Data
@Entity
public class Reader implements UserDetails {
private static final long serialVersionUID = 1L;
@Id
private String username;
private String fullname;
private String password;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return Arrays.asList(new SimpleGrantedAuthority("ROLE_READER"));
}
@Override
public String getPassword() {
return password;
}
@Override
public boolean isAccountNonExpired() {
// 항상 계정이 만료되지 않았다고 반환
return true;
}
@Override
public boolean isAccountNonLocked() {
// 항상 계정이 잠금되지 않았다고 반환
return true;
}
@Override
public boolean isCredentialsNonExpired() {
// 항상 계정이 유효하다고 반환
return true;
}
@Override
public boolean isEnabled() {
// 항상 계정이 활성화되어 있다고 반환
return true;
}
}