コード例 #1
0
 private boolean isKioskEnabled() {
   if (PentahoSystem.getInitializedOK()) {
     return "true".equals(PentahoSystem.getSystemSetting("kiosk-mode", "false"));
   } else {
     return false;
   }
 }
  private StagingMode getStagingMode(final Map<String, Object> inputs, final MasterReport report) {
    final Object o = inputs.get("report-staging-mode");
    if (o != null) {
      try {
        return StagingMode.valueOf(String.valueOf(o));
      } catch (IllegalArgumentException ie) {
        logger.trace("Staging mode was specified but invalid");
      }
    }

    StagingMode mode =
        (StagingMode)
            report.getAttribute(
                AttributeNames.Pentaho.NAMESPACE, AttributeNames.Pentaho.STAGING_MODE);
    if (mode == null) {
      logger.trace("Looking at default settings for mode"); // $NON-NLS-1$
      // Unable to use the plugin settings.xml because the
      // classloader for the ReportContentGenerator isn't the plugin classloader
      // IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null);
      // String defaultStagingMode = resLoader.getPluginSetting(ReportContentGenerator.class,
      // "settings/report-staging-mode"); //$NON-NLS-1$
      //
      // So - get default setting from the pentaho.xml instead
      String defaultStagingMode =
          PentahoSystem.getSystemSetting("report-staging-mode", null); // $NON-NLS-1$
      if (defaultStagingMode == null) {
        // workaround for a bug in getPluginSetting that ignores the default passed in
        defaultStagingMode = DEFAULT.toString(); // $NON-NLS-1$
        logger.trace("Nothing in settings/staging-mode - defaulting to MEMORY"); // $NON-NLS-1$
      } else {
        logger.trace(
            "Read "
                + defaultStagingMode
                + " from settings/report-staging-mode"); //$NON-NLS-1$//$NON-NLS-2$
      }
      try {
        mode = StagingMode.valueOf(defaultStagingMode.toUpperCase());
        logger.trace("Staging mode set from default - " + mode); // $NON-NLS-1$
      } catch (IllegalArgumentException badStringInSettings) {
        mode = DEFAULT; // default state - handling staging in memory by default.
      }
    }
    return mode;
  }
コード例 #3
0
 public static TestManager getInstance(TestSuite all) throws Exception {
   if (manager == null) {
     String testManagerClassName =
         PentahoSystem.getSystemSetting(
             "test-suite/test-settings.xml",
             "test-manager",
             "org.pentaho.test.TestManager"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     if (testManagerClassName == null) {
       testManagerClassName = "org.pentaho.test.TestManager"; // $NON-NLS-1$
     }
     Class componentClass = Class.forName(testManagerClassName.trim());
     manager = (TestManager) componentClass.newInstance();
     if (manager != null) {
       manager.init(all);
     } else {
       throw new ClassNotFoundException();
     }
   }
   return manager;
 }
コード例 #4
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      // Retrieving the file upload defaults from pentaho.xml
      String relativePath =
          PentahoSystem.getSystemSetting(
              "file-upload-defaults/relative-path",
              String.valueOf(DEFAULT_RELATIVE_UPLOAD_FILE_PATH)); // $NON-NLS-1$
      String maxFileLimit =
          PentahoSystem.getSystemSetting(
              "file-upload-defaults/max-file-limit", String.valueOf(MAX_FILE_SIZE)); // $NON-NLS-1$
      String maxFolderLimit =
          PentahoSystem.getSystemSetting(
              "file-upload-defaults/max-folder-limit",
              String.valueOf(MAX_FOLDER_SIZE)); // $NON-NLS-1$

      response.setContentType("text/plain");
      FileItem uploadItem = getFileItem(request);
      if (uploadItem == null) {
        response
            .getWriter()
            .write(
                Messages.getInstance()
                    .getErrorString("UploadFileServlet.ERROR_0001_NO_FILE_TO_UPLOAD"));
        return;
      }
      if (Long.parseLong(maxFileLimit) < uploadItem.getSize()) {
        response
            .getWriter()
            .write(
                Messages.getInstance().getErrorString("UploadFileServlet.ERROR_0003_FILE_TOO_BIG"));
        return;
      }

      String path = PentahoSystem.getApplicationContext().getSolutionPath(relativePath);

      File pathDir = new File(path);
      // create the path if it doesn't exist yet
      if (!pathDir.exists()) {
        pathDir.mkdirs();
      }

      if (uploadItem.getSize() + getFolderSize(pathDir) > Long.parseLong(maxFolderLimit)) {
        response
            .getWriter()
            .write(
                Messages.getInstance()
                    .getErrorString("UploadFileServlet.ERROR_0004_FOLDER_SIZE_LIMIT_REACHED"));
        return;
      }
      byte[] fileContents = uploadItem.get();
      UUID id = UUIDUtil.getUUID();
      String filename = id.toString() + CSV_EXT;

      if (doesFileExists(new File(path + filename))) {
        response
            .getWriter()
            .write(
                Messages.getInstance()
                    .getErrorString("UploadFileServlet.ERROR_0002_FILE_ALREADY_EXIST"));
        return;
      }
      FileOutputStream outputStream = new FileOutputStream(path + filename);
      outputStream.write(fileContents);
      outputStream.flush();
      outputStream.close();
      response.getWriter().write(new String(filename));
    } catch (Exception e) {
      response
          .getWriter()
          .write(
              Messages.getInstance()
                  .getErrorString(
                      "UploadFileServlet.ERROR_0005_UNKNOWN_ERROR", e.getLocalizedMessage()));
    }
  }
