如何在ServerSecurityContextRepository上定义切入点?

问题描述 投票:0回答:1

我试图创建一个方面来在调用

ServerSecurityContextRepository.save(ServerWebExchange exchange, SecurityContext context)
之前执行代码,但我无法让我的切入点工作。

这是我迄今为止尝试过的:

@Aspect
@Component
@Slf4j
public static class ServerSecurityContextRepositoryAspect {

    @Pointcut("within(org.springframework.security.web.server.context.ServerSecurityContextRepository+) && execution(* *.save(..))")
    public void securityContextSaved() {
    }

    @Before("securityContextSaved()")
    public void beforeSecurityContextSaved(JoinPoint jp) {
        log.error("%d".formatted(jp.getArgs().length));
        if (jp.getArgs().length != 2) {
            log.warn("oups");
        }
        if (jp.getArgs()[1] == null) {
            log.warn("SecurityContext destroyed");
        } else {
            log.warn("SecurityContext saved");
        }
    }
}

有什么建议吗?

spring aspectj spring-aop
1个回答
0
投票

我刚刚发现:

ServerSecurityContextRepository
在我的应用程序中没有作为bean公开(在我的代码中用
new
实例化)=>Spring不可能用AOP来检测它...

© www.soinside.com 2019 - 2024. All rights reserved.