/**
   * 根据已有授权信息,新增一条授权信息。 新增前会先判断授权信息是否已经存在。
   *
   * @param exsitPermission 节点的未补齐授权信息 或 父(祖)节点授权信息
   * @param resource 节点资源
   * @param permissionTable
   *     <p>TODO 保存权限前要在当前授权级别的上一级去查找有没有已经授过的,如果授过的,则删掉。 保存当前授权级别(一个资源对同一个权限选项只能有一种授权级别)
   */
  public void createPermission(
      AbstractPermission exsitPermission, IResource resource, String permissionTable) {
    String operationId = exsitPermission.getOperationId();
    Long roleId = exsitPermission.getRoleId();
    Integer permissionState = exsitPermission.getPermissionState();
    Integer isGrant = exsitPermission.getIsGrant();
    Integer isPass = exsitPermission.getIsPass();

    // 先判断授权信息是否已经存在
    Class<?> permissionTableClass = BeanUtil.createClassByName(permissionTable);
    String hql =
        "from "
            + permissionTableClass.getName()
            + " t  where t.resourceId = ? and t.operationId = ?"
            + " and t.roleId = ? and t.permissionState = ? and t.isGrant = ? and t.isPass = ?";

    Long resourceId = resource.getId();
    List<?> list =
        getEntities(
            hql, new Object[] {resourceId, operationId, roleId, permissionState, isGrant, isPass});
    if (list.size() == 0) {
      AbstractPermission newPermission =
          (AbstractPermission) BeanUtil.newInstance(permissionTableClass);
      newPermission.setOperationId(operationId);
      newPermission.setRoleId(roleId);
      newPermission.setPermissionState(permissionState);
      newPermission.setIsGrant(isGrant);
      newPermission.setIsPass(isPass);

      newPermission.setResourceId(resourceId);
      newPermission.setResourceName(resource.getName());

      createObjectWithoutFlush(newPermission);
    }
  }
  public AppServer getAppServer(String appCode) {
    if (cache.get(appCode) != null) {
      return cache.get(appCode);
    }

    String appServerXML = null;
    try {
      // 读取appServer配置不依赖Spring容器,因某些bean初始化本身就要用到AppServer
      appServerXML = ParamManager.getValueNoSpring(appCode);
    } catch (Exception e) {
    }

    if (appServerXML == null) {
      throw new BusinessException("参数管理模块中尚没有应用Code为:" + appCode + " 的应用服务配置信息");
    }

    try {
      Element appServerNode = XMLDocUtil.dataXml2Doc(appServerXML).getRootElement();
      Map<String, String> attrsMap = XMLDocUtil.dataNode2Map(appServerNode);

      AppServer bean = new AppServer();
      BeanUtil.setDataToBean(bean, attrsMap);

      cache.put(appCode, bean);
      return bean;
    } catch (Exception e) {
      throw new BusinessException("参数管理模块中应用Code为:" + appCode + " 的应用服务配置信息有误,请检查!");
    }
  }
Example #3
0
  public Map<String, Object> getAttributes4XForm() {
    Map<String, Object> map = new HashMap<String, Object>();
    BeanUtil.addBeanProperties2Map(this, map);

    map.put("startDate", DateUtil.format(startDate));
    map.put("endDate", DateUtil.format(endDate));
    return map;
  }
  /**
   * 获取用户对一个应用中的一种资源类型中的一个资源拥有的权限选项ID集合
   *
   * @param resourceTypeId
   * @param resourceId
   * @param userId
   * @return
   */
  public List<?> getOperationsByResource(String resourceTypeId, Long resourceId) {
    String applicationId = PermissionHelper.getApplicationID();
    String permissionTable = resourceTypeDao.getPermissionTable(applicationId, resourceTypeId);
    String resourceTable = resourceTypeDao.getResourceTable(applicationId, resourceTypeId);

    Class<?> resourceClass = BeanUtil.createClassByName(resourceTable);

    return getOperationsByResource(resourceId, permissionTable, resourceClass);
  }
  /**
   * 获取用户对一个资源在当前授权级别能够看到的子节点的个数
   *
   * @param resourceId
   * @param permissionRank
   * @param permissionTable
   * @param resourceTable
   * @return
   */
  public int getVisibleChildrenNumByPermissionRank(
      Long resourceId, String permissionRank, String permissionTable, String resourceTable) {
    String hql =
        "select distinct r.id from "
            + resourceTable
            + " r, "
            + permissionTable
            + " p, Temp t "
            + " where t.id = p.roleId and p.resourceId = r.id and r.decode like ? ";
    hql += genRankCondition4SelectPermission(permissionRank);

    IResource resource =
        (IResource) getEntity(BeanUtil.createClassByName(resourceTable), resourceId);
    return getEntities(hql, resource.getDecode() + "%").size();
  }
  /**
   * 创建一条授权信息(未补齐)
   *
   * @param roleId
   * @param resourceId
   * @param operationId
   * @param permissionState
   * @param isGrant
   * @param isPass
   * @param permissionTable
   */
  public AbstractPermission createUnPermission(
      Long roleId,
      Long resourceId,
      String operationId,
      Integer permissionState,
      Integer isGrant,
      Integer isPass,
      String permissionTable) {

    AbstractPermission usPermission =
        (AbstractPermission) BeanUtil.newInstanceByName(permissionTable);
    usPermission.setRoleId(roleId);
    usPermission.setResourceId(resourceId);
    usPermission.setOperationId(operationId);
    usPermission.setPermissionState(permissionState);
    usPermission.setIsGrant(isGrant);
    usPermission.setIsPass(isPass);

    return usPermission;
  }
 /**
  * 获取资源的父节点Id
  *
  * @param appId
  * @param resourceTypeId
  * @param resourceId
  * @return
  */
 public Long getParentResourceId(String appId, String resourceTypeId, Long resourceId) {
   String resourceTable = resourceTypeDao.getResourceTable(appId, resourceTypeId);
   IResource resource =
       (IResource) getEntity(BeanUtil.createClassByName(resourceTable), resourceId);
   return resource.getParentId();
 }