@Override
  public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain)
      throws Exception {
    final String graphEdgeId = getAttributeString(request, "graphEdgeId");
    final String visibilitySource = getRequiredParameter(request, "visibilitySource");

    User user = getUser(request);
    Authorizations authorizations = getAuthorizations(request, user);
    String workspaceId = getActiveWorkspaceId(request);

    Edge graphEdge = graph.getEdge(graphEdgeId, authorizations);
    if (graphEdge == null) {
      respondWithNotFound(response);
      return;
    }

    if (!graph.isVisibilityValid(new Visibility(visibilitySource), authorizations)) {
      LOGGER.warn(
          "%s is not a valid visibility for %s user", visibilitySource, user.getDisplayName());
      respondWithBadRequest(response, "visibilitySource", getString(request, "visibility.invalid"));
      chain.next(request, response);
      return;
    }

    LOGGER.info(
        "changing edge (%s) visibility source to %s",
        graphEdge.getId().toString(), visibilitySource);

    GraphUtil.VisibilityAndElementMutation<Edge> setPropertyResult =
        GraphUtil.updateElementVisibilitySource(
            visibilityTranslator,
            graphEdge,
            GraphUtil.getSandboxStatus(graphEdge, workspaceId),
            visibilitySource,
            workspaceId,
            authorizations);
    auditRepository.auditEdgeElementMutation(
        AuditAction.UPDATE,
        setPropertyResult.elementMutation,
        graphEdge,
        graphEdge.getVertex(Direction.OUT, authorizations),
        graphEdge.getVertex(Direction.IN, authorizations),
        "",
        user,
        setPropertyResult.visibility.getVisibility());

    this.graph.flush();

    this.workQueueRepository.pushGraphPropertyQueue(
        graphEdge,
        null,
        LumifyVisibilityProperties.VISIBILITY_JSON_PROPERTY.getPropertyName(),
        workspaceId,
        visibilitySource);

    JSONObject json = JsonSerializer.toJson(graphEdge, workspaceId, authorizations);
    respondWithJson(response, json);
  }
Exemple #2
0
  private int delete(CommandLine cmd) {
    User user = findUser(cmd);
    if (user == null) {
      printUserNotFoundError(cmd);
      return 2;
    }

    getUserRepository().delete(user);
    System.out.println("Deleted user " + user.getUserId());
    return 0;
  }
Exemple #3
0
  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain)
      throws Exception {
    final String username = UrlUtils.urlDecode(request.getParameter("username"));

    User user = getUserRepository().findByUsername(username);
    if (user == null) {
      // For form based authentication, username and displayName will be the same
      String randomPassword = UserRepository.createRandomPassword();
      user = getUserRepository().addUser(username, username, null, randomPassword, new String[0]);
    }
    getUserRepository().recordLogin(user, AuthenticationHandler.getRemoteAddr(request));

    CurrentUser.set(request, user.getUserId(), user.getUsername());
    JSONObject json = new JSONObject();
    json.put("status", "OK");
    respondWithJson(response, json);
  }
Exemple #4
0
  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain)
      throws Exception {
    User user = getUser(request);
    String email = getRequiredParameter(request, EMAIL_PARAMETER_NAME);

    if (user != null) {
      if (email.length() > 0) {
        getUserRepository().setEmailAddress(user, email);
        LOGGER.info("changed email for user: %s", user.getUsername());
        respondWithSuccessJson(response);
      } else {
        respondWithBadRequest(response, EMAIL_PARAMETER_NAME, "new email may not be blank");
      }
    } else {
      LOGGER.error("current user not found while attempting to change email");
      respondWithAccessDenied(response, "current user not found");
    }
  }
Exemple #5
0
 private void printUser(User user) {
   System.out.println("                        ID: " + user.getUserId());
   System.out.println("                  Username: "******"            E-Mail Address: " + valueOrBlank(user.getEmailAddress()));
   System.out.println("              Display Name: " + user.getDisplayName());
   System.out.println("               Create Date: " + valueOrBlank(user.getCreateDate()));
   System.out.println("        Current Login Date: " + valueOrBlank(user.getCurrentLoginDate()));
   System.out.println(
       " Current Login Remote Addr: " + valueOrBlank(user.getCurrentLoginRemoteAddr()));
   System.out.println("       Previous Login Date: " + valueOrBlank(user.getPreviousLoginDate()));
   System.out.println(
       "Previous Login Remote Addr: " + valueOrBlank(user.getPreviousLoginRemoteAddr()));
   System.out.println("               Login Count: " + user.getLoginCount());
   System.out.println(
       "                Privileges: "
           + privilegesAsString(getUserRepository().getPrivileges(user)));
   System.out.println(
       "            Authorizations: "
           + authorizationsAsString(getUserRepository().getAuthorizations(user)));
   System.out.println("");
 }
