[英]SpringMVC 3 Spring Security Creating User Login
I'm trying to use this tutorial to create a spring mvc user login page.我正在尝试使用本教程创建 spring mvc 用户登录页面。
The tutorial is great but one thing is not clear, on the second page he talks about the UserRepository
interface.教程很棒,但有一点不清楚,在 第二页他谈到了UserRepository
接口。 The interface methods return User
.接口方法返回User
。 What I'm confused about is of the User
he's referring to is the User
object part of the spring framework?我对他所指的User
感到困惑的是 spring 框架的User
object 部分? The reason I ask if because I want to have an email address field which is not there in the User
object which is part of the Spring security framework.我问的原因是因为我想要一个 email 地址字段,该地址字段在User
object 中不存在,它是 Spring 安全框架的一部分。
Also, in his implementation of the UserLoginService
he has a method:此外,在他的UserLoginService
实现中,他有一个方法:
@Override
public User getLoggedUser() {
User loggedUser = null;
AuthenticationUserDetails userDetails = getLoggedUserDetails();
if (userDetails != null) {
loggedUser = userRepository.findById(userDetails.getId());
}
return loggedUser;
}
the trouble is that the AuthenticationUserDetails
does not have a getId()
method, which makes me think he intends us to extend Spring's User to create our own Account entity or something.问题是AuthenticationUserDetails
没有getId()
方法,这让我觉得他打算让我们扩展 Spring 的 User 来创建我们自己的 Account 实体或其他东西。
I want to use Hibernate to create my Account
and Role
entities and so far every tutorial I've found seems to be before Spring MVC 3 or just giving bits and pieces.我想使用 Hibernate 来创建我的Account
和Role
实体,到目前为止,我发现的每个教程似乎都在 Spring MVC 3 之前,或者只是提供一些零碎的东西。
Can anyone provide clarification on this or refer me to a good tutorial for User Login with Spring Security and SpringMVC?任何人都可以对此提供澄清或向我推荐使用 Spring 安全性和 SpringMVC 进行用户登录的好教程吗?
The User
is a Spring Security UserDetails
object. User
是 Spring 安全用户详细信息UserDetails
。 If you want to extend the object to add more fields, implement the UserDetailsService
interface and extend the UserDetails
object with your own fields.如果您想扩展 object 以添加更多字段,请实现UserDetailsService
ervice 接口并使用您自己的字段扩展UserDetails
object。 Then configure Spring Security to use your service, as follows:然后配置 Spring Security 来使用你的服务,如下:
<security:authentication-manager>
<security:authentication-provider user-service-ref="myDetailsService" />
</security:authentication-manager>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.