コード例 #5
0
  public void handleRequest(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    try {
      // look for a passed in theme context (content generator, other named area)
      String moduleName = req.getParameter("context");
      OutputStream out = resp.getOutputStream();
      resp.setContentType("text/javascript"); // $NON-NLS-1$
      resp.setHeader("Cache-Control", "no-cache"); // $NON-NLS-1$

      IUserSettingService settingsService =
          PentahoSystem.get(IUserSettingService.class, getPentahoSession(req));

      String activeTheme = (String) getPentahoSession(req).getAttribute("pentaho-user-theme");

      String ua = req.getHeader("User-Agent");
      // check if we're coming from a mobile device, if so, lock to system default (crystal)
      if (!StringUtils.isEmpty(ua) && ua.matches(".*(?i)(iPad|iPod|iPhone|Android).*")) {
        activeTheme = PentahoSystem.getSystemSetting("default-theme", "crystal");
      }
      if (activeTheme == null) {
        try {
          activeTheme =
              settingsService.getUserSetting("pentaho-user-theme", null).getSettingValue();
        } catch (
            Exception
                ignored) { // the user settings service is not valid in the agile-bi deployment of
          // the server
        }
        if (activeTheme == null) {
          activeTheme = PentahoSystem.getSystemSetting("default-theme", "crystal");
        }
      }

      out.write(
          ("\n\n// Theming scripts. This file is generated by ("
                  + getClass().getName()
                  + ") and cannot be found on disk\n")
              .getBytes());

      out.write(("var active_theme = \"" + activeTheme + "\";\n\n").getBytes());

      // Build-up JSON graph for system theme.
      JSONObject root = new JSONObject();
      JSONObject themeObject;

      for (String systemThemeName : themeManager.getSystemThemeIds()) {
        Theme theme = themeManager.getSystemTheme(systemThemeName);

        themeObject = new JSONObject();
        root.put(theme.getId(), themeObject);
        themeObject.put("rootDir", theme.getThemeRootDir());
        for (ThemeResource res : theme.getResources()) {
          themeObject.append("resources", res.getLocation());
        }
      }

      out.write(("var core_theme_tree = " + root.toString() + ";\n\n").getBytes());
      out.write(
          "// Inject the theme script to handle the insertion of requested theme resources\n\n"
              .getBytes());

      ModuleThemeInfo moduleThemeinfo = themeManager.getModuleThemeInfo(moduleName);
      if (moduleThemeinfo != null) {
        // Build-up JSON graph for module theme.
        root = new JSONObject();
        for (Theme theme : moduleThemeinfo.getModuleThemes()) {
          themeObject = new JSONObject();
          root.put(theme.getName(), themeObject);
          themeObject.put("rootDir", theme.getThemeRootDir());
          for (ThemeResource res : theme.getResources()) {
            themeObject.append("resources", res.getLocation());
          }
        }

        out.write(("var module_theme_tree = " + root.toString() + ";\n\n").getBytes());
      }

      // createElement & insertBefore
      out.write(
          ("(function() {\n"
                  + "var script = document.createElement('script');\n"
                  + "script.type = 'text/javascript';\n"
                  +
                  // "script.async = false;\n" +
                  "script.src = CONTEXT_PATH + 'js/themeResources.js';\n"
                  + "var existing = document.getElementsByTagName('script')[0];\n"
                  + "existing.parentNode.insertBefore(script, existing);\n"
                  + "}());")
              .getBytes());

    } catch (IOException e) {
      logger.debug("IO exception creating Theme info", e);
      throw new ServletException(e);
    } catch (JSONException e) {
      logger.debug("JSON exception creating Theme info", e);
      throw new ServletException(e);
    }
  }
