java - Spring Boot Http Security 配置单元测试
问题描述
在我的 Spring 引导应用程序中,我有一个安全配置类,我正在尝试为其编写单元测试。这是我第一次这样做,所以我需要一些帮助。这是下面的代码。请一些帮助将不胜感激。谢谢
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);
}}
解决方案
推荐阅读
- python - 将类似列表的长字符串转换为新列表
- twig - Drupal 8 twig 调试未显示所有变量
- java - 为什么我的代码找不到我选择的图像是否相同?
- fat-free-framework - 未使用重新路由存储的会话变量
- sql-server - 如何在 set 子句中使用 max 函数修复更新语句
- javascript - 有什么方法可以使用量角器测试加载的网页 url,尽管它会随机更改端口号并且 url 正在更改?
- spring-cloud-dataflow - spring cloud数据流API.1.7.3中如何使用dataflowtemplate
- javascript - 如果其中一个对象仅包含字符串的一部分,我如何签入一组对象?
- java - 滚动在 RecyclerView 中插入的项目
- gcc - 我可以让 cpp 不在#pragma 上输出空格行吗?