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

📄 registerclientsynchronizationaction.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.agent.actions;

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.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jdom.Document;
import org.jdom.Element;

import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.core.actions.XMLOutputAction;
import com.sslexplorer.security.User;
import com.sslexplorer.security.VPNSession;

/**
 * An {@link com.sslexplorer.core.actions.XMLOutputAction} that blocks until the
 * <i>SSL-Explorer Agent</i> or an application using the <i>Embedded Client API</i>
 * registers.
 * <p>
 * If registration does not occur within the specified amount of time an error
 * XML document will be returned, otherwise and XML document containing the port
 * on which the VPN client has been started is returned.
 * <p>
 * This is used by the agent launcher applet so prevent the next being displayed
 * until the VPN client is up and running.
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.3 $
 */
public class RegisterClientSynchronizationAction extends XMLOutputAction {

    final static Log log = LogFactory.getLog(RegisterClientSynchronizationAction.class);

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {

        // Get the pending VPN session ticket
        String ticket = request.getParameter("ticket");
        if (log.isDebugEnabled())
        	log.debug("Registering client synchronization " + ticket);

        User user;
        VPNSession vpnSession = null;
        if (CoreServlet.getServlet().getLogonController().verifyPendingVPNAuthorization(request)) {
        	if (log.isDebugEnabled())
        		log.debug("Verifying pending VPN authorization.");
            vpnSession = CoreServlet.getServlet().getLogonController().getPendingVPNSession(request);
            user = vpnSession.getSessionInfo().getUser();
        } else {
        	if (log.isDebugEnabled())
        		log.debug("Verifying VPN authorization.");
            vpnSession = CoreServlet.getServlet().getLogonController().getVPNSession(request);
            user = vpnSession.getSessionInfo().getUser();

        }

        int timeout = 10000;

        try {
            timeout = Integer.parseInt(CoreServlet.getServlet().getPropertyDatabase().getProperty(
                            CoreUtil.getCurrentPropertyProfileId(request.getSession()), user.getPrincipalName(),
                            "client.registration.synchronization.timeout"));
        } catch (Exception ex) {
        }

        if (log.isDebugEnabled())
        	log.debug("Waiting for client registration (timeout " + timeout + ")");
        if (CoreServlet.getServlet().getLogonController().waitForClientRegistration(ticket, timeout)) {
        	if (log.isDebugEnabled())
        		log.debug("Successfull client registration");
            Element root = new Element("success");
            root.setAttribute("clientPort", String.valueOf(vpnSession.getClientPort()));
            Document doc = new Document(root);
            root.setText("The client registered successfully");
            sendDocument(doc, response);
        } else {
        	if (log.isDebugEnabled())
        		log.debug("Failed client registration");
            sendError("The client failed to register within the allowed time period [" + timeout + "]", response);
        }

        return null;
    }
}

⌨️ 快捷键说明

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