英文:
How to define a pointcut on ServerSecurityContextRepository?
问题
我正在尝试创建一个在调用 `ServerSecurityContextRepository.save(ServerWebExchange exchange, SecurityContext context)` 方法之前执行代码的切面,但我无法使我的切入点起作用。
以下是我迄今为止尝试过的内容:
```java
@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");
}
}
}
有任何建议吗?
<details>
<summary>英文:</summary>
I'm trying to create an aspect to execute code before `ServerSecurityContextRepository.save(ServerWebExchange exchange, SecurityContext context)` is called, but I couldn't get my pointcut working.
Here is what I tried so far:
```java
@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");
}
}
}
Any suggestion?
答案1
得分: 0
ServerSecurityContextRepository
没有作为一个bean在我的应用程序中暴露(在我的代码中使用new
实例化)=> Spring不可能使用AOP来对其进行处理...
英文:
I just figured it out: ServerSecurityContextRepository
is not exposed as a bean in my application (instantiated with a new
in my code) => no chance that Spring can instrument it with AOP...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论