示例#1
0
文件: UserDB.java 项目: sgewuhan/cpm
  /**
   * 得到传入的组织上下文中具有权限的权限对象
   *
   * @param teamList 组织上下文
   * @param targetList 用户或者角色的列表,只能是ID list
   * @param tokenId 权限ID
   * @param targetType 授权类型user还是role
   * @param authValue 授权值,授权为true,否则为false
   * @return 通过权限的组织列表
   */
  @Deprecated
  public static List<DBObject> getTeamContextAuthorityData(
      BasicDBList teamList,
      BasicDBList targetList,
      String tokenId,
      String targetType,
      boolean authValue) {
    DBCollection col = DBActivator.getDefaultDBCollection(COLLECTION_AUTHORITY);

    List<DBObject> result = new ArrayList<DBObject>();

    DBCursor cur =
        col.find(
            new BasicDBObject()
                .append(FIELD_AUTHVALUE, authValue)
                .append(FIELD_TOKENID, tokenId)
                .append(FIELD_TARGETTYPE, targetType)
                .append(FIELD_TARGETID, new BasicDBObject().append("$in", targetList)));

    while (cur.hasNext()) {
      DBObject one = cur.next();
      ObjectId contextId = (ObjectId) one.get(FIELD_CONTEXTID);
      if (teamList.contains(contextId)) {
        result.add(one);
      }
    }

    return result;
  }
示例#2
0
文件: UserDB.java 项目: sgewuhan/cpm
  public static void getParentRoleAndTeam(
      ObjectId userId, BasicDBList roleIdList, BasicDBList teamIdList) {
    // 检查准备回写的数组是否初始化
    Assert.isNotNull(roleIdList);
    Assert.isNotNull(teamIdList);

    // obs的集合
    DBCollection obsCol = DBActivator.getDefaultDBCollection(COLLECTION_OBS);

    // 查询该用户的OBSPARENT
    DBObject ref =
        new BasicDBObject()
            .append(FIELD_USEROID, userId)
            .append(
                FIELD_PROJECT_ROOTOBS,
                new BasicDBObject().append("$exists", false)); // 这种情况是属于项目上下文组织中的用户,跳过

    DBObject keys = new BasicDBObject().append(FIELD_OBS_PARENT, 1);

    DBCursor cur = obsCol.find(ref, keys); // 查询所有的在OBS集合中的USER节点

    // 将这些节点的ID取出备用
    BasicDBList parentIdList = new BasicDBList();

    while (cur.hasNext()) {
      Object parentId = cur.next().get(FIELD_OBS_PARENT);
      if (!parentIdList.contains(parentId)) {
        parentIdList.add(parentId);
      }
    }

    // 查询出这些obs上的节点
    cur =
        obsCol.find(
            new BasicDBObject().append(FIELD__ID, new BasicDBObject().append("$in", parentIdList)));
    while (cur.hasNext()) {
      DBObject obsItem = cur.next();
      Object id = obsItem.get(FIELD__ID);
      if (VALUE_ROLE.equals(obsItem.get(FIELD_OBS_TYPE))) {

        // 如果是角色,需要判断这个角色是否已经加入到了角色列表
        if (roleIdList.contains(id)) {
          continue;
        } else {

          // 将角色加入到角色列表
          roleIdList.add(id);

          // 进一步查询他的obsprent以获得组织
          // 角色的上级一定是组织
          Object parentTeamId = obsItem.get(FIELD_OBS_PARENT);
          if (!teamIdList.contains(parentTeamId)) {
            teamIdList.add(parentTeamId);
          }
        }

      } else if (VALUE_TEAM.equals(obsItem.get(FIELD_OBS_TYPE))) {

        if (!teamIdList.contains(id)) {
          teamIdList.add(id);
        }
      }
    }
  }