示例#1
0
  @Override
  public void handle(Request request, Response response)
      throws UnauthorizedException, ForbiddenException, InternalServerException {
    Boolean authenticated, authorized;
    String challenge;

    try {
      authenticated =
          getAuth()
              .authenticate(
                  request.requestMethod(), request.uri(), request.headers("Authorization"));
      authorized = getAuth().authorize(request.requestMethod());
      challenge = getAuth().challenge();
    } catch (UnloadableConfigException | InvalidPropertyException | RuntimeException e) {
      throw new InternalServerException(e);
    }

    if (!authenticated) {
      response.header("WWW-Authenticate", challenge);
      throw new UnauthorizedException();
    }

    if (!authorized) {
      throw new ForbiddenException();
    }
  }
示例#2
0
 public static byte[] getOrigin(Request req, Response res) {
   res.header("Content-Type", "application/octet-stream");
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   int x = Integer.parseInt(req.params("x"));
   int y = Integer.parseInt(req.params("y").replaceFirst("\\.dat$", ""));
   StaticSiteRequest.PointRequest pr = staticSiteRequest.getPointRequest(x, y);
   StaticComputer computer = new StaticComputer(pr, network, new TaskStatistics());
   try {
     computer.write(baos);
     return baos.toByteArray();
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
示例#3
0
 @Override
 public void header(String header, String value) {
   delegate.header(header, value);
 }
示例#4
0
 public static byte[] getTransitiveNetwork(Request req, Response res) {
   res.header("Content-Type", "application/json");
   return transitive;
 }
示例#5
0
 public static byte[] getStopTrees(Request req, Response res) {
   res.header("Content-Type", "application/octet-stream");
   return stopTrees;
 }
示例#6
0
 /** get a query json file */
 public static byte[] getQuery(Request req, Response res) {
   res.header("Content-Type", "application/json");
   return metadata;
 }