/** * Encapsulates the logic of registering import handlers, generating the manifest, and performing * the export */ public ZipExportProcessor(String path, IUnifiedRepository repository, boolean withManifest) { this.withManifest = withManifest; // set a default path at root if missing if (StringUtils.isEmpty(path)) { this.path = "/"; } else { this.path = path; } this.unifiedRepository = repository; this.exportHandlerList = new ArrayList<ExportHandler>(); this.exportManifest = new ExportManifest(); // set created by and create date in manifest information IPentahoSession session = PentahoSessionHolder.getSession(); Date todaysDate = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat(EXPORT_INFO_DATE_FORMAT); SimpleDateFormat timeFormat = new SimpleDateFormat(EXPORT_INFO_TIME_FORMAT); exportManifest.getManifestInformation().setExportBy(session.getName()); exportManifest .getManifestInformation() .setExportDate(dateFormat.format(todaysDate) + " " + timeFormat.format(todaysDate)); }
@Before public void setUp() throws Exception { repository = mock(IUnifiedRepository.class); session = mock(IPentahoSession.class); when(session.getName()).thenReturn("test"); PentahoSessionHolder.setSession(session); userSettings = new HashMap<String, Serializable>() { { put(USER_SETTING_NAME_1, USER_SETTING_VALUE_1); put(UserSettingService.SETTING_PREFIX + COMMON_SETTING_NAME, COMMON_USER_SETTING_VALUE); put(USER_SETTING_NAME_2, USER_SETTING_VALUE_2); put(UserSettingService.SETTING_PREFIX + USER_SETTING_NAME_3, USER_SETTING_VALUE_3); } }; globalSettings = new HashMap<String, Serializable>() { { put(GLOBAL_SETTING_NAME_1, GLOBAL_SETTING_VALUE_1); put( UserSettingService.SETTING_PREFIX + COMMON_SETTING_NAME, COMMON_GLOBAL_SETTING_VALUE); put(GLOBAL_SETTING_NAME_2, GLOBAL_SETTING_VALUE_2); put(UserSettingService.SETTING_PREFIX + GLOBAL_SETTING_NAME_3, GLOBAL_SETTING_VALUE_3); } }; when(repository.getFileMetadata(eq(USER_FOLDER_ID))).thenReturn(userSettings); when(repository.getFileMetadata(eq(TENANT_FOLDER_ID))).thenReturn(globalSettings); final RepositoryFile tenantRepositoryFile = mock(RepositoryFile.class); when(tenantRepositoryFile.getId()).thenReturn(TENANT_FOLDER_ID); when(repository.getFile(eq(ClientRepositoryPaths.getEtcFolderPath()))) .thenReturn(tenantRepositoryFile); final RepositoryFile userRepositoryFile = mock(RepositoryFile.class); when(userRepositoryFile.getId()).thenReturn(USER_FOLDER_ID); when(repository.getFile(eq(ClientRepositoryPaths.getUserHomeFolderPath(session.getName())))) .thenReturn(userRepositoryFile); securityHelper = mock(ISecurityHelper.class); when(securityHelper.runAsSystem(any(Callable.class))) .thenAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { final Callable callable = (Callable) invocation.getArguments()[0]; if (callable != null) { return callable.call(); } return null; } }); SecurityHelper.setMockInstance(securityHelper); userSettingService = new UserSettingService(repository); userSettingService.init(session); }
@POST @Path("/session-variable") public Response setSessionVariable( @QueryParam("key") String key, @QueryParam("value") String value) { IPentahoSession session = getPentahoSession(); session.setAttribute(key, value); return Response.ok(session.getAttribute(key)).build(); }
@Override public void createContent() throws Exception { this.session = PentahoSessionHolder.getSession(); this.repository = PentahoSystem.get(IUnifiedRepository.class, session); final RepositoryFile BIRTfile = (RepositoryFile) parameterProviders.get("path").getParameter("file"); final String ExecBIRTFilePath = "../webapps/birt/" + BIRTfile.getId() + ".rptdocument"; /* * Get BIRT report design from repository */ final File ExecBIRTFile = new File(ExecBIRTFilePath); if (!ExecBIRTFile.exists()) { final FileOutputStream fos = new FileOutputStream(ExecBIRTFilePath); try { final SimpleRepositoryFileData data = repository.getDataForRead(BIRTfile.getId(), SimpleRepositoryFileData.class); final InputStream inputStream = data.getInputStream(); final byte[] buffer = new byte[0x1000]; int bytesRead = inputStream.read(buffer); while (bytesRead >= 0) { fos.write(buffer, 0, bytesRead); bytesRead = inputStream.read(buffer); } } catch (final Exception e) { Logger.error(getClass().getName(), e.getMessage()); } finally { fos.close(); } } /* * Redirect to BIRT Viewer */ try { // Get informations about user context final IUserRoleListService service = PentahoSystem.get(IUserRoleListService.class); String roles = ""; final ListIterator<String> li = service.getRolesForUser(null, session.getName()).listIterator(); while (li.hasNext()) { roles = roles + li.next().toString() + ","; } // Redirect final HttpServletResponse response = (HttpServletResponse) this.parameterProviders.get("path").getParameter("httpresponse"); response.sendRedirect( "/birt/frameset?__document=" + BIRTfile.getId() + ".rptdocument&__showtitle=false&username="******"&userroles=" + roles + "&reportname=" + BIRTfile.getTitle()); } catch (final Exception e) { Logger.error(getClass().getName(), e.getMessage()); } }
public String getContext(IParameterProvider requestParams) { try { String solution = requestParams.getStringParameter("solution", ""), path = requestParams.getStringParameter("path", ""), // Fix #29. Because there is no file parameter in CDF, but action parameter // file parameter is used in CDE file = requestParams.getStringParameter( "file", requestParams.getStringParameter("action", "")), fullPath = ("/" + solution + "/" + path + "/" + file).replaceAll("/+", "/"); final JSONObject context = new JSONObject(); Calendar cal = Calendar.getInstance(); Document config = getConfigFile(); context.put("queryData", processAutoIncludes(fullPath, config)); context.put("sessionAttributes", processSessionAttributes(config)); context.put("serverLocalDate", cal.getTimeInMillis()); context.put("serverUTCDate", cal.getTimeInMillis() + cal.getTimeZone().getRawOffset()); context.put("user", userSession.getName()); context.put("locale", userSession.getLocale()); context.put("solution", solution); context.put("path", path); context.put("file", file); context.put("fullPath", fullPath); SecurityParameterProvider securityParams = new SecurityParameterProvider(userSession); context.put("roles", securityParams.getParameter("principalRoles")); JSONObject params = new JSONObject(); Iterator it = requestParams.getParameterNames(); while (it.hasNext()) { String p = (String) it.next(); if (p.indexOf("param") == 0) { params.put(p.substring(5), requestParams.getParameter(p)); } } context.put("params", params); final StringBuilder s = new StringBuilder(); s.append("\n<script language=\"javascript\" type=\"text/javascript\">\n"); s.append(" Dashboards.context = "); s.append(context.toString(2) + "\n"); s.append("</script>\n"); // setResponseHeaders(MIME_PLAIN,0,null); logger.info( "[Timing] Finished building context: " + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date())); return s.toString(); } catch (JSONException e) { return ""; } }
private String getUserHomeDirectoryPath() { try { return ClientRepositoryPaths.getUserHomeFolderPath(pentahoSession.getName()); } catch (Exception e) { logger.warn(e.getMessage(), e); } return null; }
/** * Creates and/or returns an internal folder called {@code .trash} located just below the user's * home folder. */ private Node getOrCreateTrashInternalFolderNode( final Session session, final PentahoJcrConstants pentahoJcrConstants) throws RepositoryException { IPentahoSession pentahoSession = PentahoSessionHolder.getSession(); String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY); Node userHomeFolderNode = (Node) session.getItem( ServerRepositoryPaths.getUserHomeFolderPath( new Tenant(tenantId, true), JcrStringHelper.fileNameEncode(PentahoSessionHolder.getSession().getName()))); if (userHomeFolderNode.hasNode(FOLDER_NAME_TRASH)) { return userHomeFolderNode.getNode(FOLDER_NAME_TRASH); } else { return userHomeFolderNode.addNode( FOLDER_NAME_TRASH, pentahoJcrConstants.getPHO_NT_INTERNALFOLDER()); } }
@Test public void testGetUserSettingOnlyGlobalExist() throws Exception { final String settingName = GLOBAL_SETTING_NAME_3; final String defaultValue = "defaultValue"; when(session.getAttribute(eq("SPRING_SECURITY_CONTEXT"))).thenReturn(1); final IUserSetting userSetting = userSettingService.getUserSetting(settingName, defaultValue); assertEquals(settingName, userSetting.getSettingName()); assertEquals(GLOBAL_SETTING_VALUE_3, userSetting.getSettingValue()); }
@Test public void testGetUserSettingUnset() throws Exception { final String settingName = "settingName"; final String defaultValue = "defaultValue"; when(session.getAttribute(eq("SPRING_SECURITY_CONTEXT"))).thenReturn(1); final IUserSetting userSetting = userSettingService.getUserSetting(settingName, defaultValue); assertEquals(settingName, userSetting.getSettingName()); assertEquals(defaultValue, userSetting.getSettingValue()); }
/** * End Audit Event * * @param processId Id for the audit process (usually the plugin name) * @param actionName Name of the action * @param objectName Object of the action * @param userSession Pentaho User Session * @param logger Logger object * @param start Start time in Millis Seconds * @param uuid UUID of start event * @param end End time in Millis Seconds */ public static void endAudit( String processId, String actionName, String objectName, IPentahoSession userSession, ILogger logger, long start, UUID uuid, long end) { AuditHelper.audit( userSession.getId(), userSession.getName(), actionName, objectName, processId, MessageTypes.INSTANCE_END, uuid.toString(), "", ((float) (end - start) / 1000), logger); }
@Override public Domain getDomain(final String id) { final IPentahoSession session = PentahoSessionHolder.getSession(); final CacheKey key = new CacheKey(session.getId(), id); Domain domain = (Domain) cacheManager.getFromRegionCache(CACHE_REGION, key); if (domain != null) { if (logger.isDebugEnabled()) { logger.debug("Found domain in cache: " + key); // $NON-NLS-1$ } return domain; } domain = delegate.getDomain(id); if (domain != null) { SecurityHelper helper = new SecurityHelper(); domain = helper.createSecureDomain(this, domain); // cache domain with the key we used to look it up, not whatever new id it might have now if (logger.isDebugEnabled()) { logger.debug("Caching domain by session: " + key); // $NON-NLS-1$ } cacheManager.putInRegionCache(CACHE_REGION, key, domain); } return domain; }
/** * Start Audit Event * * @param processId Id for the audit process (usually the plugin name) * @param actionName Name of the action * @param objectName Object of the action * @param userSession Pentaho User Session * @param logger Logger object * @param requestParams parameters associated to the request * @return UUID of start event */ public static UUID startAudit( String processId, String actionName, String objectName, IPentahoSession userSession, ILogger logger, IParameterProvider requestParams) { UUID uuid = UUID.randomUUID(); StringBuilder sb = new StringBuilder(); if (requestParams != null) { @SuppressWarnings("unchecked") Iterator<String> iter = requestParams.getParameterNames(); while (iter.hasNext()) { String paramName = iter.next().toString(); sb.append(paramName) .append("=") .append(requestParams.getStringParameter(paramName, "novalue")) .append(";"); } } AuditHelper.audit( userSession.getId(), userSession.getName(), actionName, objectName, processId, MessageTypes.INSTANCE_START, uuid.toString(), sb.toString(), 0, logger); return uuid; }
protected XulDomContainer getXulContainer(String documentPath, IPentahoSession session) { try { ISolutionRepository repo = PentahoSystem.get(ISolutionRepository.class, session); InputStream in = repo.getResourceInputStream(documentPath, true, ISolutionRepository.ACTION_EXECUTE); SAXReader rdr = new SAXReader(); final Document doc = rdr.read(in); XulDomContainer container = getXulLoader().loadXul(doc); return container; } catch (Exception e) { session.error( Messages.getErrorString("BaseMenuProvider.ERROR_0001_COULD_NOT_GET_MENU_CONTAINER"), e); //$NON-NLS-1$ } return null; }
private JSONObject processSessionAttributes(Document config) { JSONObject result = new JSONObject(); @SuppressWarnings("unchecked") List<Node> attributes = config.selectNodes("//sessionattributes/attribute"); for (Node attribute : attributes) { String name = attribute.getText(); String key = XmlDom4JHelper.getNodeText("@name", attribute); if (key == null) key = name; try { result.put(key, userSession.getAttribute(name)); } catch (JSONException e) { logger.error(e); } } return result; }
protected XulMenubar getXulMenubar(String id, String documentPath, IPentahoSession session) { XulDomContainer container = getXulContainer(documentPath, session); if (container == null) { return null; } List<XulComponent> components = container.getDocumentRoot().getElementsByTagName("menubar"); // $NON-NLS-1$ for (XulComponent component : components) { if (component instanceof XulMenubar && component.getId().equals(id)) { XulMenubar menubar = (XulMenubar) component; // now get customizations to it IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, session); List<?> menuCustomizations = pluginManager.getMenuCustomizations(); for (Object custom : menuCustomizations) { if (custom instanceof IMenuCustomization) { IMenuCustomization item = (IMenuCustomization) custom; try { // apply each customization and log any failures MenuUtil.customizeMenu(menubar, item, getXulLoader()); } catch (Exception e) { session.error( Messages.getString( "BaseMenuProvider.ERROR_0004_COULD_NOT_CUSTOMIZE_MENU", item.getId(), item.getLabel()), e); //$NON-NLS-1$ } } } return menubar; } } Logger.error( getClass().getName(), Messages.getErrorString( "BaseMenuProvider.ERROR_0002_COULD_NOT_GET_MENUBAR")); //$NON-NLS-1$ return null; }
/** @throws Exception */ @Before public void setUp() throws Exception { standaloneSession = new StandaloneSession("admin"); standaloneSession.setAttribute("MONDRIAN_SCHEMA_XML_CONTENT", "<mock-schema></mock-schema>"); }
/** {@inheritDoc} */ public void permanentlyDeleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException { Assert.notNull(fileId); Node fileNode = session.getNodeByIdentifier(fileId.toString()); // guard against using a file retrieved from a more lenient session inside a more strict session Assert.notNull(fileNode); // see if anything is referencing this node; if yes, then we cannot delete it as a // ReferentialIntegrityException // will result Set<RepositoryFile> referrers = new HashSet<RepositoryFile>(); PropertyIterator refIter = fileNode.getReferences(); if (refIter.hasNext()) { while (refIter.hasNext()) { // for each referrer property, march up the tree until we find the file node to which the // property belongs RepositoryFile referrer = getReferrerFile(session, pentahoJcrConstants, refIter.nextProperty()); if (referrer != null) { referrers.add(referrer); } } if (!referrers.isEmpty()) { RepositoryFile referee = JcrRepositoryFileUtils.nodeToFile( session, pentahoJcrConstants, pathConversionHelper, lockHelper, fileNode); throw new RepositoryFileDaoReferentialIntegrityException(referee, referrers); } } // technically, the node can be deleted while it is locked; however, we want to avoid an // orphaned lock token; // delete // it first if (fileNode.isLocked()) { Lock lock = session.getWorkspace().getLockManager().getLock(fileNode.getPath()); // don't need lock token anymore lockHelper.removeLockToken(session, pentahoJcrConstants, lock); } // if this file was non-permanently deleted, delete its containing folder too IPentahoSession pentahoSession = PentahoSessionHolder.getSession(); String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY); String trashFolder = ServerRepositoryPaths.getUserHomeFolderPath( new Tenant(tenantId, true), PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + FOLDER_NAME_TRASH; Node parent = fileNode.getParent(); purgeHistory(fileNode, session, pentahoJcrConstants); if (fileNode.getPath().startsWith(trashFolder)) { // Remove the file and then the wrapper foler fileNode.remove(); parent.remove(); } else { fileNode.remove(); } }
/** * 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); }
/** * 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; } }
public DashboardContext(IPentahoSession userSession) { logger.debug("Creating Context for user " + userSession.getName()); this.userSession = userSession; }
/** * 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; }
private ITenant getDefaultTenant() { IPentahoSession session = PentahoSessionHolder.getSession(); String tenantId = (String) session.getAttribute(IPentahoSession.TENANT_ID_KEY); return new Tenant(tenantId, true); }
public void createReportContent( final OutputStream outputStream, final Serializable fileId, final String path, final boolean forceDefaultOutputTarget) throws Exception { final long start = System.currentTimeMillis(); final Map<String, Object> inputs = contentGenerator.createInputs(); AuditHelper.audit( userSession.getId(), userSession.getName(), path, contentGenerator.getObjectName(), getClass().getName(), MessageTypes.INSTANCE_START, contentGenerator.getInstanceId(), "", 0, contentGenerator); //$NON-NLS-1$ String result = MessageTypes.INSTANCE_END; StagingHandler reportStagingHandler = null; try { final Object rawSessionId = inputs.get(ParameterXmlContentHandler.SYS_PARAM_SESSION_ID); if ((rawSessionId instanceof String) == false || "".equals(rawSessionId)) { inputs.put(ParameterXmlContentHandler.SYS_PARAM_SESSION_ID, UUIDUtil.getUUIDAsString()); } // produce rendered report final SimpleReportingComponent reportComponent = new SimpleReportingComponent(); reportComponent.setReportFileId(fileId); reportComponent.setPaginateOutput(true); reportComponent.setForceDefaultOutputTarget(forceDefaultOutputTarget); reportComponent.setDefaultOutputTarget(HtmlTableModule.TABLE_HTML_PAGE_EXPORT_TYPE); if (path.endsWith(".prpti")) { reportComponent.setForceUnlockPreferredOutput(true); } reportComponent.setInputs(inputs); final MasterReport report = reportComponent.getReport(); final StagingMode stagingMode = getStagingMode(inputs, report); reportStagingHandler = new StagingHandler(outputStream, stagingMode, this.userSession); if (reportStagingHandler.isFullyBuffered()) { // it is safe to disable the buffered writing for the report now that we have a // extra buffering in place. report.getReportConfiguration().setConfigProperty(FORCED_BUFFERED_WRITING, "false"); } reportComponent.setOutputStream(reportStagingHandler.getStagingOutputStream()); // the requested mime type can be null, in that case the report-component will resolve the // desired // type from the output-target. // Hoever, the report-component will inspect the inputs independently from the mimetype here. final IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class, userSession); final RepositoryFile file = repository.getFileById(fileId); // add all inputs (request parameters) to report component final String mimeType = reportComponent.getMimeType(); // If we haven't set an accepted page, -1 will be the default, which will give us a report // with no pages. This default is used so that when we do our parameter interaction with the // engine we can spend as little time as possible rendering unused pages, making it no pages. // We are going to intentionally reset the accepted page to the first page, 0, at this point, // if the accepted page is -1. final String outputTarget = reportComponent.getComputedOutputTarget(); if (HtmlTableModule.TABLE_HTML_PAGE_EXPORT_TYPE.equals(outputTarget) && reportComponent.getAcceptedPage() < 0) { reportComponent.setAcceptedPage(0); } if (logger.isDebugEnabled()) { logger.debug( Messages.getInstance() .getString( "ReportPlugin.logStartGenerateContent", mimeType, //$NON-NLS-1$ outputTarget, String.valueOf(reportComponent.getAcceptedPage()))); } HttpServletResponse response = null; boolean streamToBrowser = false; final IParameterProvider pathProviders = contentGenerator.getParameterProviders().get("path"); if (pathProviders != null) { final Object httpResponse = pathProviders.getParameter("httpresponse"); if (httpResponse instanceof HttpServletResponse) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ response = (HttpServletResponse) httpResponse; // $NON-NLS-1$ //$NON-NLS-2$ if (reportStagingHandler.getStagingMode() == StagingMode.THRU) { // Direct back - check output stream... final OutputStream respOutputStream = response.getOutputStream(); if (respOutputStream == outputStream) { // // Massive assumption here - // Assume the container returns the same object on successive calls to // response.getOutputStream() streamToBrowser = true; } } } } final String extension = MimeHelper.getExtension(mimeType); String filename = file.getName(); if (filename.lastIndexOf(".") != -1) { // $NON-NLS-1$ filename = filename.substring(0, filename.lastIndexOf(".")); // $NON-NLS-1$ } String disposition = "inline; filename*=UTF-8''" + RepositoryPathEncoder.encode( RepositoryPathEncoder.encodeRepositoryPath(filename + extension)); final boolean validates = reportComponent.validate(); if (!validates) { sendErrorResponse(response, outputStream, reportStagingHandler); } else { if (response != null) { // Send headers before we begin execution response.setHeader("Content-Disposition", disposition); response.setHeader("Content-Description", file.getName()); // $NON-NLS-1$ response.setHeader("Cache-Control", "private, max-age=0, must-revalidate"); } if (reportComponent.execute()) { if (response != null) { if (reportStagingHandler.canSendHeaders()) { response.setHeader("Content-Disposition", disposition); response.setHeader("Content-Description", file.getName()); // $NON-NLS-1$ response.setHeader("Cache-Control", "private, max-age=0, must-revalidate"); response.setContentLength(reportStagingHandler.getWrittenByteCount()); } } if (logger.isDebugEnabled()) { logger.debug( Messages.getInstance() .getString( "ReportPlugin.logEndGenerateContent", String.valueOf(reportStagingHandler.getWrittenByteCount()))); // $NON-NLS-1$ } reportStagingHandler.complete(); // will copy bytes to final destination... } else { // failed execution sendErrorResponse(response, outputStream, reportStagingHandler); } } } catch (Exception ex) { result = MessageTypes.INSTANCE_FAILED; throw ex; } finally { if (reportStagingHandler != null) { reportStagingHandler.close(); } final long end = System.currentTimeMillis(); AuditHelper.audit( userSession.getId(), userSession.getName(), path, contentGenerator.getObjectName(), getClass().getName(), result, contentGenerator.getInstanceId(), "", ((float) (end - start) / 1000), contentGenerator); //$NON-NLS-1$ } }
protected String generateDomainIdCacheKeyForSession(IPentahoSession session) { return DOMAIN_CACHE_KEY_PREDICATE + session.getId(); }