我有一个Spring Boot Web应用程序,暴露了很少的休息端点.我想知道我们如何只为选定的休息端点启用基本身份验证.假设我只/employee/{id}想要进行身份验证请求并忽略所有其他其他端点.我使用以下代码.我的问题是antMatcher唯一验证指定的请求吗?目前,它为所有其他端点启用身份验证:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// How does it work will it only authenticate employee &
// ignore any other request?? Its authenticating all the requests currently.
http
.authorizeRequests()
.antMatchers("/employee/*").authenticated()
.and()
.httpBasic()
.and()
.csrf()
.disable();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("admin").password("admin").roles("USER");
}
}
Run Code Online (Sandbox Code Playgroud) 我需要if-else在我的加特林检查中实施一个条件。
例如:- 下面,我可能将 JSON 响应中的 items 数组设为空。所以我需要检查 items 是否为空。我需要执行另一组动作。你能告诉我如何实现这一目标吗?
.check(
jsonPath("$..items[(@.length-1)].id").saveAs("MyAlbumId")
)
Run Code Online (Sandbox Code Playgroud)