【问题标题】:Spring Security encrypted password problem [duplicate]Spring Security加密密码问题[重复]
【发布时间】:2021-05-13 01:56:27
【问题描述】:

我遇到的问题是我收到错误“没有为 id “null”映射 PasswordEncoder ”。我已经阅读了 Spring Security 如何不允许密码为纯文本(我理解这是出于安全措施),但问题是我真的不知道如何修复此错误

    @Override                                                                 
    protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/", "/home").permitAll().antMatchers("/admin").hasRole("ADMIN")
            .anyRequest().authenticated().and().formLogin().loginPage("/login").permitAll().and().logout()
            .permitAll();
    http.exceptionHandling().accessDeniedPage("/403");
}

@Autowired                                                                    
DataSource dataSource;

@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
    auth.jdbcAuthentication().dataSource(dataSource)
            .usersByUsernameQuery("select username, password, enabled from users where username=?")
            .authoritiesByUsernameQuery("select username, role from user_roles where username=?");

}

【问题讨论】:

  • 我在这个项目中使用的唯一其他东西是一个 Web 控制器,它返回我在那里拥有的每个请求映射的 HTML 文件,显示页面 /home、/admin、/login等。
  • 强烈不推荐(不建议这样做),但您可以使用它来不编码密码:stackoverflow.com/questions/56762121/…
  • 我已经使用了它,它解决了我的问题,现在问题来了,我该怎么做才能加密?我看过一些例子,但我不确定如何在我的案例中应用它们
  • 当谷歌搜索你的错误时,这是​​第一个命中,猜猜是谁写了这个答案。在询问stackoverflow.com/questions/62770105/…之前请先谷歌

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


【解决方案1】:

这个问题之前已经出现过,我已经为这个问题写了一个答案here。如果您在谷歌上搜索此错误消息,那么哪个是第一个命中。

这个错误也是the first error mentioned in the spring security documentation

当存储的密码之一没有密码存储格式中描述的 id 时,会发生以下错误。

【讨论】:

  • 我说我错过了 :) 这是我的错,我明白在您发表的评论中并感谢您的提醒。我花了大约 2 个小时在不好的地方搜索,但这也是学习的一部分,不是因为我的研究很差,我们都从某个地方开始。
  • + 在我搜索“spring security 加密密码编码器问题”之后,我没有得到这些结果,如果你愿意,我可以发送屏幕截图。不好的问题问?哦,好吧,这仍然是一个可以改进的问题,所以不必强调我没有研究而不知道完整背景的事实。不过你说的也是对的,问之前先研究好,但信息缺失不代表研究不好,代表做不好。 (不是因为时间太短,而是因为我们都随着时间而成长的一点点练习)
  • 所有你需要谷歌是"There is no PasswordEncoder mapped for the id "null" " 请阅读这篇文章,并首先回答在询问堆栈溢出之前你应该付出什么努力。只是把它当作一种学习经验。 meta.stackoverflow.com/questions/261592/…
  • 请不要在答案中添加元评论。另外,请注意,缺乏研究从不成为结束问题的理由,这只是拒绝投票的理由。另外,如果你要写一个答案,写一个完整的答案,不要只是链接到另一个答案,即使它是你自己的。
猜你喜欢
  • 2014-05-24
  • 1970-01-01
  • 2012-04-10
  • 2011-06-25
  • 2012-07-07
  • 2018-12-10
  • 2015-10-27
  • 2023-03-30
  • 2014-02-14
相关资源
最近更新 更多