use of com.djrapitops.plan.delivery.web.resolver.Resolver in project Plan by plan-player-analytics.
the class ResponseResolver method tryToGetResponse.
/**
* @throws NotFoundException In some cases when page was not found, not all.
* @throws ForbiddenException If the user is not allowed to see the page
* @throws BadRequestException If the request did not have required things.
*/
private Response tryToGetResponse(Request request) {
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
return Response.builder().setStatus(204).build();
}
Optional<WebUser> user = request.getUser();
List<Resolver> foundResolvers = resolverService.getResolvers(request.getPath().asString());
if (foundResolvers.isEmpty())
return responseFactory.pageNotFound404();
for (Resolver resolver : foundResolvers) {
boolean isAuthRequired = webServer.get().isAuthRequired() && resolver.requiresAuth(request);
if (isAuthRequired) {
if (!user.isPresent()) {
if (webServer.get().isUsingHTTPS()) {
throw new WebUserAuthException(FailReason.NO_USER_PRESENT);
} else {
return responseFactory.forbidden403();
}
}
if (resolver.canAccess(request)) {
Optional<Response> resolved = resolver.resolve(request);
if (resolved.isPresent())
return resolved.get();
} else {
return responseFactory.forbidden403();
}
} else {
Optional<Response> resolved = resolver.resolve(request);
if (resolved.isPresent())
return resolved.get();
}
}
return responseFactory.pageNotFound404();
}
Aggregations