我正在使用 Spring Boot 3、Spring Security 6。我的安全配置无法正常工作。我有两条路径,任何请求都应该被允许,而对于其他所有请求,都需要进行身份验证。
GET和方法都POST适用于那些需要身份验证的人。
对于那些带有 的permitAll(),只有GET请求有效。对于POST,我收到 401 Unauthorized。
我负责 CSRF,无论如何我希望所有POST请求都能工作,而不仅仅是那些带有身份验证的请求。
在 Postman 上,我选择POST“无身份验证”,放置 RAW 正文并选择 JSON。我真的不知道为什么它不起作用。
这是我的代码:
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http, KeycloakLogoutHandler keycloakLogoutHandler) throws Exception {
CookieCsrfTokenRepository tokenRepository = CookieCsrfTokenRepository.withHttpOnlyFalse();
XorCsrfTokenRequestAttributeHandler delegate = new XorCsrfTokenRequestAttributeHandler();
// set the name of the attribute the CsrfToken will be populated …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Spring Boot 3、Java 17、Open Api 3 查看 Swagger 页面。
我一定做错了什么,但是什么?是不是有什么不兼容的地方?
在 http://localhost:8080/v3/api-docs/ 或 http://localhost:8080/swagger-ui 我得到Whitelabel错误页面。
我正在从 Spring Boot 2.5 迁移,但为了确保我没有忘记删除导致此错误的某些内容,我从此处复制了一个教程https://www.techgeeknext.com/spring-boot/spring-boot- swagger3-example(我在这篇文章的末尾写了它)。
虽然运行了,但控制台中出现错误:
ERROR Class 'org.springframework.core.io.support.PathMatchingResourcePatternResolver' could not be processed by org.zeroturnaround.javarebel.integration.spring.core.cbp.PathMatchingResourcePatternResolverCBP@jdk.internal.loader.ClassLoaders$AppClassLoader@7a46a697: org.zeroturnaround.bundled.javassist.NotFoundException: retrieveMatchingFiles(..) is not found in org.springframework.core.io.support.PathMatchingResourcePatternResolver
at org.zeroturnaround.bundled.javassist.CtClassType.getDeclaredMethod(SourceFile:1356)
at org.zeroturnaround.javarebel.integration.spring.core.cbp.PathMatchingResourcePatternResolverCBP.registerScannedDirs(PathMatchingResourcePatternResolverCBP.java:255)
at org.zeroturnaround.javarebel.integration.spring.core.cbp.PathMatchingResourcePatternResolverCBP.process(PathMatchingResourcePatternResolverCBP.java:41)
at org.zeroturnaround.javarebel.integration.support.JavassistClassBytecodeProcessor.process(SourceFile:137)
at org.zeroturnaround.javarebel.integration.support.CacheAwareJavassistClassBytecodeProcessor.process(SourceFile:34)
at org.zeroturnaround.javarebel.integration.support.JavassistClassBytecodeProcessor.process(SourceFile:83)
at com.zeroturnaround.javarebel.yg.a(SourceFile:413)
at com.zeroturnaround.javarebel.yg.a(SourceFile:340)
at com.zeroturnaround.javarebel.SDKIntegrationImpl.runBytecodeProcessors(SourceFile:44)
at com.zeroturnaround.javarebel.vk.transform(SourceFile:140)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:43009)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at org.springframework.core.io.support.ResourceArrayPropertyEditor.<init>(ResourceArrayPropertyEditor.java:77)
at …Run Code Online (Sandbox Code Playgroud)