{"record":{"id":"419f557ba1b59a84","repo":"spring-projects/spring-security","slug":"no-rsocketsecurity-defined","errorCode":null,"errorMessage":"No RSocketSecurity defined","messagePattern":"No RSocketSecurity defined","errorType":"exception","errorClass":"NoSuchBeanDefinitionException","httpStatus":null,"severity":"error","filePath":"config/src/main/java/org/springframework/security/config/annotation/rsocket/SecuritySocketAcceptorInterceptorConfiguration.java","lineNumber":49,"sourceCode":" * @author Rob Winch\n * @since 5.2\n */\n@Configuration(proxyBeanMethods = false)\nclass SecuritySocketAcceptorInterceptorConfiguration {\n\n\t@Bean\n\tSecuritySocketAcceptorInterceptor securitySocketAcceptorInterceptor(\n\t\t\tObjectProvider<PayloadSocketAcceptorInterceptor> rsocketInterceptor,\n\t\t\tObjectProvider<RSocketSecurity> rsocketSecurity) {\n\t\tPayloadSocketAcceptorInterceptor delegate = rsocketInterceptor\n\t\t\t.getIfAvailable(() -> defaultInterceptor(rsocketSecurity));\n\t\treturn new SecuritySocketAcceptorInterceptor(delegate);\n\t}\n\n\tprivate PayloadSocketAcceptorInterceptor defaultInterceptor(ObjectProvider<RSocketSecurity> rsocketSecurity) {\n\t\tRSocketSecurity rsocket = rsocketSecurity.getIfAvailable();\n\t\tif (rsocket == null) {\n\t\t\tthrow new NoSuchBeanDefinitionException(\"No RSocketSecurity defined\");\n\t\t}\n\t\t// @formatter:off\n\t\trsocket.basicAuthentication(Customizer.withDefaults())\n\t\t\t.simpleAuthentication(Customizer.withDefaults())\n\t\t\t.authorizePayload((authz) -> authz\n\t\t\t\t.setup().authenticated()\n\t\t\t\t.anyRequest().authenticated()\n\t\t\t\t.matcher((e) -> MatchResult.match()).permitAll()\n\t\t\t);\n\t\t// @formatter:on\n\t\treturn rsocket.build();\n\t}\n\n}\n","sourceCodeStart":31,"sourceCodeEnd":64,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/config/src/main/java/org/springframework/security/config/annotation/rsocket/SecuritySocketAcceptorInterceptorConfiguration.java#L31-L64","documentation":"When Spring Boot auto-configures RSocket security, it needs an RSocketSecurity bean to build the default PayloadSocketAcceptorInterceptor. If no RSocketSecurity bean exists in the context, defaultInterceptor throws NoSuchBeanDefinitionException(\"No RSocketSecurity defined\"). This means the security setup for RSocket was never defined even though the interceptor configuration is active.","triggerScenarios":"Having spring-security-rsocket + the security socket acceptor interceptor configuration on the classpath but never defining an @Bean RSocketSecurity; excluding the auto-configuration that creates it; defining security differently (e.g. custom interceptor) while the default configuration still runs.","commonSituations":"RSocket apps that add the security dependency but skip the @EnableRSocketSecurity / RSocketSecurity bean setup; tests that slice away the security configuration; migration from manual interceptor wiring to auto-configuration.","solutions":["Define an RSocketSecurity bean and enable it, e.g. @Bean RSocketSecurity rSocketSecurity(PayloadSocketAcceptorInterceptor ignored) { return new RSocketSecurity(); } or use @EnableRSocketSecurity","If you wire your own PayloadSocketAcceptorInterceptor, exclude the default SecuritySocketAcceptorInterceptorConfiguration auto-config","Ensure the RSocketSecurity bean is not conditionally skipped in your profile/test setup"],"exampleFix":"// before\n// no RSocketSecurity bean defined\n// after\n@Bean\nRSocketSecurity rSocketSecurity() {\n    return new RSocketSecurity();\n}","handlingStrategy":"validation","validationCode":"if (!context.getBeanNamesForType(RSocketSecurity.class).hasNext()\n        && context.getBeanProvider(RSocketSecurity.class).getIfAvailable() == null) {\n    throw new IllegalStateException(\"Define an RSocketSecurity bean or exclude the RSocket security auto-configuration\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    context.getBean(PayloadSocketAcceptorInterceptor.class);\n} catch (NoSuchBeanDefinitionException e) {\n    // register an RSocketSecurity bean or wire your own interceptor\n}","preventionTips":["When adding spring-security-rsocket, always define an RSocketSecurity bean (or use @EnableRSocketSecurity)","If you wire your own PayloadSocketAcceptorInterceptor, exclude the default interceptor auto-configuration","Smoke-test RSocket endpoints in CI so missing security setup fails fast"],"tags":["spring-security","rsocket","missing-bean","auto-configuration"],"backgroundTag":"missing-dependency","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}