0
我已經能夠驗證用戶,並且可以獲取他們登錄的用戶名以在他們的頁面上顯示。但不是用戶名,我想使用用戶名。Spring身份驗證 - 獲取登錄名
此彙編:
@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。有另一種方法可以做到這一點嗎?
是的,它工作絕對好。非常感謝。 – user2259555 2013-05-04 06:23:52