【发布时间】:2023-03-25 11:05:02
【问题描述】:
基于此topic 似乎我发现了问题,但我真的不知道如何解决它。
我对 WebSecurityConfigurerAdapter 进行了以下配置,因为我正在使用 JWT 安全流程,例如 page 问题出在配置方面,而不是构建本身。
配置是这样的:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable()
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests().antMatchers("/login").permitAll()
.antMatchers("/register/**").permitAll()
.antMatchers("/").permitAll()
.anyRequest().authenticated();
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
}
不幸的是,它不允许我访问主页。如果我这样做.antMatchers("/**").permitAll() 它会正常工作。
当我访问 http://localhost:8080 我得到:
2021-04-26 23:09:42.517 ERROR 10160 --- [nio-8080-exec-4] c.a.d.security.jwt.AuthEntryPointJwt : Unauthorized error: Full authentication is required to access this resource
这来自 unauthorizedHandler,但在配置中,.antMatchers("/").permitAll() 应该让我访问索引但不是。
如果我以.antMatchers("/**").permitAll() 为例,它可以让我访问该页面,但总的来说它会破坏安全流程。
【问题讨论】:
标签: spring-boot spring-security jwt