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

📄 createnewcertificateform.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.forms;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.prefs.Preferences;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import com.sslexplorer.boot.ContextHolder;
import com.sslexplorer.boot.KeyStoreManager;
import com.sslexplorer.wizard.AbstractWizardSequence;
import com.sslexplorer.wizard.forms.DefaultWizardForm;

public class CreateNewCertificateForm extends DefaultWizardForm {
    // Statics for sequence attributes
    public final static String ATTR_HOSTNAME = "hostname";
    public final static String ATTR_ORGANISATIONAL_UNIT = "organisationalUnit";
    public final static String ATTR_COMPANY = "company";
    public final static String ATTR_COUNTRY_CODE = "countryCode";
    public final static String ATTR_CITY = "city";
    public final static String ATTR_STATE = "state";
    public static final String ATTR_KEY_STORE_TYPE = "keyStoreType";

    // Private instance variables
    
    private String hostname;
    private String organisationalUnit;
    private String company;
    private String countryCode;    
    private String city;    
    private String state;
    private String keyStoreType;
    
    public final static Preferences PREF_NODE = ContextHolder.getContext().getPreferences().node("installation").node("certificate");
        
    public CreateNewCertificateForm() {
        super(true, true, "/WEB-INF/jsp/content/install/createNewCertificate.jspf", 
            "hostname", true, false, "createNewCertificate", 
            "install", "installation.createNewCertificate", 1);
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.wizard.forms.AbstractWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence)
     */
    public void init(AbstractWizardSequence sequence, HttpServletRequest request) throws Exception {
        String localhostAddress = null;
        hostname = (String)sequence.getAttribute(ATTR_HOSTNAME, PREF_NODE.get("hostname", ""));
        if (hostname.equals("")) {
            try {
                Enumeration e = NetworkInterface.getNetworkInterfaces();

                while (e.hasMoreElements() && hostname == null) {
                    NetworkInterface netface = (NetworkInterface) e.nextElement();
                    Enumeration e2 = netface.getInetAddresses();
                    while (e2.hasMoreElements() && hostname == null) {
                        InetAddress ip = (InetAddress) e2.nextElement();
                        if (!ip.getCanonicalHostName().equals("localhost")
                                        && !ip.getCanonicalHostName().equals("localhost.localdomain")) {
                            hostname = ip.getCanonicalHostName();
                        } else {
                            localhostAddress = ip.getCanonicalHostName();
                        }
                    }
                }
            } catch (Exception e) {
            }
            if (hostname.equals("")) {
                hostname = localhostAddress == null ? "localhost" : localhostAddress;
            }
        }
        countryCode =(String) sequence.getAttribute(ATTR_COUNTRY_CODE, PREF_NODE.get("countryCode", ""));
        if (countryCode.equals("")) {
            countryCode = Locale.getDefault().getCountry();
        }
        organisationalUnit = (String)sequence.getAttribute(ATTR_COUNTRY_CODE, PREF_NODE.get("organisationalUnit", ""));
        company = (String)sequence.getAttribute(ATTR_COMPANY, PREF_NODE.get("company", ""));
        city =  (String)sequence.getAttribute(ATTR_CITY, PREF_NODE.get("city", ""));
        state =  (String)sequence.getAttribute(ATTR_STATE, PREF_NODE.get("state", ""));
        keyStoreType = (String)sequence.getAttribute(ATTR_KEY_STORE_TYPE, getAvailableKeyStoreTypes().get(0).toString());
        
    }

    public List getAvailableKeyStoreTypes() {
        return KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE).getSupportedKeyStoreTypes();
    }
    
    public String getKeyStoreType() {
        return keyStoreType;
    }
    
    public void setKeyStoreType(String keyStoreType) {
        this.keyStoreType = keyStoreType;
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.wizard.forms.AbstractWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
     */
    public void apply(AbstractWizardSequence sequence) throws Exception {  
        sequence.putAttribute(ATTR_CITY, city);       
        sequence.putAttribute(ATTR_COMPANY, company);       
        sequence.putAttribute(ATTR_COUNTRY_CODE, countryCode);       
        sequence.putAttribute(ATTR_HOSTNAME, hostname);       
        sequence.putAttribute(ATTR_ORGANISATIONAL_UNIT, organisationalUnit);       
        sequence.putAttribute(ATTR_STATE, state);       
        sequence.putAttribute(ATTR_KEY_STORE_TYPE, keyStoreType);
    }

    public void setCity(String city) {
        this.city = city;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public String getCity() {
        return city;
    }

    public String getState() {
        return state;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public String getHostname() {
        return hostname;
    }

    public void setHostname(String hostname) {
        this.hostname = hostname;
    }

    public String getOrganisationalUnit() {
        return organisationalUnit;
    }

    public void setOrganisationalUnit(String organisationalUnit) {
        this.organisationalUnit = organisationalUnit;
    }
    
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errs = new ActionErrors();
        if(isCommiting()) {
            if ("".equals(hostname)) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("installation.createNewCertificate.error.noHost"));
            }

            if ("".equals(organisationalUnit)) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("installation.createNewCertificate.error.noOrganisationalUnit"));
            }

            if ("".equals(company)) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("installation.createNewCertificate.error.noCompany"));
            }
            
            if ("".equals(countryCode)) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("installation.createNewCertificate.error.noCountryCode"));
            }
            
            if ("".equals(city)) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("installation.createNewCertificate.error.noCity"));
            }
            
            if ("".equals(state)) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("installation.createNewCertificate.error.noState"));
            }
        }
        return errs;
    }
}

⌨️ 快捷键说明

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