我试图创建一个方面来在调用
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");
}
}
}
有什么建议吗?
我刚刚发现:
ServerSecurityContextRepository
在我的应用程序中没有作为bean公开(在我的代码中用new
实例化)=>Spring不可能用AOP来检测它...