コード例 #6
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {

      String relativePath =
          PentahoSystem.getSystemSetting(
              "file-upload-defaults/relative-path",
              String.valueOf(DEFAULT_RELATIVE_UPLOAD_FILE_PATH)); // $NON-NLS-1$
      String maxFileLimit =
          PentahoSystem.getSystemSetting(
              "file-upload-defaults/max-file-limit",
              String.valueOf(MAX_FILE_SIZE)); // $NON-NLS-1$
      String maxFolderLimit =
          PentahoSystem.getSystemSetting(
              "file-upload-defaults/max-folder-limit",
              String.valueOf(MAX_FOLDER_SIZE)); // $NON-NLS-1$
      IPentahoSession session = PentahoHttpSessionHelper.getPentahoSession(request);

      response.setContentType("text/plain"); // $NON-NLS-1$

      FileItem uploadItem = getFileItem(request);
      if (uploadItem == null) {
        String error =
            Messages.getErrorString(
                "UploadFileDebugServlet.ERROR_0001_NO_FILE_TO_UPLOAD"); //$NON-NLS-1$
        response.getWriter().write(error);
        return;
      }
      if (Long.parseLong(maxFileLimit) < uploadItem.getSize()) {
        String error =
            Messages.getErrorString(
                "UploadFileDebugServlet.ERROR_0003_FILE_TOO_BIG"); //$NON-NLS-1$
        response.getWriter().write(error);
        return;
      }

      String path = PentahoSystem.getApplicationContext().getSolutionPath(relativePath);
      File pathDir = new File(path);
      // create the path if it doesn't exist yet
      if (!pathDir.exists()) {
        pathDir.mkdirs();
      }

      if (uploadItem.getSize() + getFolderSize(new File(path)) > Long.parseLong(maxFolderLimit)) {
        String error =
            Messages.getErrorString(
                "UploadFileDebugServlet.ERROR_0004_FOLDER_SIZE_LIMIT_REACHED"); //$NON-NLS-1$
        response.getWriter().write(error);
        return;
      }

      String filename = request.getParameter("file_name"); // $NON-NLS-1$
      if (StringUtils.isEmpty(filename)) {
        filename = UUIDUtil.getUUID().toString();
      }

      String temporary = request.getParameter("mark_temporary"); // $NON-NLS-1$
      boolean isTemporary = false;
      if (temporary != null) {
        isTemporary = Boolean.valueOf(temporary);
      }

      File file;
      if (isTemporary) {
        file =
            PentahoSystem.getApplicationContext()
                .createTempFile(session, "", ".tmp", true); // $NON-NLS-1$
      } else {
        file = new File(path + File.separatorChar + filename);
      }

      FileOutputStream outputStream = new FileOutputStream(file);
      byte[] fileContents = uploadItem.get();
      outputStream.write(fileContents);
      outputStream.flush();
      outputStream.close();

      response.getWriter().write(file.getName());
    } catch (Exception e) {
      String error =
          Messages.getErrorString(
              "UploadFileDebugServlet.ERROR_0005_UNKNOWN_ERROR",
              e.getLocalizedMessage()); // $NON-NLS-1$
      response.getWriter().write(error);
    }
  }
