【发布时间】: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