/**
   * Get a new ticket.
   *
   * @param session HttpSession
   * @return String
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public String readTicket(HttpSession session) throws IOException {
    logger.debug("IN");
    String ticket = null;
    String spagoBiServerURL = EnginConf.getInstance().getSpagoBiServerUrl();
    logger.debug("Read spagoBiServerURL=" + spagoBiServerURL);
    SourceBean engineConfig = EnginConf.getInstance().getConfig();
    SourceBean sourceBeanConf = (SourceBean) engineConfig.getAttribute("FILTER_RECEIPT");
    String filterReceipt = (String) sourceBeanConf.getCharacters();
    logger.debug("Read filterReceipt=" + filterReceipt);
    filterReceipt = spagoBiServerURL + filterReceipt;

    Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
    ticket = assertion.getPrincipal().getProxyTicketFor(filterReceipt);

    logger.debug("OUT.ticket=" + ticket);
    return ticket;
  }
Example #2
0
 public String getResourcePath() {
   if (resPath == null) {
     try {
       String jndiName =
           SingletonConfig.getInstance().getConfigValue("SPAGOBI.RESOURCE_PATH_JNDI_NAME");
       resPath = SpagoBIUtilities.readJndiResource(jndiName);
     } catch (Throwable t) {
       logger.debug(t);
       resPath = EnginConf.getInstance().getResourcePath();
     }
   }
   if (resPath == null) {
     throw new SpagoBIRuntimeException("Resource path not found!!!");
   }
   return resPath;
 }
Example #3
0
  /**
   * Substitutes the parameters with sintax "$P{attribute_name}" with the correspondent value in the
   * string passed at input. Only for datatset parameters, had to duplicate to handle null values,
   * not throw an exception but put null!
   *
   * @param statement The string to be modified (tipically a query)
   * @param userProfile The IEngUserProfile object
   * @param profileAttributeStartIndex The start index for query parsing (useful for recursive
   *     calling)
   * @param surroundWithQuotes Flag: if true, the replacement will be surrounded by quotes if they
   *     are missing
   * @return The statement with parameters replaced by their values.
   * @throws Exception
   */
  private static String substituteDatasetParametersInString(
      String statement,
      Map valuesMap,
      Map parTypeMap,
      int profileAttributeStartIndex,
      boolean surroundWithQuotes)
      throws Exception {
    logger.debug("IN");

    int profileAttributeEndIndex = statement.indexOf("}", profileAttributeStartIndex);
    if (profileAttributeEndIndex == -1)
      throw new Exception("Not closed profile attribute: '}' expected.");
    if (profileAttributeEndIndex < profileAttributeEndIndex)
      throw new Exception("Not opened profile attribute: '$P{' expected.");
    String attribute =
        statement.substring(profileAttributeStartIndex + 3, profileAttributeEndIndex).trim();

    String dequotePrefix = "_dequoted";
    if (attribute.endsWith(dequotePrefix)) {
      surroundWithQuotes = false;
    }

    int startConfigIndex = attribute.indexOf("(");
    String attributeName = "";
    String prefix = "";
    String split = "";
    String suffix = "";
    boolean attributeExcpetedToBeMultiValue = false;

    if (startConfigIndex != -1) {
      // the parameter is expected to be multivalue
      attributeExcpetedToBeMultiValue = true;
      int endConfigIndex = attribute.length() - 1;
      if (attribute.charAt(endConfigIndex) != ')')
        throw new Exception(
            "Sintax error: \")\" missing. The expected sintax for "
                + "parameter is  $P{parameters} for singlevalue parameters. ");
      String configuration = attribute.substring(startConfigIndex + 1, endConfigIndex);
      // check the configuration content and add empty prefix/suffix as default if they are null
      if (configuration.equals(";,;")) configuration = " ;,; ";

      String[] configSplitted = configuration.split(";");
      if (configSplitted == null || configSplitted.length != 3)
        throw new Exception(
            "Sintax error. The expected sintax for parameters"
                + "or $P{parameter} for singlevalue parameter. 'parameterName' must not contain '(' characters. "
                + "The (prefix;split;suffix) is not properly configured");
      prefix = configSplitted[0];
      split = configSplitted[1];
      suffix = configSplitted[2];
      logger.debug(
          "Multi-value parameter configuration found: prefix: '"
              + prefix
              + "'; split: '"
              + split
              + "'; suffix: '"
              + suffix
              + "'.");
      attributeName = attribute.substring(0, startConfigIndex);
      logger.debug("Expected multi-value parameter name: '" + attributeName + "'");
    } else {
      attributeName = attribute;
      logger.debug("Expected single-value parameter name: '" + attributeName + "'");
    }

    String value = (String) valuesMap.get(attributeName);
    boolean isNullValue = false;
    if (value == null) {
      isNullValue = true;
      value = "null";
    }

    if (value.startsWith("' {")) value = value.substring(1);
    if (value.endsWith("}'")) value = value.substring(0, value.indexOf("}'") + 1);
    value = value.trim();
    logger.debug("Parameter value found: " + value);
    String replacement = null;
    String newListOfValues = null;

    // if is specified a particular type for the parameter can add '' in case of String or Date
    String parType = null;
    if (parTypeMap != null) {
      parType = (String) parTypeMap.get(attributeName);
    }
    if (parType == null) parType = new String("");

    if (attributeExcpetedToBeMultiValue) {
      if (value.startsWith("{")) {
        // the parameter is multi-value
        String[] values = findAttributeValues(value);
        logger.debug("N. " + values.length + " parameter values found: '" + values + "'");
        // newListOfValues = values[0];
        newListOfValues =
            ((values[0].startsWith(prefix)))
                ? ""
                : prefix + values[0] + ((values[0].endsWith(suffix)) ? "" : suffix);
        for (int i = 1; i < values.length; i++) {
          // newListOfValues = newListOfValues + split + values[i];
          String singleValue =
              ((values[i].startsWith(prefix)))
                  ? ""
                  : prefix + values[i] + ((values[i].endsWith(suffix)) ? "" : suffix);
          singleValue = checkParType(singleValue, parType, attribute);
          newListOfValues = newListOfValues + split + singleValue;
        }
      } else {
        logger.warn(
            "The attribute value has not the sintax of a multi value parameter; considering it as a single value.");
        newListOfValues = value;
      }
    } else {
      if (value.startsWith("{")) {
        // the profile attribute is multi-value
        logger.warn(
            "The attribute value seems to be a multi value parameter; trying considering it as a multi value using its own splitter and no prefix and suffix.");
        try {
          // checks the sintax
          String[] values = findAttributeValues(value);
          newListOfValues = values[0];
          for (int i = 1; i < values.length; i++) {
            newListOfValues = newListOfValues + value.charAt(1) + values[i];
          }
        } catch (Exception e) {
          logger.error(
              "The attribute value does not respect the sintax of a multi value attribute; considering it as a single value.",
              e);
          newListOfValues = value;
        }
      } else {
        newListOfValues = value;
      }
    }
    String nullValueString = null;
    if (newListOfValues.equals("")
        || newListOfValues.equals("''")
        || newListOfValues.equals("null")) {
      try {
        nullValueString = SingletonConfig.getInstance().getConfigValue("DATA_SET_NULL_VALUE");
        if (nullValueString != null) {
          newListOfValues = "'" + nullValueString + "'";
        }
      } catch (Throwable e) {
        // try to read engine_config settings
        nullValueString =
            ((SourceBean) EnginConf.getInstance().getConfig().getAttribute("DATA_SET_NULL_VALUE"))
                .getCharacters();
        if (nullValueString != null) {
          newListOfValues = "'" + nullValueString + "'";
        }
      }
    }
    // replacement = prefix + newListOfValues + suffix;
    replacement =
        ((newListOfValues.startsWith(prefix)) ? "" : prefix)
            + newListOfValues
            + ((newListOfValues.endsWith(suffix)) ? "" : suffix);

    if (!attributeExcpetedToBeMultiValue)
      replacement = checkParType(replacement, parType, attribute);

    // // if is specified a particular type for the parameter can add '' in case of String or Date
    // String parType=null;
    // if(parTypeMap!=null){
    // parType=(String)parTypeMap.get(attributeName);
    // }
    // if(parType==null)parType=new String("");
    //
    //
    // // check if numbers are number otherwise throw exception
    // try{
    // if(parType.equalsIgnoreCase("NUMBER")){
    // replacement = replacement.replaceAll("\'", "");
    // Double double1 = Double.valueOf(replacement);
    // }
    // }
    // catch (NumberFormatException e) {
    // String me = e.getMessage();
    // me += " - attribute "+attribute+" should be of number type";
    // NumberFormatException numberFormatException = new NumberFormatException(attribute);
    // numberFormatException.setStackTrace(e.getStackTrace());
    // throw numberFormatException;
    // }
    //
    // // check when type is RAW that there are not '' surrounding values (in case remove them)
    // // remotion done here in order to not modify SpagoBI Analytical driver of type string
    // handling
    // try{
    // if(parType.equalsIgnoreCase("RAW")){
    // logger.debug("Parmaeter is Raw type, check if there are '' and remove them");
    // if(replacement.length()>2){
    // if(replacement.startsWith("'")){
    // logger.debug("first character is ', remove");
    // replacement = replacement.substring(1);
    // }
    // if(replacement.endsWith("'")){
    // logger.debug("last character is ', remove");
    // replacement = replacement.substring(0, replacement.length()-1);
    // }
    // }
    // }
    // }
    // catch (Exception e) {
    // logger.error("Error in removing the '' in value "+replacement+" do not substitute them");
    // }
    //
    // if (surroundWithQuotes || parType.equalsIgnoreCase("STRING") ||
    // parType.equalsIgnoreCase("DATE")) {
    // if(!isNullValue){
    // if (!replacement.startsWith("'")) replacement = "'" + replacement;
    // if (!replacement.endsWith("'")) replacement = replacement + "'";
    // }
    // }

    attribute = quote(attribute);
    statement = statement.replaceAll("\\$P\\{" + attribute + "\\}", replacement);

    // statement = statement.replaceAll("\\P\\{" + attribute + "\\}", replacement);
    /*
     * profileAttributeStartIndex = statement.indexOf("$P{", profileAttributeEndIndex-1); if (profileAttributeStartIndex != -1) statement =
     * substituteParametersInString(statement, valuesMap, profileAttributeStartIndex);
     */
    logger.debug("OUT");

    return statement;
  }