コード例 #7
0
  public static int saveAnalysis(
      final IPentahoSession session,
      final HashMap props,
      final String path,
      String fileName,
      final boolean overwrite) {

    if ("true"
        .equals(
            PentahoSystem.getSystemSetting(
                "kiosk-mode", "false"))) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      throw new RuntimeException(
          Messages.getInstance()
              .getErrorString("ANALYSISSAVER.ERROR_0006_SAVE_IS_DISABLED")); // $NON-NLS-1$
    }

    int result = 0;
    try {
      AnalysisSaver.logger = LogFactory.getLog(AnalysisSaver.class);
      String baseUrl = PentahoSystem.getApplicationContext().getSolutionPath(""); // $NON-NLS-1$
      ISolutionRepository solutionRepository =
          PentahoSystem.get(ISolutionRepository.class, session);

      // We will (at this point in time) always have an original action sequence to start from...
      String originalActionReference = (String) props.get("actionreference"); // $NON-NLS-1$

      if (originalActionReference == null) {
        throw new MissingParameterException(
            Messages.getInstance()
                .getErrorString(
                    "ANALYSISSAVER.ERROR_0001_MISSING_ACTION_REFERENCE")); //$NON-NLS-1$
      }

      Document document = null;
      try {
        org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader();
        reader.setEntityResolver(new SolutionURIResolver());
        document =
            reader.read(
                ActionSequenceResource.getInputStream(
                    originalActionReference, LocaleHelper.getLocale()));
      } catch (Throwable t) {
        // XML document can't be read. We'll just return a null document.
      }

      // Update the document with the stuff we passed in on the props
      document = AnalysisSaver.updateDocument(document, props);
      fileName =
          fileName.endsWith(AnalysisSaver.SUFFIX) ? fileName : fileName + AnalysisSaver.SUFFIX;
      result =
          solutionRepository.publish(
              baseUrl,
              path,
              fileName,
              document.asXML().getBytes(document.getXMLEncoding()),
              overwrite);

      // Now save the resource files
      ActionInfo actionInfo = ActionInfo.parseActionString(originalActionReference);
      String originalPath =
          actionInfo.getSolutionName() + "/" + actionInfo.getPath(); // $NON-NLS-1$
      String originalFileName = actionInfo.getActionName();
      originalFileName =
          originalFileName.substring(0, originalFileName.lastIndexOf(AnalysisSaver.SUFFIX));
      ISolutionFile[] parentFiles =
          solutionRepository
              .getSolutionFile(originalPath, ISolutionRepository.ACTION_EXECUTE)
              .listFiles();
      String baseFileName = fileName.substring(0, fileName.lastIndexOf(AnalysisSaver.SUFFIX));
      for (ISolutionFile aSolutionFile : parentFiles) {
        if (!aSolutionFile.isDirectory()
            && aSolutionFile.getFileName().startsWith(originalFileName)
            && aSolutionFile
                .getFileName()
                .toLowerCase()
                .endsWith(AnalysisSaver.PROPERTIES_SUFFIX)) {
          String newFileName =
              aSolutionFile.getFileName().replaceFirst(originalFileName, baseFileName);
          result =
              result
                  & solutionRepository.publish(
                      baseUrl, path, newFileName, aSolutionFile.getData(), overwrite);
        }
      }

      solutionRepository.resetRepository();
    } catch (Exception e) {
      AnalysisSaver.logger.error(
          Messages.getInstance().getErrorString("ANALYSISSAVER.ERROR_0000_UNKNOWN"),
          e); //$NON-NLS-1$
      result = ISolutionRepository.FILE_ADD_FAILED;
    }

    return result;
  }
コード例 #8
0
/**
 * A utility class with several static methods that are used to either bind the
 * <tt>Authentication</tt> to the <tt>IPentahoSession</tt>, retrieve the <tt>Authentication</tt>
 * from the <tt>IPentahoSession</tt>, and other various helper functions.
 *
 * @author mbatchel
 */
public class SecurityHelper {

  private static final Log logger = LogFactory.getLog(SecurityHelper.class);

  public static final String SESSION_PRINCIPAL = "SECURITY_PRINCIPAL"; // $NON-NLS-1$

  public static final String DefaultAnonymousRole =
      PentahoSystem.getSystemSetting(
          "anonymous-authentication/anonymous-role", "Anonymous"); // $NON-NLS-1$ //$NON-NLS-2$

  public static final String DefaultAnonymousUser =
      PentahoSystem.getSystemSetting(
          "anonymous-authentication/anonymous-user", "anonymousUser"); // $NON-NLS-1$ //$NON-NLS-2$

