【发布时间】:2021-12-16 17:57:56
【问题描述】:
我有一个名为 authenticate 的端点,该端点被提供给 antMatchers("/authenticate") 以跳过对该端点的授权,但它仍会检查身份验证。
代码:
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
// We don't need CSRF for this example
httpSecurity.csrf().disable()
// dont authenticate this particular request
.authorizeRequests().antMatchers("/authenticate").permitAll()
// all other requests need to be authenticated
.and().authorizeRequests()
.anyRequest().authenticated()
.and()
// make sure we use stateless session; session won't be used to
// store user's state.
.exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint)
.and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// Add a filter to validate the tokens with every request
httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}
【问题讨论】:
-
permitAll并不意味着没有安全性。仍然需要一个身份验证对象,但它可以是匿名的。你还确定模式是正确的,并且 url 是/authenticate而不是别的吗? -
模式是正确的,而不是permitAll(),我们还能用什么来停止在端点检查授权?
-
那个端点是做什么的?您的 JWT 过滤器不应该已经解码令牌并设置身份验证吗?为什么你需要一个端点?
标签: java spring-boot jwt