Exemple #6
0
  private int setPrivileges(CommandLine cmd) {
    String privilegesString = cmd.getOptionValue(CMD_OPT_PRIVILEGES);
    Set<Privilege> privileges = null;
    if (privilegesString != null) {
      privileges = Privilege.stringToPrivileges(privilegesString);
    }

    User user = findUser(cmd);
    if (user == null) {
      printUserNotFoundError(cmd);
      return 2;
    }

    if (privileges != null) {
      System.out.println("Assigning privileges " + privileges + " to user " + user.getUserId());
      getUserRepository().setPrivileges(user, privileges);
      user = getUserRepository().findById(user.getUserId());
    }

    printUser(user);
    return 0;
  }
  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain)
      throws Exception {
    final String artifactId = getRequiredParameter(request, "artifactId");
    final String propertyKey = getRequiredParameter(request, "propertyKey");
    final long mentionStart = getRequiredParameterAsLong(request, "mentionStart");
    final long mentionEnd = getRequiredParameterAsLong(request, "mentionEnd");
    final String title = getRequiredParameter(request, "sign");
    final String conceptId = getRequiredParameter(request, "conceptId");
    final String visibilitySource = getRequiredParameter(request, "visibilitySource");
    final String resolvedVertexId = getOptionalParameter(request, "resolvedVertexId");
    final String justificationText = getOptionalParameter(request, "justificationText");
    final String sourceInfo = getOptionalParameter(request, "sourceInfo");
    String termMentionRowKeyString = getOptionalParameter(request, "rowKey");

    User user = getUser(request);
    String workspaceId = getActiveWorkspaceId(request);
    Workspace workspace = workspaceRepository.findById(workspaceId, user);

    Authorizations authorizations = getAuthorizations(request, user);

    JSONObject visibilityJson =
        GraphUtil.updateVisibilitySourceAndAddWorkspaceId(null, visibilitySource, workspaceId);
    LumifyVisibility visibility = this.visibilityTranslator.toVisibility(visibilityJson);
    if (!graph.isVisibilityValid(visibility.getVisibility(), authorizations)) {
      LOGGER.warn(
          "%s is not a valid visibility for %s user", visibilitySource, user.getDisplayName());
      respondWithBadRequest(response, "visibilitySource", STRINGS.getString("visibility.invalid"));
      chain.next(request, response);
      return;
    }

    Object id = resolvedVertexId == null ? graph.getIdGenerator().nextId() : resolvedVertexId;

    Concept concept = ontologyRepository.getConceptByIRI(conceptId);

    final Vertex artifactVertex = graph.getVertex(artifactId, authorizations);
    LumifyVisibility lumifyVisibility = visibilityTranslator.toVisibility(visibilityJson);
    Map<String, Object> metadata = new HashMap<String, Object>();
    LumifyVisibilityProperties.VISIBILITY_JSON_PROPERTY.setMetadata(metadata, visibilityJson);
    ElementMutation<Vertex> vertexMutation;
    Vertex vertex;
    if (resolvedVertexId != null) {
      vertex = graph.getVertex(id, authorizations);
      vertexMutation = vertex.prepareMutation();
    } else {
      vertexMutation = graph.prepareVertex(id, lumifyVisibility.getVisibility());
      GraphUtil.addJustificationToMutation(
          vertexMutation, justificationText, sourceInfo, lumifyVisibility);

      CONCEPT_TYPE.setProperty(
          vertexMutation, conceptId, metadata, lumifyVisibility.getVisibility());
      TITLE.addPropertyValue(
          vertexMutation, MULTI_VALUE_KEY, title, metadata, lumifyVisibility.getVisibility());

      vertex = vertexMutation.save(authorizations);

      auditRepository.auditVertexElementMutation(
          AuditAction.UPDATE, vertexMutation, vertex, "", user, lumifyVisibility.getVisibility());

      LumifyVisibilityProperties.VISIBILITY_JSON_PROPERTY.setProperty(
          vertexMutation, visibilityJson, metadata, lumifyVisibility.getVisibility());

      this.graph.flush();

      workspaceRepository.updateEntityOnWorkspace(
          workspace, vertex.getId(), false, null, null, user);
    }

    // TODO: a better way to check if the same edge exists instead of looking it up every time?
    Edge edge =
        graph.addEdge(
            artifactVertex,
            vertex,
            this.artifactHasEntityIri,
            lumifyVisibility.getVisibility(),
            authorizations);
    LumifyVisibilityProperties.VISIBILITY_JSON_PROPERTY.setProperty(
        edge, visibilityJson, metadata, lumifyVisibility.getVisibility(), authorizations);

    auditRepository.auditRelationship(
        AuditAction.CREATE,
        artifactVertex,
        vertex,
        edge,
        "",
        "",
        user,
        lumifyVisibility.getVisibility());

    TermMentionRowKey termMentionRowKey;
    if (termMentionRowKeyString != null) {
      termMentionRowKey = new TermMentionRowKey(RowKeyHelper.jsonDecode(termMentionRowKeyString));
    } else {
      termMentionRowKey =
          new TermMentionRowKey(
              artifactId, propertyKey, mentionStart, mentionEnd, edge.getId().toString());
    }
    TermMentionModel termMention = new TermMentionModel(termMentionRowKey);
    termMention
        .getMetadata()
        .setSign(title, lumifyVisibility.getVisibility())
        .setOntologyClassUri(concept.getDisplayName(), lumifyVisibility.getVisibility())
        .setConceptGraphVertexId(concept.getTitle(), lumifyVisibility.getVisibility())
        .setVertexId(vertex.getId().toString(), lumifyVisibility.getVisibility())
        .setEdgeId(edge.getId().toString(), lumifyVisibility.getVisibility());
    termMentionRepository.save(termMention);

    vertexMutation.addPropertyValue(
        graph.getIdGenerator().nextId().toString(),
        LumifyProperties.ROW_KEY.getPropertyName(),
        termMentionRowKey.toString(),
        metadata,
        lumifyVisibility.getVisibility());
    vertexMutation.save(authorizations);

    this.graph.flush();
    workQueueRepository.pushTextUpdated(artifactId);

    workQueueRepository.pushElement(edge);

    JSONObject result = new JSONObject();
    result.put("success", true);
    respondWithJson(response, result);
  }
Exemple #8
0
 private void printUsers(Iterable<User> users) {
   if (users != null) {
     int maxCreateDateWidth = 1;
     int maxIdWidth = 1;
     int maxUsernameWidth = 1;
     int maxEmailAddressWidth = 1;
     int maxDisplayNameWidth = 1;
     int maxLoginCountWidth = 1;
     int maxPrivilegesWidth = privilegesAsString(Privilege.ALL).length();
     for (User user : users) {
       maxCreateDateWidth = maxWidth(user.getCreateDate(), maxCreateDateWidth);
       maxIdWidth = maxWidth(user.getUserId(), maxIdWidth);
       maxUsernameWidth = maxWidth(user.getUsername(), maxUsernameWidth);
       maxEmailAddressWidth = maxWidth(user.getEmailAddress(), maxEmailAddressWidth);
       maxDisplayNameWidth = maxWidth(user.getDisplayName(), maxDisplayNameWidth);
       maxLoginCountWidth = maxWidth(Integer.toString(user.getLoginCount()), maxLoginCountWidth);
     }
     String format =
         String.format(
             "%%%ds %%%ds %%%ds %%%ds %%%ds %%%dd %%%ds%%n",
             -1 * maxCreateDateWidth,
             -1 * maxIdWidth,
             -1 * maxUsernameWidth,
             -1 * maxEmailAddressWidth,
             -1 * maxDisplayNameWidth,
             maxLoginCountWidth,
             -1 * maxPrivilegesWidth);
     for (User user : users) {
       System.out.printf(
           format,
           valueOrBlank(user.getCreateDate()),
           user.getUserId(),
           user.getUsername(),
           valueOrBlank(user.getEmailAddress()),
           user.getDisplayName(),
           user.getLoginCount(),
           privilegesAsString(getUserRepository().getPrivileges(user)));
     }
   } else {
     System.out.println("No users");
   }
 }