  /**
   * Looks in the provided session to get the Spring Security Authentication object out. Optionally
   * returns an "anonymous" Authentication if desired.
   *
   * @param session Users' IPentahoSession object
   * @param allowAnonymous If true, will return an anonymous Authentication object.
   * @return the Authentication object from the session
   */
  public static Authentication getAuthentication(
      final IPentahoSession session, final boolean allowAnonymous) {
    Principal principal = (Principal) session.getAttribute(SecurityHelper.SESSION_PRINCIPAL);
    if (SecurityHelper.logger.isDebugEnabled()) {
      SecurityHelper.logger.debug("principal from IPentahoSession: " + principal); // $NON-NLS-1$
      if (null != principal) {
        SecurityHelper.logger.debug(
            "principal class: " + principal.getClass().getName()); // $NON-NLS-1$
      }
    }
    if (principal instanceof Authentication) {
      if (SecurityHelper.logger.isDebugEnabled()) {
        SecurityHelper.logger.debug("principal is an instance of Authentication"); // $NON-NLS-1$
      }
      return (Authentication) principal;
    } else if (principal != null) {
      if (SecurityHelper.logger.isDebugEnabled()) {
        SecurityHelper.logger.debug(
            "principal is not an instance of Authentication"); //$NON-NLS-1$
        SecurityHelper.logger.debug("attempting role fetch with username"); // $NON-NLS-1$
      }

      // OK - Not Spring Security somehow.
      // However, since the principal interface doesn't specify the
      // roles a user is in, we need to dispatch a call to the
      // UserRoleListProvider to get that information from there.

      IUserDetailsRoleListService roleListService = PentahoSystem.getUserDetailsRoleListService();
      List roles = roleListService.getRolesForUser(principal.getName());
      if (SecurityHelper.logger.isDebugEnabled()) {
        SecurityHelper.logger.debug("rolesForUser from roleListService:" + roles); // $NON-NLS-1$
      }
      if (!roles.isEmpty()) {
        GrantedAuthority[] grantedAuthorities = new GrantedAuthority[roles.size()];
        for (int i = 0; i < roles.size(); i++) {
          grantedAuthorities[i] = new GrantedAuthorityImpl((String) roles.get(i));
        }

        Authentication auth =
            new UsernamePasswordAuthenticationToken(principal.getName(), null, grantedAuthorities);

        return auth;
      }
    }
    if (SecurityHelper.logger.isDebugEnabled()) {
      SecurityHelper.logger.debug("either principal is null or user has no roles"); // $NON-NLS-1$
    }

    if (allowAnonymous) {
      if (SecurityHelper.logger.isDebugEnabled()) {
        SecurityHelper.logger.debug("there is no principal in IPentahoSession"); // $NON-NLS-1$
        SecurityHelper.logger.debug(
            "creating token with username anonymous and role Anonymous"); //$NON-NLS-1$
      }
      // Hmmm - at this point, we're being asked for an authentication on
      // an un-authenticated user. For now, we'll default to returning
      // an authentication that has the user as anonymous.
      Authentication auth =
          new UsernamePasswordAuthenticationToken(
              SecurityHelper.DefaultAnonymousUser,
              null,
              new GrantedAuthorityImpl[] {
                new GrantedAuthorityImpl(SecurityHelper.DefaultAnonymousRole)
              });
      return auth;
    } else {
      if (SecurityHelper.logger.isDebugEnabled()) {
        SecurityHelper.logger.debug("there is no principal in IPentahoSession"); // $NON-NLS-1$
        SecurityHelper.logger.debug("and allowAnonymous is false"); // $NON-NLS-1$
      }
      // If we're here - we require a properly authenticated user and
      // there's nothing
      // else we can do aside from returning null.
      return null;
    }
  }

  /**
   * Gets the java.security.principal object from the IPentahoSession object
   *
   * @param session The users' session
   * @return The bound Principal
   */
  public static Principal getPrincipal(final IPentahoSession session) {
    Principal principal = (Principal) session.getAttribute(SecurityHelper.SESSION_PRINCIPAL);
    return principal;
  }

  /**
   * Sets the java.security.principal object into the IPentahoSession object.
   *
   * @param principal The principal from the servlet context
   * @param session The users' IPentahoSession object
   */
  public static void setPrincipal(final Principal principal, final IPentahoSession session) {
    session.setAttribute(SecurityHelper.SESSION_PRINCIPAL, principal);
  }

  /**
   * Utility method that communicates with the installed ACLVoter to determine administrator status
   *
   * @param session The users IPentahoSession object
   * @return true if the user is considered a Pentaho administrator
   */
  public static boolean isPentahoAdministrator(final IPentahoSession session) {
    IAclVoter voter = PentahoSystem.get(IAclVoter.class, session);
    return voter.isPentahoAdministrator(session);
  }

