SystemUtils { public static boolean canDownload( String downloadDir ) { IAuthorizationPolicy policy = PentahoSystem.get( IAuthorizationPolicy.class ); IUserRoleListService userRoleListService = PentahoSystem.get( IUserRoleListService.class ); String tenantedUserName = PentahoSessionHolder.getSession().getName(); List<String> tenantedUserRoles = userRoleListService.getRolesForUser( JcrTenantUtils.getUserNameUtils().getTenant( tenantedUserName ), tenantedUserName ); boolean isAdminOrHaveDownloadActionRole = policy.isAllowed( RepositoryReadAction.NAME ) && policy.isAllowed( RepositoryCreateAction.NAME ) && ( policy.isAllowed( AdministerSecurityAction.NAME ) || !Collections.disjoint( tenantedUserRoles, PentahoSystem.getDownloadRolesList() ) ); if ( !isAdminOrHaveDownloadActionRole && !StringUtils.isEmpty( downloadDir ) ) { return validateAccessToHomeFolder( downloadDir ); } return isAdminOrHaveDownloadActionRole; }  static boolean canAdminister(); static boolean canUpload( String uploadDir ); static boolean canDownload( String downloadDir ); static boolean validateAccessToHomeFolder( String dir );  }
@Test public void testCanDownload() { IAuthorizationPolicy mockAuthPolicy = mock( IAuthorizationPolicy.class ); PentahoSystem.registerObject( mockAuthPolicy ); doReturn( true ).when( mockAuthPolicy ).isAllowed( RepositoryReadAction.NAME ); doReturn( true ).when( mockAuthPolicy ).isAllowed( RepositoryCreateAction.NAME ); doReturn( false ).when( mockAuthPolicy ).isAllowed( AdministerSecurityAction.NAME ); assertFalse( SystemUtils.canDownload( "" ) ); doReturn( true ).when( mockAuthPolicy ).isAllowed( AdministerSecurityAction.NAME ); assertTrue( SystemUtils.canDownload( "/mock/path" ) ); doReturn( false ).when( mockAuthPolicy ).isAllowed( AdministerSecurityAction.NAME ); assertFalse( SystemUtils.canDownload( "/mock/path" ) ); assertTrue( SystemUtils.canDownload( IMPORT_DIR ) ); doReturn( false ).when( mockAuthPolicy ).isAllowed( RepositoryReadAction.NAME ); assertFalse( SystemUtils.canDownload( IMPORT_DIR ) ); }