我通过Hibernate将用户保存在数据库表中,我使用Spring Security进行身份验证:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import org.springframework.security.config.annotation.authentication.builders.*;
import org.springframework.security.config.annotation.web.configuration.*;
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}
Run Code Online (Sandbox Code Playgroud)
这很有效,但有一点 - 用户在服务器启动时加载.我需要编写方法RegisterUser(用户用户),在运行时将新用户添加到Spring Security.此方法应仅关注此任务.我不知道如何开始实现此功能,所以感谢任何建议!;)
Ofc用户有登录,密码,角色等等字段...
请不要使用Spring MVC发布解决方案.该系统是使用版本4.0.x中的Spring Web Boost和Spring Security Boost的RESTful应用程序