  /**
   * Utility method that communicates with the installed ACLVoter to determine whether a particular
   * role is granted to the specified user.
   *
   * @param session The users' IPentahoSession
   * @param role The role to look for
   * @return true if the user is granted the specified role.
   */
  public static boolean isGranted(final IPentahoSession session, final GrantedAuthority role) {
    IAclVoter voter = PentahoSystem.get(IAclVoter.class, session);
    return voter.isGranted(session, role);
  }

  /**
   * @param aFile
   * @return a boolean that indicates if this file can have ACLS placed on it.
   */
  public static boolean canHaveACLS(final ISolutionFile aFile) {
    if (aFile.isDirectory()) { // All Directories can have ACLS
      return true;
    }

    // Otherwise anything in the PentahoSystem extension list.
    return PentahoSystem.getACLFileExtensionList().contains(aFile.getExtension());
  }

  public static boolean hasAccess(
      final IAclHolder aHolder, final int actionOperation, final IPentahoSession session) {
    IAclVoter voter = PentahoSystem.get(IAclVoter.class, session);
    int aclMask = -1;

    switch (actionOperation) {
      case (IAclHolder.ACCESS_TYPE_READ):
        {
          aclMask = IPentahoAclEntry.PERM_EXECUTE;
          break;
        }
      case IAclHolder.ACCESS_TYPE_WRITE:
      case IAclHolder.ACCESS_TYPE_UPDATE:
        {
          aclMask = IPentahoAclEntry.PERM_UPDATE;
          break;
        }
      case IAclHolder.ACCESS_TYPE_DELETE:
        {
          aclMask = IPentahoAclEntry.PERM_DELETE;
          break;
        }
      case IAclHolder.ACCESS_TYPE_ADMIN:
        {
          aclMask = IPentahoAclEntry.PERM_ADMINISTRATION;
          break;
        }
      default:
        {
          aclMask = IPentahoAclEntry.PERM_EXECUTE;
          break;
        }
    }
    return voter.hasAccess(session, aHolder, aclMask);
  }

