⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesystemviewdispatchaction.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        Clipboard cb = (Clipboard) request.getSession().getAttribute("clipboard");
        if (cb != null) {
            if (!cb.getContent().iterator().hasNext()) {
                ActionMessages msgs = getErrors(request);
                msgs.add(Globals.ERROR_KEY, new ActionMessage("vfs.paste.error"));
                saveErrors(request, msgs);
                return mapping.getInputForward();
            }
        }
        pasteFromClipBoard(request, response, fileSystemForm.getPath(), fileSystemForm);
        return mapping.findForward("list");
    }

    /**
     * @param request The <code>HttpServletRequest<code> for the action.
     * @param response The <code>HttpServletResponse<code> for the action.
     * @param destinationPath The destination location.
     * @param rename rename
     * @throws Exception if aan exception is thrown.
     */
    private void pasteFromClipBoard(HttpServletRequest request, HttpServletResponse response, String destinationPath,
                                    FileSystemForm fileSystemForm) throws Exception {

        try {
            Clipboard cb = (Clipboard) request.getSession().getAttribute(Constants.CLIPBOARD);
            ActionMessages msgs = getMessages(request);
            ActionMessages errs = getErrors(request);
            int fileCounter = 1;
            int directorieCounter = 1;
            String allFiles = "";
            if (log.isDebugEnabled())
                log.debug("Pasting from clipboard to " + destinationPath);
            Iterator clipboardIterator = cb.getContent().iterator();
            try {

                while (clipboardIterator.hasNext()) {
                    String divider = allFiles.equals("") ? "" : ", ";
                    DAVResourceClipboardContent element = (DAVResourceClipboardContent) clipboardIterator.next();
                    try {
                        DAVResource sourceResource = DAVServlet.getDAVResource(request, response, element.getDAVPath());
                        if (log.isDebugEnabled())
                            log.debug("  Source. = " + sourceResource + " (display name = " + sourceResource.getDisplayName()
                                            + ", mount = " + sourceResource.isMount() + ")");
                        DAVResource destinationResource = null;
                        if (log.isDebugEnabled())
                            log.debug("Paste");
                        destinationResource = DAVServlet.getDAVResource(request, response, destinationPath + "/"
                                        + sourceResource.getDisplayName());

                        if (log.isDebugEnabled())
                            log.debug("  Dest. = " + destinationResource);
                        if (sourceResource.getFullPath().equals(destinationResource.getFullPath())) {
                            cb.removeContent(element);
                            throw new DAVBundleActionMessageException(new BundleActionMessage("vfs",
                                            "vfs.paste.sourceSameAsDestination"));
                        }
                        allFiles = allFiles + divider + sourceResource.getDisplayName();

                        sourceResource.copy(destinationResource, true, true);


                        if (element.deleteOnPaste()) {
                            if (log.isDebugEnabled())
                                log.debug("      Deleting source");
                            sourceResource.delete();
                        }
                        msgs.add(Globals.MESSAGE_KEY, new ActionMessage("vfs.copy.to.clipboard", allFiles));
                    } catch (DAVBundleActionMessageException e) {
                        errs.add(Globals.ERROR_KEY, e.getBundleActionMessage());
                    }
                }
            } finally {
                // The void entries cannot be removed untill the iterator is
                // finished with.
                cb.clearRemovedContent();
            }

            this.saveErrors(request, errs);
            this.saveMessages(request, msgs);
        } catch (Exception e) {
            throw e;
        }

    }

    /**
     * <p>
     * Make a new directory in the current location.
     * 
     * 
     * @param mapping The
     *        <code>ActionMapping<code> associated with this dispatch action.
     * @param form The <code>FileSystemForm<code> for the action.
     * @param request The <code>HttpServletRequest<code> for the action.
     * @param response The <code>HttpServletResponse<code> for the action.
     * @return <code>ActionForward<code> The result of the action.
     * @throws Exception if aan exception is thrown.
     */
    public ActionForward mkdir(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        FileSystemForm fileSystemForm = (FileSystemForm) form;
        getResourceForPath(request, response, fileSystemForm);
        ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
        if (fwd != null) {
            return fwd;
        }
        String path = fileSystemForm.getPath() + "/" + fileSystemForm.getNewFolder();
        DAVResource res = null;
        res = DAVServlet.getDAVResource(request, response, path);
        try {
            res.makeCollection();
            fileSystemForm.setPath(path);

        } catch (DAVException e) {
            if (e.getStatus() == 405) {
                ActionMessages msgs = getErrors(request);
                msgs.add(Globals.ERROR_KEY, new BundleActionMessage("vfs", "vfs.folder.exists", fileSystemForm.getNewFolder()));
                saveErrors(request, msgs);
                return mapping.findForward("list");
            } else {
                throw e;
            }
        }
        return mapping.findForward("list");
    }

    /**
     * <p>
     * Action to forward to the make directory page.
     * 
     * @param mapping The
     *        <code>ActionMapping<code> associated with this dispatch action.
     * @param form The <code>FileSystemForm<code> for the action.
     * @param request The <code>HttpServletRequest<code> for the action.
     * @param response The <code>HttpServletResponse<code> for the action.
     * @return <code>ActionForward<code> The result of the action.
     * @throws Exception if aan exception is thrown.
     */
    public ActionForward showMkDir(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        FileSystemForm fileSystemForm = (FileSystemForm) form;
        getResourceForPath(request, response, fileSystemForm);
        ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
        if (fwd != null) {
            return fwd;
        }
        return mapping.findForward("showMkDir");
    }

    /**
     * <p>
     * Action to forward to the rename file page.
     * 
     * @param mapping The
     *        <code>ActionMapping<code> associated with this dispatch action.
     * @param form The <code>FileSystemForm<code> for the action.
     * @param request The <code>HttpServletRequest<code> for the action.
     * @param response The <code>HttpServletResponse<code> for the action.
     * @return <code>ActionForward<code> The result of the action.
     * @throws Exception if aan exception is thrown.
     */
    public ActionForward showRenameFile(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                        HttpServletResponse response) throws Exception {
        FileSystemForm fileSystemForm = (FileSystemForm) form;
        getResourceForPath(request, response, fileSystemForm);
        ActionForward fwd = checkAccess(mapping, fileSystemForm, request);
        if (fwd != null) {
            return fwd;
        }
        fileSystemForm.setNewName(DAVUtilities.stripTrailingSlash(fileSystemForm.getFileName()));
        return mapping.findForward("showRenameFile");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.policyframework.actions.AbstractResourcesDispatchAction#remove(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        throw new Exception("Not implemented for this resource.");
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.policyframework.actions.AbstractResourcesDispatchAction#getResourceById(int)
     */
    public Resource getResourceById(int id) throws Exception {
        throw new Exception("Not implemented for this resource.");
    }

    /**
     * @param mapping action mapping
     * @param fileSystemForm The <code>FileSystemForm<code> for the action.
     * @param request The <code>HttpServletRequest<code> for the action.
     * @return forward to move on to input access is denied or <code>null</code> to allow continue
     * @throws NoPermissionException 
     * @throws NoPermissionException Thown if there is no permission.
     */
    private ActionForward checkAccess(ActionMapping mapping, FileSystemForm fileSystemForm, HttpServletRequest request)
                    throws NoPermissionException {
        SessionInfo session = this.getSessionInfo();
        // Get the network place associated with the current path
        int resourceId = fileSystemForm.getNetworkPlace().getResourceId();
        if (resourceId == -1) {
            throw new NoPermissionException("resourceId parameter must be supplied.", session.getUser(),
                            PolicyConstants.NETWORK_PLACE_RESOURCE_TYPE);
        }
        // check access for the attributes on the NetworkPlace.
        if (fileSystemForm.getNetworkPlace().isNoDelete() && NO_DELETE.contains(fileSystemForm.getActionTarget())) {
            ActionMessages msgs = getErrors(request);
            msgs.add(Globals.ERROR_KEY, new BundleActionMessage("vfs", "vfs.noDelete.error"));
            saveMessages(request, msgs);
            return mapping.getInputForward();
        }
        if (fileSystemForm.getNetworkPlace().isReadOnly() && READ_ONLY.contains(fileSystemForm.getActionTarget())) {
            ActionMessages msgs = getErrors(request);
            msgs.add(Globals.ERROR_KEY, new BundleActionMessage("vfs", "vfs.readOnly.error"));
            saveMessages(request, msgs);
            return mapping.getInputForward();
        }

        try {

            NetworkPlace resource = fileSystemForm.getNetworkPlace();
            ResourceType resourceType = resource.getResourceType();
            try {
                if (!(resource instanceof OwnedResource)
                                || (resource instanceof OwnedResource && ((OwnedResource) resource).getOwnerUsername() == null)) {
                    try {
                        // assigned
                        if (!CoreServlet.getServlet().getPolicyDatabase().isPrincipalAllowed(session.getUser(), resource, false)) {
                            throw new NoPermissionException("You may not access this resource here.", session.getUser(),
                                            resourceType);
                        }
                    } catch (NoPermissionException npe2) {
                        throw npe2;
                    } catch (Exception e) {
                        throw new NoPermissionException("Failed to determine if resource is accessable.", session.getUser(),
                                        resourceType);
                    }
                } else {
                    // or owned
                    if (!(session.getUser().getPrincipalName().equals(((OwnedResource) resource).getOwnerUsername()))) {
                        throw new NoPermissionException("You do not have permission to access this resource.", session.getUser(),
                                        resourceType);
                    }
                }
                fileSystemForm.setReadWrite();
            } catch (NoPermissionException npe) {
                if (!ResourceUtil.isManageableResource(resource, session.getUser(), null)) {
                    throw new NoPermissionException("You do not have permission to access this resource.", session.getUser(),
                                    resourceType);
                }
                ActionMessages warnings = getWarnings(request);
                warnings.add(Constants.REQ_ATTR_WARNINGS, new BundleActionMessage("vfs", "vfs.manageOnly.warning"));
                saveWarnings(request, warnings);
            } catch (Exception e) {
                throw new NoPermissionException("Failed to determine if resource is accessable.", session.getUser(), resourceType);
            }
            return null;
        } catch (Exception e) {
            log.error("Failed to test if user has access to resource. Denying", e);
            throw new NoPermissionException("Permission denied.", session.getUser(), PolicyConstants.NETWORK_PLACE_RESOURCE_TYPE);
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.core.actions.AuthenticatedDispatchAction#gotoLogon(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    protected ActionForward gotoLogon(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                      HttpServletResponse response) throws Exception {
        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.");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -