示例#1
0
  @Override
  public ResponseVO isUserAuthenticated(String authString, ResponseVO response) throws IOException {
    String decodedAuth = "";
    // Header is in the format "Basic 5tyc0uiDat4"
    // We need to extract data before decoding it back to original string
    // Decode the data back to original string
    byte[] bytes = null;
    new Base64();
    bytes = Base64.decode(authString);
    decodedAuth = new String(bytes);

    String[] decodedAuths = decodedAuth.split(":");

    User user = getUserDetail(decodedAuths[0], decodedAuths[1]);
    if (user == null) {
      response.setSuccess(false);
      response.setError(new Error(222, "Invalid credentials!!"));
    } else {
      String accessToken = ApplicationUtilities.generateAccessToken(user);
      CachedObject newCachedObject = new CachedObject(user.getUuid(), accessToken, 0);
      CacheManager.putCache(newCachedObject);
      response.setSuccess(true);
      // response.setData(new LoggedInUserVO(accessToken,user.getEmailAddress()));
    }
    return response;
  }
示例#2
0
  @Override
  public void map(LongWritable ikey, Text ivalue, Context context)
      throws IOException, InterruptedException {
    // TODO Auto-generated method stub
    String line = ivalue.toString();
    int index = line.indexOf('\t');
    if (index < 0) return;

    int bIndex = line.indexOf(':');
    if (bIndex < 0) return;

    double val = Double.parseDouble(line.substring(0, bIndex));

    try {
      int pIndex = model.cIndex(val);
      if (pIndex < li || pIndex > ri) return;

      String cb = line.substring(bIndex + 1, index);
      String b = new String(util.Dec(SecurityUtility.K, Base64.decode(cb.getBytes())));

      if (pIndex == li) {
        if (b.equals(bl) && val < left) return;
        if (bl.equals("0") && b.equals("1")) return;
      }

      if (pIndex == ri) {
        if (b.equals(bl) && val > right) return;
        if (br.equals("1") && b.equals("0")) return;
      }

      long p = model.decRng(val, b);

      String cextra = line.substring(index + 1);
      String pextra = new String(util.Dec(SecurityUtility.K, Base64.decode(cextra.getBytes())));
      context.write(new LongWritable(p), new Text(pextra));
    } catch (Exception e) {
      // TODO: handle exception
      System.err.println(StringUtils.stringifyException(e));
    }
  }
  @POST
  @Path("/update")
  @Consumes(value = "application/json")
  @Override
  public void update(Record record) {
    this.LOGGER.debug("update(), record: {}", record);

    if (record == null) return;
    if (record.getName() == null) return;
    if (record.getPath() == null) return;

    if (record.getBinary() != null && !record.getBinary().isEmpty()) {
      final String encodedString = record.getBinary();
      byte[] decodedBuffer = Base64.decode(encodedString);

      File file = new File(record.getPath());
      if (!file.exists()) {
        file.mkdirs();
      }

      try {
        FileOutputStream outstream =
            new FileOutputStream(record.getPath().concat(record.getName()));
        outstream.write(decodedBuffer);
        outstream.flush();
        outstream.close();
      } catch (FileNotFoundException fnfe) {
        this.LOGGER.error(fnfe.getMessage());
        Response.status(Status.INTERNAL_SERVER_ERROR).build();
      } catch (IOException ioe) {
        this.LOGGER.error(ioe.getMessage());
        Response.status(Status.INTERNAL_SERVER_ERROR).build();
      }
    }

    final Record updatedRecord = this.recordService.update(record);
  }
  public Response authAdmin(HttpHeaders header) {
    try {
      String authorization = header.getRequestHeader(HttpHeaders.AUTHORIZATION).get(0);

      byte[] authorizationArr = Base64.decode(authorization);

      authorization = new String(authorizationArr, "UTF-8");

      String[] authArr = authorization.split(":");

      if (authArr.length == 2) {
        String username = authArr[0];
        String password = authArr[1];

        logger.info("Trying login of admin  {}", username);
        try {
          AuthorizationHandler auth = new AuthorizationHandler();
          AuthTransfer type = auth.authAdmin(username, password);
          return Response.status(Status.OK).entity(type).build();
        } catch (WrongPasswordException e) {
          logger.error("", e);
          return Response.status(Status.UNAUTHORIZED).build();
        } catch (NoUserFoundException e) {
          logger.error("", e);
          return Response.status(Status.NOT_FOUND).build();
        } catch (Exception e) {
          logger.error("", e);
          return Response.status(Status.INTERNAL_SERVER_ERROR).build();
        }
      }
    } catch (UnsupportedEncodingException e) {
      logger.error("", e);
    }

    return Response.status(Status.BAD_REQUEST).build();
  }
示例#5
0
  @GET
  @Path("flowStats/{cluster}/{user}/{appId}")
  @Produces(MediaType.APPLICATION_JSON)
  public PaginatedResult<Flow> getJobFlowStats(
      @PathParam("cluster") String cluster,
      @PathParam("user") String user,
      @PathParam("appId") String appId,
      @QueryParam("version") String version,
      @QueryParam("startRow") String startRowParam,
      @QueryParam("startTime") long startTime,
      @QueryParam("endTime") long endTime,
      @QueryParam("limit") @DefaultValue("100") int limit,
      @QueryParam("includeJobs") boolean includeJobs)
      throws IOException {
    LOG.info(
        "Fetching flowStats for flowStats/{cluster}/{user}/{appId} with input query: "
            + "flowStats/"
            + cluster
            + SLASH // + user /{appId} cluster + " user " + user
            + appId
            + "?version="
            + version
            + "&limit="
            + limit
            + "&startRow="
            + startRowParam
            + "&startTime="
            + startTime
            + "&endTime="
            + endTime
            + "&includeJobs="
            + includeJobs);

    Stopwatch timer = new Stopwatch().start();
    byte[] startRow = null;
    if (startRowParam != null) {
      startRow = Base64.decode(startRowParam);
    }

    if (includeJobs) {
      serializationContext.set(
          new SerializationContext(
              SerializationContext.DetailLevel.FLOW_SUMMARY_STATS_WITH_JOB_STATS));
    } else {
      serializationContext.set(
          new SerializationContext(SerializationContext.DetailLevel.FLOW_SUMMARY_STATS_ONLY));
    }

    if (endTime == 0) {
      endTime = Long.MAX_VALUE;
    }

    if ((limit == 0) || (limit == Integer.MAX_VALUE)) {
      limit = Integer.MAX_VALUE - 1;
    }

    List<Flow> flows =
        getJobHistoryService()
            .getFlowTimeSeriesStats(
                cluster, user, appId, version, startTime, endTime, limit + 1, startRow);
    PaginatedResult<Flow> flowStatsPage = new PaginatedResult<Flow>(limit);
    // add request parameters
    flowStatsPage.addRequestParameter("user", user);
    flowStatsPage.addRequestParameter("appId", appId);
    if (StringUtils.isNotBlank(version)) {
      flowStatsPage.addRequestParameter("version", version);
    } else {
      flowStatsPage.addRequestParameter("version", "all");
    }

    flowStatsPage.addRequestParameter("startTime", Long.toString(startTime));
    flowStatsPage.addRequestParameter("endTime", Long.toString(endTime));
    flowStatsPage.addRequestParameter("limit", Integer.toString(limit));

    if (startRow != null) {
      flowStatsPage.addRequestParameter("startRow", startRowParam);
    }

    if (includeJobs) {
      flowStatsPage.addRequestParameter("includeJobs", "true");
    } else {
      flowStatsPage.addRequestParameter("includeJobs", "false");
    }

    if (flows.size() > limit) {
      // copy over the last excluding the last element
      // the last element is the start row for next page
      flowStatsPage.setValues(flows.subList(0, limit));
      flowStatsPage.setNextStartRow(new FlowKeyConverter().toBytes(flows.get(limit).getFlowKey()));
    } else {
      flowStatsPage.setNextStartRow(null);
      flowStatsPage.setValues(flows);
    }
    timer.stop();

    LOG.info(
        "For flowStats/{cluster}/{user}/{appId} with input query: "
            + "flowStats/"
            + cluster
            + SLASH // + user /{appId} cluster + " user " + user
            + appId
            + "?version="
            + version
            + "&limit="
            + limit
            + "&startRow="
            + startRow
            + "&startTime="
            + startTime
            + "&endTime="
            + endTime
            + "&includeJobs="
            + includeJobs
            + " fetched "
            + flows.size()
            + " in "
            + timer);
    return flowStatsPage;
  }