Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让Spring对我使用的数据库进行身份验证?_Spring_Spring Boot_Spring Security - Fatal编程技术网

如何让Spring对我使用的数据库进行身份验证?

如何让Spring对我使用的数据库进行身份验证?,spring,spring-boot,spring-security,Spring,Spring Boot,Spring Security,我在Spring boot支持的API中有以下安全配置 @Configuration @EnableGlobalMethodSecurity(prePostEnabled = true) @EnableWebSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) t

我在Spring boot支持的API中有以下安全配置

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.httpBasic().and().authorizeRequests()
                .antMatchers("/", "/helloWorld").permitAll()
                .anyRequest().authenticated();

        http.csrf().disable();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
            .withUser("user").password("password").roles("USER")
            .and().withUser("tester").password("password").roles("NOROLE");
    }
}
现在,这很好-它让我开始运行,测试我的资源,等等

但目前,我真的不知道如何适应我存储在数据库中的用户。我理解我需要遵循的逻辑:

  • 获取凭据(如电子邮件和通行证)
  • findOne电子邮件
  • 如果未找到记录,则用户无效-拒绝身份验证,不要返回令牌
  • 否则,请加密提供的密码,并检查它是否与存储的密码匹配
  • 如果匹配,则创建令牌,并将其返回给客户端
  • 否则,拒绝验证-不返回令牌
  • 我以前在node.js、mongo和mongoose中做过这项工作,但我不熟悉在Spring中采用这种方法。我真的需要一些指导。我在谷歌上搜索了相当多,但是所有的auth教程似乎都采用了我的方法,然后相信你知道如何在以后适应它——这对我们这些不使用教程作为参考,而是实际学习spring的人来说很糟糕


    非常感谢您的帮助。谢谢。

    不要问阅读如何解释如何使用数据库的问题?基本上,SpringSecurity可以满足您的所有需求……这正是我想要的。考虑到这个网站的用途,不必抱怨我问了一个问题。谢谢