オブジェクトをオブジェクト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
}
}