Problem
I'm currently building an application using Quarkus (2.9.2.Final). The project contains multiple modules that depend on each other. The usecase
module contains the interfaces for the repositories of the repository
module. I now want to restrict access to the data, depending on some business-rules. Therefore, I added a decorator with the @Decorator annotation to the usecase
module that decorates the repository interfaces.
The decorator runs and gets called before the call is delegated to the concrete bean. However, after that there seems to be a recursion happening somewhere, which triggers the decorator again, and so on and so forth. The repositories also have an @Interceptor that logs method calls.
Here is some sample code of what I have in the decorator (usecase
module)
@Decorator
public class MyDecorator implements SomeRepository {
@Inject
@Delegate
@Any
SomeRepository delegate;
private boolean canAccess() // check business-rules if access is allowed
@Override
public Entity get(Long id) {
var cannotAccess = !canAccess();
if (cannotAccess) {
throw new RuntimeException("Access not allowed");
}
return delegate.get(id);
}
// other repository methods skipped for brevity
}
and the repository (repository
module)
@ApplicationScoped
public class DefaultSomeRepositoryRepository implements SomeRepository {
// inject some dependencies here
@Override
public Entity get(Long id) {
// retrieve data from database
// calls should only end up here, when access
// has already been checked and allowed
return new Entity();
}
// other repository methods skipped for brevity
}
What I've tried
- Adding, changing the priority of the Decorator/Interceptor classes
- Removing the Interceptor
- Making the decorator abstract