【发布时间】:2019-08-12 05:06:09
【问题描述】:
这是我的安全配置代码:
@EnableWebSecurity
@EnableGlobalMethodSecurity (
prePostEnabled=true
)
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
auth.inMemoryAuthentication()
.withUser("chandra").password("{noop}1234").roles("USER").and()
.withUser("admin").password("{noop}admin123").roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/addItem","/delete").hasRole("ADMIN")
.antMatchers("/getAllItems").hasRole("USER")
.and().csrf().disable().headers().frameOptions().disable()
.and()
.formLogin();
}
}
但是在编译 spring 时仍然为我生成密码。
Using generated security password: 49f04bde-ac1f-4e30-870b-ba0dd93d50f3
我通过打印语句检查了配置是否正在加载,发现安全配置正在加载。是否应该进行任何更改以使其与给定的用户 ID 和密码一起使用。
提前致谢。
【问题讨论】:
-
您是否尝试使用指定用户登录?
-
是的,在我尝试过的邮递员中并且正在加载表单,所以我删除了 .and.formLogin() 并使用我的凭据('chandra','1234')再次尝试,但被禁止了 403。@安德鲁萨沙
-
嗨,我现在面临同样的问题。这个问题有公认的答案或解决方案吗?
-
enter link description here你应该设置密码编码
标签: spring-boot spring-security