📄 registerclientaction.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 java.util.Enumeration;
import java.util.Properties;
import javax.servlet.http.Cookie;
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.CoreEvent;
import com.sslexplorer.core.CoreEventConstants;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.actions.XMLOutputAction;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.InvalidTicketException;
import com.sslexplorer.security.VPNSession;
/**
* Processes client registrations requests from either the <i>SSL-Explorer Agent</i>
* or an application using the <i>Embedded Client API</i>
* <p>
* When a VPN client is started it must connect to the SSL Explorer and
* authenticate itself by providing the pending VPN session ticket the user was
* allocated when they logged on. This will authenticate the user and create a
* new VPN session ticket which is provided in this actions response.
*
* @author Lee David Painter <a href="mailto: lee@3sp.com"><lee@3sp.com></a>
* @version $Revision: 1.5 $
*/
public class RegisterClientAction extends XMLOutputAction {
static Log log = LogFactory.getLog(RegisterClientAction.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 {
String ticket = null;
int clientPort = -1;
Properties properties = new Properties();
int type = VPNSession.UNKNOWN_VPN_CLIENT;
for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
String name = (String) e.nextElement();
String val = request.getParameter(name);
if (name.equals("ticket")) {
ticket = val;
} else if (name.equals("type")) {
try {
type = Integer.parseInt(request.getParameter("type"));
} catch (NumberFormatException ex) {
}
} else if (name.equals("port")) {
try {
clientPort = Integer.parseInt(request.getParameter("port"));
} catch (NumberFormatException ex) {
}
} else {
properties.put(name, val);
}
}
// Check the values and send error if incorrect
if (ticket == null) {
log.error("The client failed to provide a ticket");
sendError("A pending VPN session ticket is requried", response);
} else {
if (log.isInfoEnabled())
log.info("Registering client VPN session for " + request.getRemoteHost() + ", client port = " + clientPort);
VPNSession vpnSession = CoreServlet.getServlet().getLogonController().getPendingVPNSession(ticket);
if(vpnSession == null) {
vpnSession = CoreServlet.getServlet().getLogonController().getVPNSessionByTicket(ticket);
}
try {
// Everything looks good so register the client
ticket = CoreServlet.getServlet().getLogonController().registerVPNClient(request, ticket, clientPort, properties,
type);
// If debugging agent we should now have a VPN session
if(vpnSession == null) {
vpnSession = CoreServlet.getServlet().getLogonController().getVPNSessionByTicket(ticket);
}
if (log.isInfoEnabled())
log.info("SSL-Explorer Agent " + request.getRemoteHost() + " has been registered");
Element root = new Element("success");
Document doc = new Document(root);
root.setAttribute("ticket", ticket);
// Add the logon ticket
response.addCookie(new Cookie(Constants.LOGON_TICKET, vpnSession.getSessionInfo().getLogonTicket()));
sendDocument(doc, response);
} catch (InvalidTicketException ex) {
// The ticket is invalid
log.error("SSL-Explorer Agent " + request.getRemoteHost() + " provided an invalid ticket (" + ticket + ")");
sendError(ex.getMessage(), response);
}
}
// We have processed the output ourselves
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -