我目前遇到的问题是,在认为身份验证有效的异步请求完成之前,我的HTTP请求被发送到“处理阶段”。
以下是导致此问题的过滤器示例:
@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);
}
}
}
如何在异步请求完成之前,请求不会进入“处理阶段”。 (民意调查mydatabase)。