当前位置: 首页 > 知识库问答 >
问题:

阻止SpringSecurity创建基于cglib的代理

夏宏旷
2023-03-14

我正在使用spring-boot 2.3.9和spring-security以及keycloak 12.0.4。

@Configuration
@KeycloakConfiguration
@ConditionalOnProperty("keycloak.enabled")
@Import(KeycloakSpringBootConfigResolver.class)
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, proxyTargetClass = false) // If I exclude this, no cglib based proxy is created, but @Secured is not applied either
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {

和我的服务bean创建配置

@Configuration(proxyBeanMethods = false)
public class EnvironmentConfig {

    @Bean
    // @Scope(proxyMode = ScopedProxyMode.INTERFACES) // Has no effect
    MyServiceInterfaceSecured myService() { new ImplA/ImplB/ImplC() }

}
09:56:38.828 DEBUG [,] --- [main] m.DelegatingMethodSecurityMetadataSource : Caching method [CacheKey[example.MyServiceImplA; ...] with attributes [...]
09:57:12.992  INFO [,] --- [main] o.s.a.f.CglibAopProxy                    : Unable to proxy interface-implementing method [public final java.util.List example.MyServiceImplA.sync()] because it is marked as final: Consider using interface-based JDK proxies instead!
09:57:12.992 DEBUG [,] --- [main] o.s.a.f.CglibAopProxy                    : Final method [public final java.util.List example.MyServiceImplA.sync()] cannot get proxied via CGLIB: Calls to this method will NOT be routed to the target instance and might lead to NPEs against uninitialized fields in the proxy instance.

编辑:这可能与Spring-Cloud-Starter-Sleuth有关。如果我移除这个依赖关系,所有的事情就会像预期的那样工作。但我也需要侦探。

共有1个答案

徐麒
2023-03-14

我通过排除spring-boot-starter-aop和spring-cloud-starter-sleuth来修复它。

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-aop</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
 类似资料:
  • 本文向大家介绍Spring基于ProxyFactoryBean创建AOP代理,包括了Spring基于ProxyFactoryBean创建AOP代理的使用技巧和注意事项,需要的朋友参考一下 Spring 通知类型 通过前面的学习可以知道,通知(Advice)其实就是对目标切入点进行增强的内容,Spring AOP 为通知(Advice)提供了 org.aopalliance.aop.Advice 接

  • 我试图从服务创建一个基于WSDL的代理。此服务运行在tomcat服务器中,该服务器已配置为只接受使用TLSV1.2的安全连接。并且该服务在运行wso2server的intranet之外。 当我测试基于wsdl的代理模板中的wsdl uri时,问题就会出现,并启动系统以下警报:“无效的wsdl uri(无法建立连接)”。我不得不说,wso2esb与外部有连接,问题不在于访问这个url,因为: nul

  • 问题内容: 这个问题解决了。 我正在开发一个基于Java Swing的项目,并且该应用程序的外观是完全自定义的。我们试图在整个程序中保持一致的外观,并且默认的Java对话框窗口不同。 当前问题要求控件禁止调用用户提示。与JOptionPane.showConfirmDialog()相似,在这种情况下,静态调用将产生一个窗口,并暂停程序的流程,直到用户选择一个选项为止。它还返回选项的值。请注意,GU

  • 我重新启动服务器和浏览器,因此没有会话数据 我去www.someurl。com公共访问页。我的控制器用这个HttpSession session=request给我一个会话。getSession(true) <李> 我点击一个指向www.someurl的平面锚链接。在新选项卡中打开的com/admin受限访问页面。Spring Security 3拦截了这一点,并对凭据提出了挑战。我成功登录 我返

  • 在使用spring Cglib代理时,我们需要实现一个MethodInterceptor回调,我对这个回调有一些问题。为了让它更清楚,让我们使用一个简单的例子。 下面是我的目标类MyPlay.java 我创建了一个回调: 在我的主要班级: 我对intercept方法的参数的含义感到困惑: 问题:和参数是什么?它们之间有什么区别?当我使用methodProxy调用时,它也起作用,这让我感到困惑。