我怎样才能让 Immutables 生成具有这种类型的类
public class IdentifiedUserDetails implements UserDetails, CredentialsContainer, Identified<UUID> {
private static final long serialVersionUID = 4905378177558522349L;
private final UUID id;
private final String username;
private final Set<GrantedAuthority> authorities;
private boolean accountNonExpired = true;
private boolean accountNonLocked = true;
private boolean credentialsNonExpired = true;
private boolean enabled = true;
private String password;
IdentifiedUserDetails( final UUID id, final String username, final String password ) {
this.id = Objects.requireNonNull( id );
this.username = Objects.requireNonNull( username );
this.password = Objects.requireNonNull( password );
this.authorities = Collections.unmodifiableSet( sortAuthorities( Collections.emptySet() ) );
}
private static SortedSet<GrantedAuthority> sortAuthorities(
final Collection<? extends GrantedAuthority> authorities ) {
// Ensure array iteration order is predictable (as per
// UserDetails.getAuthorities() contract and SEC-717)
return authorities.stream()
.filter( Objects::nonNull )
.collect( Collectors.toCollection( () -> {
return new TreeSet<GrantedAuthority>(
Comparator.nullsFirst( Comparator.comparing( GrantedAuthority::getAuthority ) ) );
} ) );
}
}
注意:空集是从某个外部数据源传入的真实集的占位符,我还没有开始填充它,但我会在某个时候填充它,排序是对 Spring Security 中的重新实现,您应该假定排序需要应用于将传递给 Immutables 构建器的任何集合。