我有一个关于在我的Spring靴示例中打开swagger ui的问题。
Securing GET /springboot-blog-rest-api/swagger-ui
2022-07-22 01:38:58.820 DEBUG 30576 --- [nio-8080-exec-4] s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
2022-07-22 01:38:58.820 DEBUG 30576 --- [nio-8080-exec-4] o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
2022-07-22 01:38:58.820 DEBUG 30576 --- [nio-8080-exec-4] o.s.s.w.a.i.FilterSecurityInterceptor : Failed to authorize filter invocation [GET /springboot-blog-rest-api/swagger-ui] with attributes [authenticated]
2022-07-22 01:38:58.820 DEBUG 30576 --- [nio-8080-exec-4] s.s.w.c.SecurityContextPersistenceFilter : Cleared SecurityContextHolder to complete request
2022-07-22 01:38:58.820 DEBUG 30576 --- [nio-8080-exec-4] o.s.security.web.FilterChainProxy : Securing GET /error
2022-07-22 01:38:58.821 DEBUG 30576 --- [nio-8080-exec-4] s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
2022-07-22 01:38:58.821 DEBUG 30576 --- [nio-8080-exec-4] o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
2022-07-22 01:38:58.821 DEBUG 30576 --- [nio-8080-exec-4] o.s.security.web.FilterChainProxy : Secured GET /error
2022-07-22 01:38:58.821 DEBUG 30576 --- [nio-8080-exec-4] a.DefaultWebInvocationPrivilegeEvaluator : filter invocation [/error] denied for AnonymousAuthenticationToken [Principal=anonymousUser, Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=null], Granted Authorities=[ROLE_ANONYMOUS]]
org.springframework.security.access.AccessDeniedException: Access is denied
我使用了springfox-swagger 2版本3、SpringFoxBootStarter版本3,最后使用了springfox swagger ui版本2.9。
如何解决我的问题?
这是我的SwaggerConfig文件。
@Configuration
@EnableSwagger2
public class SwaggerConfig {
public static final String AUTHORIZATION_HEADER = "Authorization";
private ApiKey apiKey(){
return new ApiKey("JWT", AUTHORIZATION_HEADER, "header");
}
private ApiInfo apiInfo(){
return new ApiInfo(
"Spring Boot Blog REST APIs",
"Spring Boot Blog REST API Documentation",
"1",
"Terms of service",
new Contact("Name", "website-address", "Email"),
"License of API",
"API license URL",
Collections.emptyList()
);
}
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.securityContexts(Arrays.asList(securityContext()))
.securitySchemes(Arrays.asList(apiKey()))
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
private SecurityContext securityContext(){
return SecurityContext.builder().securityReferences(defaultAuth()).build();
}
private List<SecurityReference> defaultAuth(){
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Arrays.asList(new SecurityReference("JWT", authorizationScopes));
}
}
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig {
@Autowired
private JwtAuthenticationEntryPoint authenticationEntryPoint;
@Bean
public JwtAuthenticationFilter jwtAuthenticationFilter(){
return new JwtAuthenticationFilter();
}
@Bean
PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().antMatchers("/v2/api-docs/**",
"/swagger-ui/**","/swagger-resources/**","/swagger-ui.html","/webjars/**");
}
@Bean
protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf().disable()
.exceptionHandling()
.authenticationEntryPoint(authenticationEntryPoint)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests((authorize) -> authorize
.antMatchers(HttpMethod.GET, "/api/v1/**").permitAll()
.antMatchers("/api/v1/auth/**").permitAll()
.anyRequest()
.authenticated()
);
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
return http.build();
}
@Bean
public AuthenticationManager authenticationManager(
AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
}
这是答案
我可以通过localhost:8080/swagger ui.html
访问url
每当我试图打开我的fxml文件中的SceneBuilder选项卡时,我会得到一个错误,说它无法在Scene Builder中打开该文件,以及下面的异常: 问题是,我可以在文件中执行操作,而不会出现任何错误。 我使用Windows10上的IntelliJ IDEA 2019.3和Azul Zulu作为我的JDK和JavaFX SDK库。 有什么办法可以解决吗?
当运行maven包目标时 MVN清洁包 构建抛出错误: 目标组织。springframework。启动:spring boot maven插件:3.0.0-M1:重新打包失败:无法在插件“org”中加载mojo“重新打包”。springframework。boot:spring boot maven插件:3.0.0-M1’,由于API不兼容:org。科德豪斯。神经丛。组成部分存储库。例外Compo
SpringBoot项目中parent中没有默认版本的依赖如何选择版本?类如mybatis-spring-boot-starter依赖,parent中是没有默认配置的。我想请问类似这种情况如何选择合适的依赖版本呢?我在mybatis官网也没有找到相关资料,依赖的jar包中也没有,我不喜欢看网友给的资料,我还是喜欢看官网的资料,大家都是怎么选择的呢?靠经验?靠百度? 尝试过百度和查看官网,想知道对于
本文向大家介绍SpringBoot 中使用JSP的方法示例,包括了SpringBoot 中使用JSP的方法示例的使用技巧和注意事项,需要的朋友参考一下 本文介绍了SpringBoot 中使用JSP的方法示例,分享给大家,具体如下: 依赖: 示例代码: 在SpringBoot中使用JSP SpringBoot默认不支持JSP,需要在项目中添加相关的依赖 配置文件增加配置项: Login.java 以
有没有办法绕过这个问题?我不是使用旧Anylogic的计算机上的系统管理员,我们的许可证也不包括更新到新版本的Anylogic(于2018年12月到期)。
我无法打开recyclerview项目中的片段。当我点击项目中的按钮时,我得到了一条错误消息:对空对象引用的onEditClick(com.example.taskapprealm.edit.EditFragment)“。Null位于适配器内部。 活动中的方法: 和适配器中的onBindViewHolder: 接口: 日志: