我使用AOP
建议将User
对象转换为Owner
对象。转换是在建议中完成的,但我想将该Owner
对象传递给调用者。
@Aspect
public class UserAuthAspect {
@Inject
private OwnerDao ownerDao;
@Pointcut("@annotation(com.google.api.server.spi.config.ApiMethod)")
public void annotatedWithApiMethod() {
}
@Pointcut("execution(* *.*(.., com.google.appengine.api.users.User)) && args(.., user)")
public void allMethodsWithUserParameter(User user) {
}
@Before("annotatedWithApiMethod() && allMethodsWithUserParameter(user)")
public void checkUserLoggedIn(com.google.appengine.api.users.User user)
throws UnauthorizedException {
if (user == null) {
throw new UnauthorizedException("Must log in");
}
Owner owner = ownerDao.readByUser(user);
}
}
具有建议方法的类:
public class RealEstatePropertyV1 {
@ApiMethod(name = "create", path = "properties", httpMethod = HttpMethod.POST)
public void create(RealEstateProperty property, User user) throws Exception {
Owner owner = the value set by the advice
}
}