1 19 20 package com.sslexplorer.networkplaces.actions; 21 22 import java.io.IOException ; 23 import java.net.UnknownHostException ; 24 import java.text.SimpleDateFormat ; 25 import java.util.ArrayList ; 26 import java.util.Calendar ; 27 import java.util.GregorianCalendar ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Map ; 32 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 import org.apache.commons.vfs.FileSystemException; 39 import org.apache.commons.vfs.FileType; 40 import org.apache.struts.Globals; 41 import org.apache.struts.action.ActionError; 42 import org.apache.struts.action.ActionForm; 43 import org.apache.struts.action.ActionForward; 44 import org.apache.struts.action.ActionMapping; 45 import org.apache.struts.action.ActionMessage; 46 import org.apache.struts.action.ActionMessages; 47 48 import com.sslexplorer.boot.Util; 49 import com.sslexplorer.core.BundleActionMessage; 50 import com.sslexplorer.core.CoreEvent; 51 import com.sslexplorer.core.CoreException; 52 import com.sslexplorer.core.CoreServlet; 53 import com.sslexplorer.core.CoreUtil; 54 import com.sslexplorer.core.FileDownloadPageInterceptListener; 55 import com.sslexplorer.core.PopupException; 56 import com.sslexplorer.core.actions.AbstractPopupAuthenticatedDispatchAction; 57 import com.sslexplorer.networkplaces.NetworkPlace; 58 import com.sslexplorer.networkplaces.NetworkPlacePlugin; 59 import com.sslexplorer.networkplaces.NetworkPlaceResourceType; 60 import com.sslexplorer.networkplaces.NetworkPlaceUploadHandler; 61 import com.sslexplorer.networkplaces.NetworkPlacesAccessEvent; 62 import com.sslexplorer.networkplaces.NetworkPlacesException; 63 import com.sslexplorer.networkplaces.clipboard.NetworkPlaceClipboardContent; 64 import com.sslexplorer.networkplaces.forms.FileSystemForm; 65 import com.sslexplorer.networkplaces.model.FileItem; 66 import com.sslexplorer.networkplaces.model.FileSystemItem; 67 import com.sslexplorer.networkplaces.model.FolderItem; 68 import com.sslexplorer.policyframework.LaunchSession; 69 import com.sslexplorer.policyframework.LaunchSessionFactory; 70 import com.sslexplorer.policyframework.NoPermissionException; 71 import com.sslexplorer.security.AbstractHTTPAuthenticationModule; 72 import com.sslexplorer.security.Constants; 73 import com.sslexplorer.security.LogonControllerFactory; 74 import com.sslexplorer.security.SessionInfo; 75 import com.sslexplorer.vfs.FileObjectVFSResource; 76 import com.sslexplorer.vfs.UploadDetails; 77 import com.sslexplorer.vfs.VFSRepository; 78 import com.sslexplorer.vfs.VFSResource; 79 import com.sslexplorer.vfs.ZipDownload; 80 import com.sslexplorer.vfs.clipboard.Clipboard; 81 import com.sslexplorer.vfs.clipboard.ClipboardContent; 82 import com.sslexplorer.vfs.webdav.DAVAuthenticationRequiredException; 83 import com.sslexplorer.vfs.webdav.DAVException; 84 import com.sslexplorer.vfs.webdav.DAVTransaction; 85 import com.sslexplorer.vfs.webdav.DAVUtilities; 86 87 98 public class FileSystemViewDispatchAction extends AbstractPopupAuthenticatedDispatchAction { 99 100 final static Log log = LogFactory.getLog(FileSystemViewDispatchAction.class); 101 102 final static List <String > NO_DELETE = new ArrayList <String >(); 103 final static List <String > READ_ONLY = new ArrayList <String >(); 104 105 static { 106 NO_DELETE.add("delete"); 109 NO_DELETE.add("deleteFile"); 110 111 READ_ONLY.add("delete"); 112 READ_ONLY.add("deleteFile"); 113 READ_ONLY.add("cut"); 114 READ_ONLY.add("cutFile"); 115 READ_ONLY.add("paste"); 116 READ_ONLY.add("pasteFile"); 117 READ_ONLY.add("showMkDir"); 118 READ_ONLY.add("upload"); 119 } 120 121 124 public FileSystemViewDispatchAction() { 125 super(null, null, NetworkPlacePlugin.NETWORK_PLACE_RESOURCE_TYPE); 126 } 127 128 136 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 137 throws Exception { 138 try { 139 ActionForward fwd = super.execute(mapping, form, request, response); 140 return fwd; 143 } catch (PopupException pe) { 144 Throwable cause = pe.getCause(); 145 if (cause instanceof CoreException) { 146 ActionMessages errs = getErrors(request); 147 errs.add(Globals.ERROR_KEY, ((CoreException) cause).getBundleActionMessage()); 148 saveErrors(request, errs); 149 return mapping.getInputForward(); 150 } else if (cause instanceof DAVException) { 151 log.error("File system operation failed.", cause); 152 String maskedException = NetworkPlacesAccessEvent.maskSensitiveArguments(cause.getMessage()); 153 throw new IOException (maskedException); 154 } else if (cause instanceof FileSystemException) { 155 log.error("File system operation failed.", cause); 156 String maskedException = NetworkPlacesAccessEvent.maskSensitiveArguments(cause.getMessage()); 157 throw new IOException (maskedException); 158 } 159 throw pe; 160 } 161 } 162 163 171 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, 172 HttpServletResponse response) throws Exception { 173 return super.unspecified(mapping, form, request, response); 174 } 175 176 189 public ActionForward home(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 190 throws Exception { 191 if (log.isDebugEnabled()) 192 log.debug("List files."); 193 FileSystemForm fileSystemForm = (FileSystemForm) form; 194 195 try { 196 VFSResource res = checkLaunchSession(request, response, fileSystemForm); 197 return new ActionForward(mapping.getPath() + ".do?actionTarget=list&path=" + res.getMount().getMountString() + "&" + LaunchSession.LAUNCH_ID + "=" + fileSystemForm.getLaunchId(), true); 198 199 } catch (DAVAuthenticationRequiredException e) { 200 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 201 return null; 202 } 203 204 } 205 206 218 public ActionForward gotoPath(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 219 throws Exception { 220 if (log.isDebugEnabled()) 221 log.debug("goto path location."); 222 FileSystemForm fileSystemForm = (FileSystemForm) form; 223 fileSystemForm.clearPathsTo(request.getParameter("id")); 224 return this.list(mapping, fileSystemForm, request, response); 225 } 226 227 239 public ActionForward renameFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 240 throws Exception { 241 if (log.isDebugEnabled()) 242 log.debug("rename the file."); 243 FileSystemForm fileSystemForm = (FileSystemForm) form; 244 245 checkLaunchSession(request, response, fileSystemForm); 246 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 247 if (fwd != null) { 248 return fwd; 249 } 250 251 VFSResource sourceResource = null; 252 VFSResource destResource = null; 253 try { 254 sourceResource = getResourceForPath(fileSystemForm.getLaunchSession(), 255 request, 256 response, 257 fileSystemForm.getPath() + "/" + fileSystemForm.getFileName()); 258 destResource = getResourceForPath(fileSystemForm.getLaunchSession(), request, response, fileSystemForm.getPath() + "/" 259 + fileSystemForm.getNewName()); 260 261 if (sourceResource == null) { 262 throw new Exception ("Could not locate source resource '" + fileSystemForm.getPath() 263 + "/" 264 + fileSystemForm.getFileName() 265 + "'"); 266 } 267 if (destResource == null) { 268 throw new Exception ("Could not locate destination resource '" + fileSystemForm.getPath() 269 + "/" 270 + fileSystemForm.getNewName() 271 + "'"); 272 } 273 274 if(sourceResource.getFullPath().equals(destResource.getFullPath())) { 275 return mapping.findForward("list"); 276 } 277 278 fwd = checkMount(destResource, mapping, fileSystemForm, request); 279 if (fwd != null) { 280 return fwd; 281 } 282 sourceResource.move(destResource, true); 283 284 if (sourceResource.getMount().getStore().getProvider().isFireEvents()) { 285 CoreServlet.getServlet().fireCoreEvent(NetworkPlaceResourceType.getResourceAccessRenameEvent(this, 286 fileSystemForm.getLaunchSession(), 287 request, 288 fileSystemForm.getPath(), 289 fileSystemForm.getFullURI(), 290 sourceResource.getDisplayName(), 291 destResource.getDisplayName(), 292 null)); 293 } 294 295 } catch (DAVAuthenticationRequiredException e) { 296 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 297 return null; 298 } catch (Exception e) { 299 if (sourceResource != null && destResource != null) { 300 if (sourceResource.getMount().getStore().getProvider().isFireEvents()) { 301 CoreServlet.getServlet().fireCoreEvent(NetworkPlaceResourceType.getResourceAccessRenameEvent(this, 302 fileSystemForm.getLaunchSession(), 303 request, 304 fileSystemForm.getPath(), 305 fileSystemForm.getFullURI(), 306 sourceResource.getDisplayName(), 307 destResource.getDisplayName(), 308 e)); 309 } 310 } 311 } 312 313 return mapping.findForward("list"); 314 } 315 316 328 public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 329 throws Exception { 330 if (log.isDebugEnabled()) 331 log.debug("List files."); 332 FileSystemForm fileSystemForm = (FileSystemForm) form; 333 checkLaunchSession(request, response, fileSystemForm); 334 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 335 if (fwd != null) { 336 return fwd; 337 } 338 ActionForward returnTo = new ActionForward("/fileSystem.do?" + LaunchSession.LAUNCH_ID + "=" + fileSystemForm.getLaunchSession().getId() 339 + "&actionTarget=list&path=" 340 + DAVUtilities.encodePath(fileSystemForm.getPath()), true); 341 UploadDetails details = new UploadDetails(NetworkPlacePlugin.MESSAGE_RESOURCES_KEY, 342 NetworkPlaceUploadHandler.TYPE_VFS, 343 fileSystemForm.getPath(), 344 mapping.findForward("upload"), 345 returnTo, 346 null); 347 details.setExtraAttribute1(fileSystemForm.getPath()); 348 details.setExtraAttribute2(fileSystemForm.getLaunchSession().getId()); 349 request.setAttribute(Constants.REQ_ATTR_UPLOAD_DETAILS, new Integer (CoreUtil.addUpload(request.getSession(), details))); 350 return mapping.findForward("upload"); 351 } 352 353 363 public ActionForward filter(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 364 throws Exception { 365 return list(mapping, form, request, response); 366 } 367 368 378 public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 379 throws Exception { 380 if (log.isDebugEnabled()) 381 log.debug("List files."); 382 FileSystemForm fileSystemForm = (FileSystemForm) form; 383 384 try { 385 VFSResource res = checkLaunchSession(request, response, fileSystemForm); 386 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 387 if (fwd != null) { 388 return fwd; 389 } 390 fwd = checkMount(res, mapping, fileSystemForm, request); 391 if (fwd != null) { 392 return fwd; 393 } 394 395 402 410 buildModel(res, fileSystemForm, request); 411 if (res.getMount().getStore().getProvider().isFireEvents()) { 412 CoreServlet.getServlet().fireCoreEvent(NetworkPlaceResourceType.getResourceAccessListEvent(this, 413 fileSystemForm.getLaunchSession(), 414 request, 415 fileSystemForm.getPath(), 416 fileSystemForm.getFullURI(), 417 null)); 418 } 419 } catch (DAVAuthenticationRequiredException e) { 420 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 421 return null; 422 } catch (UnknownHostException e) { 423 ActionMessages errs = getErrors(request); 424 errs.add(Globals.ERROR_KEY, new ActionMessage("error.networkPlaces.unknown.host", e.getMessage())); 425 saveErrors(request, errs); 426 return mapping.findForward("display"); 427 } catch (Exception e) { 428 CoreServlet.getServlet().fireCoreEvent(NetworkPlaceResourceType.getResourceAccessListEvent(this, 429 fileSystemForm.getLaunchSession(), 430 request, 431 fileSystemForm.getPath(), 432 fileSystemForm.getFullURI(), 433 e)); 434 435 ActionMessages errs = getErrors(request); 436 errs.add(Globals.ERROR_KEY, new ActionMessage("error.networkPlaces.generic", NetworkPlacesAccessEvent.maskSensitiveArguments(e.getMessage()))); 437 saveErrors(request, errs); 438 String stacktraceAsString = NetworkPlacesAccessEvent.maskSensitiveArguments(CoreUtil.toString(e)); 439 log.error("File system error:" + stacktraceAsString); 440 return mapping.findForward("display"); 441 } 442 443 return mapping.findForward("display"); 444 } 445 446 456 public ActionForward launch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 457 throws Exception { 458 if (log.isDebugEnabled()) 459 log.debug("Launch network place."); 460 return list(mapping, form, request, response); 461 } 462 463 void buildModel(VFSResource res, FileSystemForm fileSystemForm, HttpServletRequest request) throws Exception { 464 List <FileSystemItem> allFileSystemItems = new ArrayList <FileSystemItem>(); 465 ActionMessages warnings = new ActionMessages(); 466 if (res != null) { 467 Iterator itr = res.getChildren(); 468 469 for (int i = 0; itr != null && itr.hasNext(); i++) { 470 Calendar gc = new GregorianCalendar () { 472 public String toString() { 473 return SimpleDateFormat.getInstance().format(this.getTime()); 474 } 475 }; 476 gc.setTimeInMillis(0); 477 FileObjectVFSResource element = (FileObjectVFSResource) itr.next(); 478 FileType ft = null; 480 try { 481 ft = element.getFile().getType(); 482 } catch (FileSystemException e) { 483 } catch (IOException e) { 484 } 485 FileSystemItem item = null; 486 if (ft != null && element.getFile().getType().equals(FileType.FOLDER) 487 && fileSystemForm.getNetworkPlace().isAllowRecursive()) { 488 if(element.getLastModified() != null) 490 gc.setTime(element.getLastModified()); 491 item = new FolderItem(fileSystemForm.getLaunchSession(), element.getDisplayName(), res.getMount() 492 .getStore() 493 .getName(), fileSystemForm.getPath(), gc, element.getFile().getType().getName(), false, i); 494 } else if (ft != null && element.getFile().getType().equals(FileType.FILE)) { 495 if(element.getLastModified() != null) 497 gc.setTime(element.getLastModified()); 498 item = new FileItem(fileSystemForm.getLaunchSession(), element.getDisplayName(), element.getContentLength() 499 .longValue(), gc, element.getFile().getType().getName(), false, i); 500 } else { 501 if (log.isInfoEnabled()) 502 log.info("Unable to display file " + element.getDisplayName() + " as it is an imaginary file."); 503 warnings.add(Constants.REQ_ATTR_WARNINGS, new BundleActionMessage(NetworkPlacePlugin.MESSAGE_RESOURCES_KEY, 504 "vfs.imaginary.file", 505 element.getDisplayName())); 506 507 i--; 509 } 510 if (item != null) { 511 allFileSystemItems.add(item); 512 if (request.getParameter("select" + Util.urlEncode(item.getFileName())) != null) { 513 item.setChecked(true); 514 } 515 } 516 } 517 if (fileSystemForm.getPaths() == null || fileSystemForm.getPaths().isEmpty()) { 518 fileSystemForm.setHome(fileSystemForm.getPath()); 519 } else { 520 fileSystemForm.addPath(fileSystemForm.getPath()); 521 } 522 } 523 if (warnings.size() > 0) { 524 addWarnings(request, warnings); 525 } 526 fileSystemForm.initialize(request, allFileSystemItems, this.getSessionInfo(request)); 527 } 528 529 VFSResource checkLaunchSession(HttpServletRequest request, HttpServletResponse response, FileSystemForm fileSystemForm) 530 throws Exception { 531 LaunchSession launchSession = fileSystemForm.getLaunchSession(); 532 if (launchSession == null) { 533 if (fileSystemForm.getLaunchId() == null || fileSystemForm.getLaunchId() == "") { 534 launchSession = new LaunchSession(getSessionInfo(request)); 536 } 537 else { 538 launchSession = LaunchSessionFactory.getInstance().getLaunchSession(getSessionInfo(request), fileSystemForm.getLaunchId()); 539 } 540 if(launchSession == null) { 541 throw new Exception ("No launch session."); 542 } 543 fileSystemForm.setLaunchSession(launchSession); 544 } 545 DAVTransaction transaction = new DAVTransaction(request, response); 546 VFSRepository repository = VFSRepository.getRepository(launchSession.getSession()); 547 VFSResource res = repository.getResource(launchSession, fileSystemForm.getPath(), transaction.getCredentials()); 548 if (res == null) { 549 throw new Exception ("Could not find network place resource for path " + fileSystemForm.getPath() + "."); 550 } 551 fileSystemForm.setVFSResource(res); 552 return res; 553 } 554 555 VFSResource getResourceForPath(LaunchSession launchSession, HttpServletRequest request, HttpServletResponse response, 556 String path) throws Exception { 557 558 DAVTransaction transaction = new DAVTransaction(request, response); 559 560 VFSRepository repository = VFSRepository.getRepository(LogonControllerFactory.getInstance().getSessionInfo(request)); 561 VFSResource res = repository.getResource(launchSession, path, transaction.getCredentials()); 562 563 if (res == null) { 564 throw new Exception ("Could not find network place resource for path " + path + "."); 565 } 566 return res; 567 } 568 569 577 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 578 return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT; 579 } 580 581 593 public ActionForward zip(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 594 throws Exception { 595 if (log.isDebugEnabled()) 596 log.debug("Zip files."); 597 598 FileSystemForm fileSystemForm = (FileSystemForm) form; 599 600 try { 601 VFSResource res = checkLaunchSession(request, response, fileSystemForm); 602 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 603 if (fwd != null) { 604 return fwd; 605 } 606 buildModel(res, fileSystemForm, request); 607 String [] uris = fileSystemForm.getSelectedFileNames(); 608 if (uris == null || uris.length < 1) { 609 ActionMessages msgs = getErrors(request); 610 msgs.add(Globals.ERROR_KEY, new ActionMessage("vfs.zip.select.error")); 611 saveErrors(request, msgs); 612 return mapping.getInputForward(); 613 } 614 return zipSelection(mapping, request, fileSystemForm, uris); 615 } catch (DAVAuthenticationRequiredException e) { 616 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 617 return null; 618 } 619 } 620 621 631 private ActionForward zipSelection(ActionMapping mapping, HttpServletRequest request, FileSystemForm fileSystemForm, 632 String [] uris) { 633 ActionForward fwd = mapping.findForward("showFileDownload"); 634 647 FileDownloadPageInterceptListener l = (FileDownloadPageInterceptListener) CoreUtil.getPageInterceptListenerById(request.getSession(), 648 FileDownloadPageInterceptListener.INTERCEPT_ID); 649 if (l == null) { 650 l = new FileDownloadPageInterceptListener(); 651 CoreUtil.addPageInterceptListener(request.getSession(), l); 652 } 653 int id = l.addDownload(new ZipDownload(fileSystemForm.getLaunchSession(), 654 fwd, 655 fileSystemForm.getPath(), 656 uris, 657 new ActionForward("/fileSystem.do?actionTarget=list&path=" + fileSystemForm.getPath() + "&" + LaunchSession.LAUNCH_ID + "=" + fileSystemForm.getLaunchId()), 658 "downloadZip.message", 659 NetworkPlacePlugin.MESSAGE_RESOURCES_KEY)); 660 661 CoreEvent evt = NetworkPlaceResourceType.getResourceAccessZipEvent(this, 662 fileSystemForm.getLaunchSession(), 663 request, 664 fileSystemForm.getPath(), 665 fileSystemForm.getFullURI(), 666 null); 667 int fileCounter = 1; 668 int directorieCounter = 1; 669 for (int i = 0; i < uris.length; i++) { 670 if (uris[i].endsWith("/")) { 671 NetworkPlaceResourceType.addDirectoryAttribute(evt, uris[i], directorieCounter); 672 directorieCounter++; 673 } else { 674 NetworkPlaceResourceType.addFileAttribute(evt, uris[i], fileCounter); 675 fileCounter++; 676 } 677 } 678 CoreServlet.getServlet().fireCoreEvent(evt); 679 return CoreUtil.addParameterToForward(fwd, "id", String.valueOf(id)); 680 } 681 682 694 public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 695 throws Exception { 696 if (log.isDebugEnabled()) 697 log.debug("Delete files."); 698 FileSystemForm fileSystemForm = (FileSystemForm) form; 699 700 try { 701 VFSResource res = checkLaunchSession(request, response, fileSystemForm); 702 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 703 if (fwd != null) { 704 return fwd; 705 } 706 fwd = checkMount(res, mapping, fileSystemForm, request); 707 if (fwd != null) { 708 return fwd; 709 } 710 buildModel(res, fileSystemForm, request); 711 String [] uris = fileSystemForm.getSelectedFileNames(); 712 for (int i = 0; i < uris.length; i++) { 713 String delPath = fileSystemForm.getPath() + "/" + uris[i]; 714 deleteSingleFile(request, response, delPath, fileSystemForm); 715 } 716 return mapping.findForward("list"); 717 } catch (DAVAuthenticationRequiredException e) { 718 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 719 return null; 720 } 721 } 722 723 735 public ActionForward deleteSelected(ActionMapping mapping, ActionForm form, HttpServletRequest request, 736 HttpServletResponse response) throws Exception { 737 if (log.isDebugEnabled()) 738 log.debug("Delete selected files."); 739 FileSystemForm fileSystemForm = (FileSystemForm) form; 740 741 try { 742 VFSResource res = checkLaunchSession(request, response, fileSystemForm); 743 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 744 if (fwd != null) { 745 return fwd; 746 } 747 fwd = checkMount(res, mapping, fileSystemForm, request); 748 if (fwd != null) { 749 return fwd; 750 } 751 buildModel(res, fileSystemForm, request); 752 Object [] uris = fileSystemForm.getSelectedFileNames(); 753 if (uris == null || uris.length < 1) { 754 ActionMessages msgs = getErrors(request); 755 msgs.add(Globals.ERROR_KEY, new ActionMessage("vfs.delete.select.error")); 756 saveErrors(request, msgs); 757 return mapping.getInputForward(); 758 } 759 return mapping.findForward("deleteFiles"); 760 } catch (DAVAuthenticationRequiredException e) { 761 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 762 return null; 763 } 764 } 765 766 778 public ActionForward deleteFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 779 throws Exception { 780 if (log.isDebugEnabled()) 781 log.debug("Delete file."); 782 FileSystemForm fileSystemForm = (FileSystemForm) form; 783 784 try { 785 VFSResource res = checkLaunchSession(request, response, fileSystemForm); 786 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 787 if (fwd != null) { 788 return fwd; 789 } 790 fwd = checkMount(res, mapping, fileSystemForm, request); 791 if (fwd != null) { 792 return fwd; 793 } 794 buildModel(res, fileSystemForm, request); 795 String delPath = fileSystemForm.getPath() + "/" + fileSystemForm.getFileName(); 796 deleteSingleFile(request, response, delPath, fileSystemForm); 797 return mapping.findForward("list"); 798 } catch (DAVAuthenticationRequiredException e) { 799 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 800 return null; 801 } 802 } 803 804 816 public ActionForward confirmDeleteFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, 817 HttpServletResponse response) throws Exception { 818 if (log.isDebugEnabled()) 819 log.debug("Delete file."); 820 FileSystemForm fileSystemForm = (FileSystemForm) form; 821 822 try { 823 VFSResource res = checkLaunchSession(request, response, fileSystemForm); 824 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 825 if (fwd != null) { 826 return fwd; 827 } 828 fwd = checkMount(res, mapping, fileSystemForm, request); 829 if (fwd != null) { 830 return fwd; 831 } 832 buildModel(res, fileSystemForm, request); 833 return mapping.findForward("deleteFile"); 834 } catch (DAVAuthenticationRequiredException e) { 835 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 836 return null; 837 } 838 } 839 840 853 public ActionForward cutFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 854 throws Exception { 855 if (log.isDebugEnabled()) 856 log.debug("Cut file."); 857 FileSystemForm fileSystemForm = (FileSystemForm) form; 858 859 try { 860 checkLaunchSession(request, response, fileSystemForm); 861 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 862 if (fwd != null) { 863 return fwd; 864 } 865 addToClipboard(request, fileSystemForm, true); 866 return mapping.findForward("list"); 867 } catch (DAVAuthenticationRequiredException e) { 868 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 869 return null; 870 } 871 } 872 873 878 private void addToClipboard(HttpServletRequest request, FileSystemForm fileSystemForm, boolean delOrig) { 879 String delPath = fileSystemForm.getPath() + "/" + fileSystemForm.getFileName(); 880 ActionMessages msgs = new ActionMessages(); 881 Clipboard cb = new Clipboard(); 882 NetworkPlaceClipboardContent fcc = new NetworkPlaceClipboardContent(delPath, delOrig); 883 cb.addContent(fcc); 884 request.getSession().setAttribute(Constants.CLIPBOARD, cb); 885 msgs.add(Globals.MESSAGE_KEY, new ActionMessage("vfs.copy.to.clipboard", fileSystemForm.getFileName())); 886 this.addMessages(request, msgs); 887 } 888 889 902 public ActionForward copyFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 903 throws Exception { 904 if (log.isDebugEnabled()) 905 log.debug("Copy file."); 906 FileSystemForm fileSystemForm = (FileSystemForm) form; 907 908 try { 909 checkLaunchSession(request, response, fileSystemForm); 910 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 911 if (fwd != null) { 912 return fwd; 913 } 914 addToClipboard(request, fileSystemForm, false); 915 return mapping.findForward("list"); 916 } catch (DAVAuthenticationRequiredException e) { 917 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 918 return null; 919 } 920 } 921 922 934 public ActionForward zipFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 935 throws Exception { 936 if (log.isDebugEnabled()) 937 log.debug("Zip file."); 938 FileSystemForm fileSystemForm = (FileSystemForm) form; 939 940 try { 941 checkLaunchSession(request, response, fileSystemForm); 942 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 943 if (fwd != null) { 944 return fwd; 945 } 946 String [] uris = { fileSystemForm.getFileName() }; 947 return zipSelection(mapping, request, fileSystemForm, uris); 948 } catch (DAVAuthenticationRequiredException e) { 949 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 950 return null; 951 } 952 } 953 954 967 public ActionForward confirmPasteFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 968 throws Exception { 969 return pasteFile(mapping, form, request, response, true); 970 } 971 972 985 public ActionForward pasteOverwriteFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 986 throws Exception { 987 return pasteFile(mapping, form, request, response, false); 988 } 989 990 private ActionForward pasteFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, boolean requiresOverwriteCheck) 991 throws Exception { 992 if (log.isDebugEnabled()) { 993 log.debug("Paste file."); 994 } 995 try { 996 FileSystemForm fileSystemForm = (FileSystemForm) form; 997 checkLaunchSession(request, response, fileSystemForm); 998 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 999 if (fwd != null) { 1000 return fwd; 1001 } 1002 1003 String path = DAVUtilities.concatenatePaths(fileSystemForm.getPath(), fileSystemForm.getFileName()); 1004 if (requiresOverwriteCheck) { 1005 boolean isOverwritingFiles = isOverwritingFiles(request, response, path, fileSystemForm); 1006 if (isOverwritingFiles) { 1007 return mapping.findForward("pasteOverwriteFiles"); 1008 } 1009 } 1010 1011 pasteFromClipboard(request, response, path, fileSystemForm); 1012 return mapping.findForward("list"); 1013 } catch (DAVAuthenticationRequiredException e) { 1014 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 1015 return null; 1016 } 1017 } 1018 1019 1026 private void deleteSingleFile(HttpServletRequest request, HttpServletResponse response, String delPath, 1027 FileSystemForm fileSystemForm) throws Exception { 1028 VFSResource res = getResourceForPath(fileSystemForm.getLaunchSession(), request, response, delPath); 1029 if (log.isDebugEnabled()) 1030 log.debug("Deleting " + res.getRelativePath()); 1031 String name = null; 1032 try { 1033 name = res.getDisplayName(); 1034 res.delete(); 1035 if (res.getMount().getStore().getProvider().isFireEvents()) { 1036 CoreServlet.getServlet().fireCoreEvent(NetworkPlaceResourceType.getResourceAccessDeleteEvent(this, 1037 fileSystemForm.getLaunchSession(), 1038 request, 1039 fileSystemForm.getPath(), 1040 fileSystemForm.getFullURI(), 1041 name, 1042 null)); 1043 } 1044 } catch (Exception e) { 1045 if (res.getMount().getStore().getProvider().isFireEvents()) { 1046 CoreServlet.getServlet().fireCoreEvent(NetworkPlaceResourceType.getResourceAccessDeleteEvent(this, 1047 fileSystemForm.getLaunchSession(), 1048 request, 1049 fileSystemForm.getPath(), 1050 fileSystemForm.getFullURI(), 1051 name, 1052 e)); 1053 } 1054 throw e; 1055 } 1056 1057 } 1058 1059 1072 public ActionForward cut(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 1073 throws Exception { 1074 if (log.isDebugEnabled()) 1075 log.debug("Cut files."); 1076 FileSystemForm fileSystemForm = (FileSystemForm) form; 1077 1078 try { 1079 VFSResource res = checkLaunchSession(request, response, fileSystemForm); 1080 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 1081 if (fwd != null) { 1082 return fwd; 1083 } 1084 fwd = checkMount(res, mapping, fileSystemForm, request); 1085 if (fwd != null) { 1086 return fwd; 1087 } 1088 buildModel(res, fileSystemForm, request); 1089 Object [] uris = fileSystemForm.getSelectedFileNames(); 1090 if (uris == null || uris.length < 1) { 1091 ActionMessages msgs = getErrors(request); 1092 msgs.add(Globals.ERROR_KEY, new ActionMessage("vfs.cut.select.error")); 1093 saveErrors(request, msgs); 1094 return mapping.getInputForward(); 1095 } 1096 copyFilesToClipboard(form, request, response, true, fileSystemForm.getSelectedFileNames()); 1097 return mapping.findForward("list"); 1098 } catch (DAVAuthenticationRequiredException e) { 1099 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 1100 return null; 1101 } 1102 } 1103 1104 1117 public ActionForward copy(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 1118 throws Exception { 1119 if (log.isDebugEnabled()) 1120 log.debug("Copy files."); 1121 FileSystemForm fileSystemForm = (FileSystemForm) form; 1122 1123 try { 1124 VFSResource res = checkLaunchSession(request, response, fileSystemForm); 1125 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 1126 if (fwd != null) { 1127 return fwd; 1128 } 1129 fwd = checkMount(res, mapping, fileSystemForm, request); 1130 if (fwd != null) { 1131 return fwd; 1132 } 1133 buildModel(res, fileSystemForm, request); 1134 String [] uris = fileSystemForm.getSelectedFileNames(); 1135 if (uris == null || uris.length < 1) { 1136 ActionMessages msgs = getErrors(request); 1137 msgs.add(Globals.ERROR_KEY, new ActionMessage("vfs.copy.select.error")); 1138 saveErrors(request, msgs); 1139 return mapping.getInputForward(); 1140 } 1141 copyFilesToClipboard(form, request, response, false, uris); 1142 return mapping.findForward("list"); 1143 } catch (DAVAuthenticationRequiredException e) { 1144 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 1145 return null; 1146 } 1147 } 1148 1149 1160 private void copyFilesToClipboard(ActionForm form, HttpServletRequest request, HttpServletResponse response, 1161 boolean deleteOnPaste, String [] uris) { 1162 ActionMessages msgs = new ActionMessages(); 1163 FileSystemForm fileSystemForm = (FileSystemForm) form; 1164 String allFiles = ""; 1165 Clipboard cb = new Clipboard(); 1166 if (uris != null) { 1167 for (int i = 0; i < uris.length; i++) { 1168 String divider = allFiles.equals("") ? "" : ", "; 1169 allFiles = allFiles + divider + uris[i]; 1170 NetworkPlaceClipboardContent fcc = new NetworkPlaceClipboardContent(fileSystemForm.getPath() + "/" + uris[i], 1171 deleteOnPaste); 1172 cb.addContent(fcc); 1173 } 1174 msgs.add(Globals.MESSAGE_KEY, new ActionMessage("vfs.copy.to.clipboard", allFiles)); 1175 } 1176 this.addMessages(request, msgs); 1177 request.getSession().setAttribute(Constants.CLIPBOARD, cb); 1178 } 1179 1180 1193 public ActionForward confirmPaste(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 1194 throws Exception { 1195 return pasteFiles(mapping, form, request, response, true); 1196 } 1197 1198 1211 public ActionForward pasteOverwriteFiles(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 1212 throws Exception { 1213 return pasteFiles(mapping, form, request, response, false); 1214 } 1215 1216 private ActionForward pasteFiles(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, boolean requiresOverwriteCheck) 1217 throws Exception { 1218 if (log.isDebugEnabled()) { 1219 log.debug("Paste files."); 1220 } 1221 try { 1222 FileSystemForm fileSystemForm = (FileSystemForm) form; 1223 ActionForward validatePasteForward = validatePasteForward(mapping, fileSystemForm, request, response); 1224 if(validatePasteForward != null) { 1225 return validatePasteForward; 1226 } 1227 1228 String path = DAVUtilities.concatenatePaths(fileSystemForm.getPath(), fileSystemForm.getFileName()); 1229 if (requiresOverwriteCheck) { 1230 boolean isOverwritingFiles = isOverwritingFiles(request, response, path, fileSystemForm); 1231 if (isOverwritingFiles) { 1232 return mapping.findForward("pasteOverwriteFiles"); 1233 } 1234 } 1235 1236 pasteFromClipboard(request, response, path, fileSystemForm); 1237 return mapping.findForward("list"); 1238 } catch (DAVAuthenticationRequiredException e) { 1239 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 1240 return null; 1241 } 1242 } 1243 1244 private ActionForward validatePasteForward(ActionMapping mapping, FileSystemForm fileSystemForm, HttpServletRequest request, HttpServletResponse response) 1245 throws Exception { 1246 VFSResource vfsResource = checkLaunchSession(request, response, fileSystemForm); 1247 ActionForward forward = checkAccess(mapping, fileSystemForm, request); 1248 if (forward != null) { 1249 return forward; 1250 } 1251 forward = checkMount(vfsResource, mapping, fileSystemForm, request); 1252 if (forward != null) { 1253 return forward; 1254 } 1255 buildModel(vfsResource, fileSystemForm, request); 1256 Clipboard clipboard = (Clipboard) request.getSession().getAttribute("clipboard"); 1257 if (clipboard != null) { 1258 if (!clipboard.getContent().iterator().hasNext()) { 1259 ActionMessages msgs = getErrors(request); 1260 msgs.add(Globals.ERROR_KEY, new ActionMessage("vfs.paste.error")); 1261 saveErrors(request, msgs); 1262 return mapping.getInputForward(); 1263 } 1264 } 1265 return null; 1266 } 1267 1268 private boolean isOverwritingFiles(HttpServletRequest request, HttpServletResponse response, String destinationPath, FileSystemForm fileSystemForm) 1269 throws Exception { 1270 Map <VFSResource, VFSResource> pasteMap = buildPasteMap(request, response, destinationPath, fileSystemForm); 1271 for (VFSResource destinationResource : pasteMap.values()) { 1272 if(!destinationResource.isNull()) { 1273 return true; 1274 } 1275 } 1276 return false; 1277 } 1278 1279 private Map <VFSResource, VFSResource> buildPasteMap(HttpServletRequest request, HttpServletResponse response, String destinationPath, FileSystemForm fileSystemForm) 1281 throws Exception { 1282 Clipboard clipboard = (Clipboard) request.getSession().getAttribute(Constants.CLIPBOARD); 1283 Map <VFSResource, VFSResource> pasteDetails = new HashMap <VFSResource, VFSResource>(); 1284 if (clipboard != null) { 1285 for (ClipboardContent content : clipboard.getContent()) { 1286 NetworkPlaceClipboardContent element = (NetworkPlaceClipboardContent) content; 1287 VFSResource sourceResource = getResourceForPath(fileSystemForm.getLaunchSession(), request, response, element.getPath()); 1288 if (log.isDebugEnabled()) { 1289 log.debug(" Source. = " + sourceResource + " (display name = " + sourceResource.getDisplayName() + ", mount = " + sourceResource.isMount() + ")"); 1290 } 1291 String concatenatePaths = DAVUtilities.concatenatePaths(destinationPath, sourceResource.getDisplayName()); 1292 VFSResource destinationResource = getResourceForPath(fileSystemForm.getLaunchSession(), request, response, concatenatePaths); 1293 1294 if (log.isDebugEnabled()) { 1295 log.debug(" Dest. = " + destinationResource); 1296 } 1297 1298 if (sourceResource.getFullPath().equals(destinationResource.getFullPath())) { 1299 throw new NetworkPlacesException(NetworkPlacesException.ERR_VFS_CANNOT_PASTE_TO_SOURCE); 1300 } 1301 1302 pasteDetails.put(sourceResource, destinationResource); 1303 } 1304 } 1305 return pasteDetails; 1306 } 1307 1308 private void pasteFromClipboard(HttpServletRequest request, HttpServletResponse response, String destinationPath, 1309 FileSystemForm fileSystemForm) throws Exception { 1310 Clipboard cb = (Clipboard) request.getSession().getAttribute(Constants.CLIPBOARD); 1311 ActionMessages msgs = getMessages(request); 1312 ActionMessages errs = getErrors(request); 1313 if (cb != null){ 1314 try { 1315 int fileCounter = 1; 1316 int directorieCounter = 1; 1317 String allFiles = ""; 1318 if (log.isDebugEnabled()) 1319 log.debug("Pasting from clipboard to " + destinationPath); 1320 Iterator clipboardIterator = cb.getContent().iterator(); 1321 1322 CoreEvent evt = NetworkPlaceResourceType.getResourceAccessPasteEvent(this, 1323 fileSystemForm.getLaunchSession(), 1324 request, 1325 fileSystemForm.getPath(), 1326 fileSystemForm.getFullURI(), 1327 null); 1328 1329 while (clipboardIterator.hasNext()) { 1330 String divider = allFiles.equals("") ? "" : ", "; 1331 NetworkPlaceClipboardContent element = (NetworkPlaceClipboardContent) clipboardIterator.next(); 1332 try { 1333 VFSResource sourceResource = getResourceForPath(fileSystemForm.getLaunchSession(), 1334 request, 1335 response, 1336 element.getPath()); 1337 if (log.isDebugEnabled()) 1338 log.debug(" Source. = " + sourceResource 1339 + " (display name = " 1340 + sourceResource.getDisplayName() 1341 + ", mount = " 1342 + sourceResource.isMount() 1343 + ")"); 1344 VFSResource destinationResource = null; 1345 if (log.isDebugEnabled()) 1346 log.debug("Paste"); 1347 destinationResource = getResourceForPath(fileSystemForm.getLaunchSession(), 1348 request, 1349 response, 1350 DAVUtilities.concatenatePaths(destinationPath, sourceResource.getDisplayName())); 1351 1352 if (log.isDebugEnabled()) 1353 log.debug(" Dest. = " + destinationResource); 1354 1355 if (sourceResource.getFullPath().equals(destinationResource.getFullPath())) { 1356 throw new NetworkPlacesException(NetworkPlacesException.ERR_VFS_CANNOT_PASTE_TO_SOURCE); 1357 } 1358 1359 allFiles = allFiles + divider + sourceResource.getDisplayName(); 1360 sourceResource.copy(destinationResource, true, true); 1361 1362 if (sourceResource.isCollection()) { 1363 NetworkPlaceResourceType.addDirectoryAttribute(evt, sourceResource.getFullPath(), directorieCounter); 1364 directorieCounter++; 1365 } else { 1366 NetworkPlaceResourceType.addDirectoryAttribute(evt, sourceResource.getFullPath(), fileCounter); 1367 fileCounter++; 1368 } 1369 NetworkPlaceResourceType.addOperationType(evt, element.deleteOnPaste()); 1370 CoreServlet.getServlet().fireCoreEvent(evt); 1371 1372 if (element.deleteOnPaste()) { 1373 if (log.isDebugEnabled()) 1374 log.debug(" Deleting source"); 1375 sourceResource.delete(); 1376 } 1377 msgs.add(Globals.MESSAGE_KEY, new ActionMessage("vfs.paste.from.clipboard", allFiles)); 1378 } catch (CoreException e) { 1379 errs.add(Globals.ERROR_KEY, e.getBundleActionMessage()); 1380 } 1381 } 1382 cb.clearClipboard(); 1385 1386 this.saveErrors(request, errs); 1387 this.saveMessages(request, msgs); 1388 } catch (Exception e) { 1389 CoreEvent evt = NetworkPlaceResourceType.getResourceAccessPasteEvent(this, 1390 fileSystemForm.getLaunchSession(), 1391 request, 1392 fileSystemForm.getPath(), 1393 fileSystemForm.getFullURI(), 1394 e); 1395 CoreServlet.getServlet().fireCoreEvent(evt); 1396 throw e; 1397 } 1398 } 1399 else{ 1400 errs.add(Globals.ERROR_KEY, new ActionError("vfs.paste.from.clipboard.no.copy")); 1401 this.saveErrors(request, errs); 1402 } 1403 } 1404 1405 1418 public ActionForward mkdir(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 1419 throws Exception { 1420 FileSystemForm fileSystemForm = (FileSystemForm) form; 1421 checkLaunchSession(request, response, fileSystemForm); 1422 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 1423 if (fwd != null) { 1424 return fwd; 1425 } 1426 String path = DAVUtilities.stripTrailingSlash(fileSystemForm.getPath() + "/" + fileSystemForm.getNewFolder()) + "/"; 1427 VFSResource res = null; 1428 res = getResourceForPath(fileSystemForm.getLaunchSession(), request, response, path); 1429 fwd = checkMount(res, mapping, fileSystemForm, request); 1430 if (fwd != null) { 1431 return fwd; 1432 } 1433 try { 1434 res.makeCollection(); 1435 fileSystemForm.setPath(path); 1436 if (res.getMount().getStore().getProvider().isFireEvents()) { 1437 CoreServlet.getServlet().fireCoreEvent(NetworkPlaceResourceType.getResourceAccessMkDirEvent(this, 1438 fileSystemForm.getLaunchSession(), 1439 request, 1440 fileSystemForm.getPath(), 1441 fileSystemForm.getFullURI(), 1442 null)); 1443 } 1444 1445 } catch (DAVException e) { 1446 if (res.getMount().getStore().getProvider().isFireEvents()) { 1447 CoreServlet.getServlet().fireCoreEvent(NetworkPlaceResourceType.getResourceAccessMkDirEvent(this, 1448 fileSystemForm.getLaunchSession(), 1449 request, 1450 fileSystemForm.getPath(), 1451 fileSystemForm.getFullURI(), 1452 e)); 1453 } 1454 if (e.getStatus() == 405) { 1455 ActionMessages msgs = getErrors(request); 1456 msgs.add(Globals.ERROR_KEY, new BundleActionMessage(NetworkPlacePlugin.MESSAGE_RESOURCES_KEY, "vfs.folder.exists", fileSystemForm.getNewFolder())); 1457 saveErrors(request, msgs); 1458 return mapping.findForward("list"); 1459 } else { 1460 throw e; 1461 } 1462 } 1463 return mapping.findForward("list"); 1464 } 1465 1466 1478 public ActionForward showMkDir(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 1479 throws Exception { 1480 FileSystemForm fileSystemForm = (FileSystemForm) form; 1481 checkLaunchSession(request, response, fileSystemForm); 1482 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 1483 if (fwd != null) { 1484 return fwd; 1485 } 1486 return mapping.findForward("showMkDir"); 1487 } 1488 1489 1501 public ActionForward showRenameFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, 1502 HttpServletResponse response) throws Exception { 1503 FileSystemForm fileSystemForm = (FileSystemForm) form; 1504 1505 try { 1506 checkLaunchSession(request, response, fileSystemForm); 1507 ActionForward fwd = checkAccess(mapping, fileSystemForm, request); 1508 if (fwd != null) { 1509 return fwd; 1510 } 1511 fileSystemForm.setNewName(DAVUtilities.stripTrailingSlash(fileSystemForm.getFileName())); 1512 return mapping.findForward("showRenameFile"); 1513 } catch (DAVAuthenticationRequiredException e) { 1514 AbstractHTTPAuthenticationModule.sendAuthorizationError(request, response, e.getHttpRealm()); 1515 return null; 1516 } 1517 } 1518 1519 private ActionForward checkMount(VFSResource vfsResource, ActionMapping mapping, FileSystemForm fileSystemForm, HttpServletRequest request) 1520 throws NoPermissionException { 1521 if (vfsResource.getMount().isReadOnly()) { 1522 if(READ_ONLY.contains(fileSystemForm.getActionTarget())) { 1523 ActionMessages msgs = getErrors(request); 1524 msgs.add(Globals.ERROR_KEY, new BundleActionMessage(NetworkPlacePlugin.MESSAGE_RESOURCES_KEY, "vfs.readOnly.error")); 1525 saveMessages(request, msgs); 1526 return mapping.getInputForward(); 1527 } 1528 } 1529 return null; 1530 } 1531 1532 private ActionForward checkAccess(ActionMapping mapping, FileSystemForm fileSystemForm, HttpServletRequest request) 1533 throws NoPermissionException { 1534 SessionInfo actualSession = LogonControllerFactory.getInstance().getSessionInfo(request); 1535 SessionInfo session = fileSystemForm.getLaunchSession().getSession(); 1536 1537 if (fileSystemForm.getNetworkPlace() != null) { 1538 NetworkPlace resource = fileSystemForm.getNetworkPlace(); 1539 1540 if (resource.isNoDelete() && NO_DELETE.contains(fileSystemForm.getActionTarget())) { 1542 ActionMessages msgs = getErrors(request); 1543 msgs.add(Globals.ERROR_KEY, new BundleActionMessage(NetworkPlacePlugin.MESSAGE_RESOURCES_KEY, "vfs.noDelete.error")); 1544 saveMessages(request, msgs); 1545 return mapping.getInputForward(); 1546 } 1547 } 1548 1549 try { 1550 if(fileSystemForm.getLaunchSession().isTracked()) { 1551 LaunchSession.AccessRight accessRight = fileSystemForm.getLaunchSession().checkAccessRights(null, actualSession); 1552 if (accessRight == LaunchSession.USER_ACCESS || isSuperUser(request)) { 1553 fileSystemForm.setReadWrite(); 1554 } else if (accessRight == LaunchSession.MANAGEMENT_ACCESS) { 1555 ActionMessages warnings = getWarnings(request); 1556 warnings.add(Constants.REQ_ATTR_WARNINGS, new BundleActionMessage(NetworkPlacePlugin.MESSAGE_RESOURCES_KEY, "vfs.manageOnly.warning")); 1557 saveWarnings(request, warnings); 1558 } 1559 } 1560 return null; 1561 } catch (Exception e) { 1562 log.error("Failed to test if user has access to resource. Denying", e); 1563 throw new NoPermissionException("Permission denied.", session.getUser(), NetworkPlacePlugin.NETWORK_PLACE_RESOURCE_TYPE); 1564 } 1565 } 1566 1567 private boolean isSuperUser(HttpServletRequest request) { 1568 SessionInfo sessionInfo = getSessionInfo(request); 1569 return LogonControllerFactory.getInstance().isAdministrator(sessionInfo.getUser()); 1570 } 1571 1572 1580 protected ActionForward gotoLogon(ActionMapping mapping, ActionForm form, HttpServletRequest request, 1581 HttpServletResponse response) throws Exception { 1582 throw new Exception ("You are no longer logged in to the SSL-Explorer server and cannot login from this window. Please login from your main browser window in the usual manner to continue."); 1583 } 1584} | Popular Tags |