我正在尝试从 Spring Security 提供的 User 和 Authorities 获取属性。
我知道您可以覆盖 UserDetailsService 以创建您自己的自定义类,但在这种情况下,我想获得完整的默认类,另外还有一些属性。
让我用代码解释一下:
public class User implements UserDetails, CredentialsContainer {
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
private String password;
private final String username;
private final Set<GrantedAuthority> authorities;
private final boolean accountNonExpired;
private final boolean accountNonLocked;
private final boolean credentialsNonExpired;
private final boolean enabled;
}
Run Code Online (Sandbox Code Playgroud)
这是 Spring Security 提供的 User 类,我想要的是使用这些属性扩展我自己的类。我试过了,但数据库没有从用户那里获取属性:
@Entity
@Table(name="MyUser")
public class ExtendedUser extends User {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
private String email;
private static final long …Run Code Online (Sandbox Code Playgroud)