我在mongodb和thymeleaf上使用spring。我的问题是我不知道如何将登录查询与用户数据库连接。我已经检查了密码(使用散列),但是我只能查询在
@Override
public void init (AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
方法。有人能帮我吗?
终于我拥有了!该指南和@helmy的帖子是一个很好的帮助。额外的一点是写
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(mongoSecurityService);
}
如果您不使用.xml配置并添加CustomMongoService
。谢谢!
编辑:
您应该WebSecurityConfiguration extends WebSecurityConfigurerAdapter
在项目文件夹中包含该类。在此类中编写以下代码:
@Configuration
protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {
@Autowired
public CustomMongoSecurityService mongoSecurityService;
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(mongoSecurityService).and()
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("1234").roles("ADMIN");
}
}
希望能有所帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句