【问题标题】:Is it OK to use a domain class to implement UserDetails interface in a Spring Boot project [closed]在Spring Boot项目中使用域类实现UserDetails接口是否可以[关闭]
【发布时间】:2018-02-28 12:42:27
【问题描述】:

是否可以使用如下所示的域类在带有 Hibernate 的 Spring Boot 中实现 UserDetails 接口?还是最好使用具有私有 User 实例的包装类?

@Entity
@Table(name = "users")
public class User
    {

    // All fields have setters and getter that aren't included in the code

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "user_id")
    private Integer id;

    @Column(name = "email")
    private String email;

    @Column(name = "username")
    private String userName;

    @Column(name = "password")
    @Transient
    private String password;

    }

【问题讨论】:

    标签: java spring spring-boot spring-security userdetailsservice


    【解决方案1】:

    没关系。您将必须实现几个处理角色功能的方法。同样根据我的经验,用户名和密码必须作为类属性存在。

    这里有一个很好的例子来说明如何使用 springboot 实现 JWT:https://auth0.com/blog/implementing-jwt-authentication-on-spring-boot/

    它包含一个实现 UserDetails 的 User 类。

    【讨论】:

    • 你好像被误解了。 it's example 的域“用户”类不是User,而是ApplicationUser
    猜你喜欢
    • 1970-01-01
    • 2019-08-06
    • 1970-01-01
    • 1970-01-01
    • 2010-09-13
    • 2019-10-22
    • 2015-07-18
    • 2010-12-10
    • 2021-12-22
    相关资源
    最近更新 更多