I'm currently running into an issue where my HTTP Request is being sent into the "processing phase" before the asynchronous request that deems if authentication is valid is completed.
Here is an example of the filter causing the issue:
@Provider
public class AuthenticationFilter implements ContainerRequestFilter {
private static final Response ACCESS_DENIED = Response.status(Response.Status.UNAUTHORIZED).build();
private static final Response INTERNAL_SERVER_ERROR = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
@Context
private ResourceInfo resourceInfo;
@Override
public void filter(final ContainerRequestContext context) throws IOException {
System.out.println("Filter called");
Method method = resourceInfo.getResourceMethod();
if(method.isAnnotationPresent(NoAuthorizationRequired.class)) {
return;
}
if(method.isAnnotationPresent(AuthorizationRequired.class)) {
AuthorizationRequest request = (new AuthorizationRequest(false) {
@Override
public void onCompleted(ParallelResult superResult) {
AuthorizationResult result = (AuthorizationResult)superResult;
if(result.successful()) {
System.out.println("Authentication completed -- Process resource");
} else {
context.abortWith(ACCESS_DENIED);
}
}
});
request.setTask(new AuthorizationTask(request));
Worker.work(request);
} else {
System.err.println("[SEVERE] IMPLEMENTATION FAULT. Authorization annotation not found for method: " + method.getName());
context.abortWith(INTERNAL_SERVER_ERROR);
}
}
}
How can I make it so the request will not enter "processing phase" until the asynchornous request is completed. (Polls mydatabase).