我用Java 17和Sping Boot 3创建了一个JWT
项目。我试图在我的应用程序中包括Swagger UI,但当我试图访问http://localhost:8080/swagger-ui/
时,他问我访问它的凭据。
我的代码:
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfiguration {
private final JwtAuthenticationFilter jwtAuthFilter;
private final AuthenticationProvider authenticationProvider;
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/v1/auth/**", "/v2/api-docs",
"/swagger-resources",
"/swagger-resources/**",
"/configuration/ui",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**",
"/v3/api-docs/**",
"/swagger-ui/**", "/configuration/**", "/swagger-ui.html").permitAll()
.anyRequest().authenticated()
)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider)
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class)
.httpBasic(Customizer.withDefaults());
return http.build();
}
}
我的依赖项:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
任何帮助是高度赞赏。
我已经尝试过配置WebConfigSecurity类所需的端点,就像here解释的那样。我还尝试重构这个方法,就像我在link上看到的那样,并将springfox版本从2.9.2升级到3.0.0,但没有结果。
1条答案
按热度按时间7vhp5slm1#
我也解决了这个问题,感谢@dauthDaert06的评论。我只是简单地改变了依赖关系,遵循了关于这个link的一些提示。SpringFox与3.0.0和更高的Sping Boot 版本不兼容。