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

📄 uploadexistingcertificateaction.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 *  SSL-Explorer
 *
 *  Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
			
package com.sslexplorer.install.actions;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.upload.FormFile;

import com.sslexplorer.boot.Util;
import com.sslexplorer.core.actions.AuthenticatedAction;
import com.sslexplorer.install.forms.ImportExistingCertificateForm;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.vfs.forms.UploadForm;
import com.sslexplorer.wizard.AbstractWizardSequence;

public class UploadExistingCertificateAction extends AuthenticatedAction {

    static Log log = LogFactory.getLog(UploadExistingCertificateAction.class);

    public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
        String alias = request.getParameter("alias");
        String password = request.getParameter("password");
        String keyStoreType = request.getParameter("keyStoreType");
        UploadForm uploadForm = (UploadForm) form;
        FormFile uploadFile = uploadForm.getUploadFile();
        String fileName = uploadFile.getFileName();
        int fileSize = uploadFile.getFileSize();
        InputStream in = null;
        OutputStream out = null;
        File uploadedFile = File.createTempFile("uploadedFile", "");

        try {
            if (fileName.trim().length() == 0) {
                ActionMessages errs = new ActionMessages();
                errs.add(Globals.ERROR_KEY, new ActionMessage("installation.uploadExistingCertificate.noFileProvided"));
                saveErrors(request, errs);
                return mapping.getInputForward();
            } else {
                if(alias == null || alias.trim().equals("")) {
                    ActionMessages errs = new ActionMessages();
                    errs.add(Globals.ERROR_KEY, new ActionMessage("installation.uploadExistingCertificate.noAliasProvided"));
                    saveErrors(request, errs);
                    return mapping.getInputForward();
                }
                else {
                	if (log.isInfoEnabled())
                		log.info("Uploading certificate with alias " + alias);
                    in = uploadFile.getInputStream();
    
    
                    out = new FileOutputStream(uploadedFile);
                    Util.copy(in, out);
                    
                    AbstractWizardSequence seq = (AbstractWizardSequence)request.getSession().getAttribute(Constants.WIZARD_SEQUENCE);
                    seq.putAttribute(ImportExistingCertificateForm.ATTR_PASSPHRASE, password);
                    seq.putAttribute(ImportExistingCertificateForm.ATTR_UPLOADED_FILE, uploadedFile);
                    seq.putAttribute(ImportExistingCertificateForm.ATTR_KEY_STORE_TYPE, keyStoreType);
                    seq.putAttribute(ImportExistingCertificateForm.ATTR_ALIAS, alias.trim());
                    
                    ActionMessages msgs = new ActionMessages();
                    msgs.add(Globals.MESSAGE_KEY,
                             new ActionMessage("installation.uploadExisting.uploaded", fileName,
                                               new Integer(fileSize)));
                    saveMessages(request, msgs);
                }
            }
        } catch (Exception e) {
            ActionMessages errs = new ActionMessages();
            errs.add(Globals.ERROR_KEY, new ActionMessage("installation.uploadExistingCertificate.failedToUploadFile", fileName,
                            e.getMessage() == null ? "No message provided." : e.getMessage()));
            saveErrors(request, errs);
            return mapping.getInputForward();
        } finally {
            Util.closeStream(in);
            Util.closeStream(out);
        }
        return mapping.findForward("success");
    }

    public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.SETUP_CONSOLE_CONTEXT;
    }

}

⌨️ 快捷键说明

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