- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 SpringBoot 2.0.1.RELEASE mvc 应用程序,因此在安全配置中我定义了此方法:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser(User
.withDefaultPasswordEncoder()
.username(DEV_USER)
.password(DEV_PWD)
.roles("ADMIN").build());
}
但是似乎 User 类型的方法 withDefaultPasswordEncoder()
已被弃用,但我不知道我必须使用哪个,
最佳答案
@Deprecated
public static User.UserBuilder withDefaultPasswordEncoder()
Deprecated. Using this method is not considered safe for production, but is acceptable for demos and getting started. For production purposes, ensure the password is encoded externally. See the method Javadoc for additional details.
WARNING: This method is considered unsafe for production and is only intended for sample applications.
UserDetails user = User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build();
// outputs {bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG
System.out.println(user.getPassword());
This is not safe for production (it is intended for getting started experience) because the password "password" is compiled into the source code and then is included in memory at the time of creation. This means there are still ways to recover the plain text password making it unsafe. It does provide a slight improvement to using plain text passwords since the UserDetails password is securely hashed. This means if the UserDetails password is accidentally exposed, the password is securely stored. In a production setting, it is recommended to hash the password ahead of time. For example:
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
// outputs {bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG
// remember the password that is printed out and use in the next step
System.out.println(encoder.encode("password"));
UserDetails user = User.withUsername("user")
.password("{bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG")
.roles("USER")
.build();
返回: 一个 UserBuilder,它使用默认的 PasswordEncoder 自动对密码进行编码
要回答您的问题,您可以这样做:
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
UserDetails userDetails = User.withUsername(DEV_USER)
.password(encoder.encode(DEV_PWD))
.roles("ADMIN")
.build();
auth.inMemoryAuthentication().withUser(userDetails);
}
关于spring - SpringBoot 2.0.1.RELEASE 中的 AuthenticationManagerBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49755413/
我正在编写一个 Google Chrome 扩展程序,它需要我使用 Spring 设置的用户身份验证,目前我的代码中有几个示例用户名和密码,而我仍在开发中。此时,我已准备好添加真实的用户名和密码,但我
我正在使用 Spring Security 4.0.1 并希望使用多个身份验证提供程序使用基于 Java 的配置进行身份验证。如何指定提供商顺序? 我希望使用 AuthenticationManage
我正在使用 Spring Boot 2.0(利用 Spring Security 5.0)。我正在尝试向 WebSecurityConfigurerAdapter 子类中的 Authenticatio
谁能解释一下何时覆盖 configure(HttpSecurity)、configure(WebSecurity) 和 configure(AuthenticationManagerBuilder)?
要在 Spring Boot 中提供自定义身份验证提供程序,我是否需要以下两项?它们有什么区别? AuthenticationManagerBuilder HttpSecurity.authentic
我正在研究基于 Spring Security Java 的配置。 我已经创建了我自己的 MyAuthenticationProvider,我想在 ProviderManager 中注册它(Authe
我正在配置 Spring Security。为了验证和授权用户,我覆盖了 configure(AuthenticationManagerBuilder auth)的 WebSecurityConfig
我有一个 SpringBoot 2.0.1.RELEASE mvc 应用程序,因此在安全配置中我定义了此方法: @Autowired public void configureGlobal(Auth
所以我正在研究 Spring Security 的实现。我遇到了一段我无法理解的代码。因此,根据文档,当我们想要自定义 Spring 使用的 AuthenticationManager 时,需要重写以
我有一个 SpringBoot 2.0.1.RELEASE mvc 应用程序,因此在安全配置中我定义了此方法: @Autowired public void configureGlobal(Auth
我已经设置了样板 spring security 配置器: public class SecurityConfiguration extends WebSecurityConfigurerAdapte
配置 Spring Security 时: @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecur
WebSecurityConfigurerAdapter 提供两个覆盖如下: protected void configure(AuthenticationManagerBuilder auth) 和
我正在 Spring Boot 应用程序中学习 Spring Security,我有一个非常简单的示例。我看到,如果我评论 configure(AuthenticationManagerBuilder
我是一名优秀的程序员,十分优秀!