【发布时间】:2019-01-20 13:16:01
【问题描述】:
在我的 Spring Boot 应用程序中,我有一个安全配置类,我正在尝试为其编写单元测试。这是我第一次这样做,所以我需要一些帮助。这是下面的代码。请一些帮助将不胜感激。谢谢
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private String id;
private String pwd;
private String role;
@Autowired
private AuthenticationEntryPoint authEntryPoint;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.anyRequest().authenticated()
.and().httpBasic()
.authenticationEntryPoint(authEntryPoint).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
//This allows to view h2 console during development
http.headers().frameOptions().sameOrigin();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().
withUser(id).
password(pwd).
roles(role);
}}
【问题讨论】:
-
你有什么问题?
-
我正在尝试对这个类进行单元测试,但不知道如何去做
标签: java spring spring-boot spring-security