我已经能够对用户进行身份验证,并且可以让他们登录的用户名显示在他们的页面上。但我想使用用户名而不是用户名。
为此的汇编程序:
@Service("assembler")
public class Assembler {
@Transactional(readOnly = true)
public UserDetails buildUserFromUser(UserEntity userEntity) {
String username = userEntity.getUsername();
String password = userEntity.getPassword();
//String name = userEntity.getName();
boolean enabled = userEntity.getActive();
boolean accountNonExpired = enabled;
boolean credentialsNonExpired = enabled;
boolean accountNonLocked = enabled;
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
for(Role role : userEntity.getRoles()) {
authorities.add(new SimpleGrantedAuthority(role.getName()));
}
User user = new
User(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
return user;
}
}
我使用的 UserDetails 仅限于 set 构造函数,因此我无法通过它获取名称。还有其他方法可以做到这一点吗?