  /**
   * Utility method for access negotiation. For performance, not all files will be checked against
   * the supplied voter.
   *
   * @param aFile
   * @param actionOperation
   * @param session
   * @return
   */
  public static boolean hasAccess(
      final IAclSolutionFile aFile, final int actionOperation, final IPentahoSession session) {
    if (aFile == null) {
      return false;
    }
    if (!aFile.isDirectory()) {
      List extensionList = PentahoSystem.getACLFileExtensionList();
      String fName = aFile.getFileName();
      int posn = fName.lastIndexOf('.');
      if (posn >= 0) {
        if (extensionList.indexOf(fName.substring(posn)) < 0) {
          // Non-acl'd file. Return true.
          return true;
        }
      } else {
        // Untyped file. Allow access.
        return true;
      }
    }
    IAclVoter voter = PentahoSystem.get(IAclVoter.class, session);
    int aclMask = -1;
    switch (actionOperation) {
      case ISolutionRepository.ACTION_EXECUTE:
        {
          aclMask = IPentahoAclEntry.PERM_EXECUTE;
          break;
        }
      case ISolutionRepository.ACTION_ADMIN:
        {
          // aclMask = PentahoAclEntry.ADMINISTRATION;
          // break;
          return SecurityHelper.isPentahoAdministrator(session);
        }
      case ISolutionRepository.ACTION_SUBSCRIBE:
        {
          aclMask = IPentahoAclEntry.PERM_SUBSCRIBE;
          break;
        }
      case ISolutionRepository.ACTION_CREATE:
        {
          aclMask = IPentahoAclEntry.PERM_CREATE;
          break;
        }
      case ISolutionRepository.ACTION_UPDATE:
        {
          aclMask = IPentahoAclEntry.PERM_UPDATE;
          break;
        }
      case ISolutionRepository.ACTION_DELETE:
        {
          aclMask = IPentahoAclEntry.PERM_DELETE;
          break;
        }
      case ISolutionRepository.ACTION_SHARE:
        {
          aclMask = IPentahoAclEntry.PERM_UPDATE_PERMS;
          break;
        }
      default:
        {
          aclMask = IPentahoAclEntry.PERM_EXECUTE;
          break;
        }
    }
    return voter.hasAccess(session, aFile, aclMask);
  }
}
コード例 #9
0
  /**
   * Return the current user console settings
   *
   * @return current settings
   */
  @GET
  @Path("/settings")
  @Produces({APPLICATION_JSON, APPLICATION_XML})
  public List<Setting> getMantleSettings() {
    ArrayList<Setting> settings = new ArrayList<Setting>();
    settings.add(
        new Setting(
            "login-show-users-list",
            PentahoSystem.getSystemSetting(
                "login-show-users-list", ""))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(
        new Setting(
            "documentation-url",
            PentahoSystem.getSystemSetting(
                "documentation-url", ""))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(
        new Setting(
            "submit-on-enter-key",
            PentahoSystem.getSystemSetting(
                "submit-on-enter-key", "true"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(
        new Setting(
            "user-console-revision",
            PentahoSystem.getSystemSetting(
                "user-console-revision", ""))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(
        new Setting(
            "startupPerspective",
            PentahoSystem.getSystemSetting(
                "startup-perspective", ""))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(
        new Setting(
            "showOnlyPerspective",
            PentahoSystem.getSystemSetting(
                "show-only-perspective", ""))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    int startupUrls = Integer.parseInt(PentahoSystem.getSystemSetting("num-startup-urls", "0"));
    settings.add(
        new Setting(
            "num-startup-urls",
            PentahoSystem.getSystemSetting(
                "num-startup-urls", "0"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    for (int i = 1; i <= startupUrls; i++) {
      settings.add(
          new Setting(
              "startup-url-" + i,
              PentahoSystem.getSystemSetting("startup-url-" + i, ""))); // $NON-NLS-1$
      settings.add(
          new Setting(
              "startup-name-" + i,
              PentahoSystem.getSystemSetting("startup-name-" + i, ""))); // $NON-NLS-1$
    }

    // Check for override of New Analysis View via pentaho.xml
    // Poked in via pentaho.xml entries
    // <new-analysis-view>
    // <command-url>http://www.google.com</command-url>
    // <command-title>Marc Analysis View</command-title>
    // </new-analysis-view>
    // <new-report>
    // <command-url>http://www.yahoo.com</command-url>
    // <command-title>Marc New Report</command-title>
    // </new-report>
    //
    String overrideNewAnalysisViewCommmand =
        PentahoSystem.getSystemSetting("new-analysis-view/command-url", null); // $NON-NLS-1$
    String overrideNewAnalysisViewTitle =
        PentahoSystem.getSystemSetting("new-analysis-view/command-title", null); // $NON-NLS-1$
    if ((overrideNewAnalysisViewCommmand != null) && (overrideNewAnalysisViewTitle != null)) {
      settings.add(
          new Setting(
              "new-analysis-view-command-url", overrideNewAnalysisViewCommmand)); // $NON-NLS-1$
      settings.add(
          new Setting(
              "new-analysis-view-command-title", overrideNewAnalysisViewTitle)); // $NON-NLS-1$
    }
    String overrideNewReportCommmand =
        PentahoSystem.getSystemSetting("new-report/command-url", null); // $NON-NLS-1$
    String overrideNewReportTitle =
        PentahoSystem.getSystemSetting("new-report/command-title", null); // $NON-NLS-1$
    if ((overrideNewReportCommmand != null) && (overrideNewReportTitle != null)) {
      settings.add(new Setting("new-report-command-url", overrideNewReportCommmand)); // $NON-NLS-1$
      settings.add(new Setting("new-report-command-title", overrideNewReportTitle)); // $NON-NLS-1$
    }

    IPluginManager pluginManager =
        PentahoSystem.get(IPluginManager.class, getPentahoSession()); // $NON-NLS-1$
    if (pluginManager != null) {
      // load content types from IPluginSettings
      int i = 0;
      for (String contentType : pluginManager.getContentTypes()) {
        IContentInfo info = pluginManager.getContentTypeInfo(contentType);
        if (info != null) {
          settings.add(
              new Setting(
                  "plugin-content-type-" + i, "." + contentType)); // $NON-NLS-1$ //$NON-NLS-2$
          settings.add(
              new Setting("plugin-content-type-icon-" + i, info.getIconUrl())); // $NON-NLS-1$
          int j = 0;
          for (IPluginOperation operation : info.getOperations()) {
            settings.add(
                new Setting(
                    "plugin-content-type-" + i + "-command-" + j,
                    operation.getId())); // $NON-NLS-1$
            settings.add(
                new Setting(
                    "plugin-content-type-" + i + "-command-perspective-" + j,
                    operation.getPerspective())); // $NON-NLS-1$
            j++;
          }
          i++;
        }
      }
    }

    return settings;
  }