KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > actions > RegisterClientSynchronizationAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.agent.actions;
21
22 import java.util.Locale JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.struts.Globals;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionForward;
32 import org.apache.struts.action.ActionMapping;
33 import org.apache.struts.util.MessageResources;
34 import org.jdom.Document;
35 import org.jdom.Element;
36
37 import com.sslexplorer.agent.DefaultAgentManager;
38 import com.sslexplorer.core.CoreUtil;
39 import com.sslexplorer.core.actions.XMLOutputAction;
40 import com.sslexplorer.properties.Property;
41 import com.sslexplorer.properties.impl.profile.ProfilePropertyKey;
42 import com.sslexplorer.security.LogonControllerFactory;
43 import com.sslexplorer.security.SessionInfo;
44
45 /**
46  * An {@link com.sslexplorer.core.actions.XMLOutputAction} that blocks until the
47  * <i>SSL-Explorer Agent</i> or an application using the <i>Embedded Client API</i>
48  * registers.
49  * <p>
50  * If registration does not occur within the specified amount of time an error
51  * XML document will be returned, otherwise and XML document containing the port
52  * on which the VPN client has been started is returned.
53  * <p>
54  * This is used by the agent launcher applet so prevent the next being displayed
55  * until the VPN client is up and running.
56  *
57  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
58  */

59 public class RegisterClientSynchronizationAction extends XMLOutputAction {
60
61     final static Log log = LogFactory.getLog(RegisterClientSynchronizationAction.class);
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
67      * org.apache.struts.action.ActionForm,
68      * javax.servlet.http.HttpServletRequest,
69      * javax.servlet.http.HttpServletResponse)
70      */

71     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
72                     throws Exception JavaDoc {
73
74         MessageResources resources = CoreUtil.getMessageResources(request.getSession(), "agent");
75
76         // Get the pending VPN session ticket
77
String JavaDoc ticket = request.getParameter("ticket");
78         
79         if (log.isDebugEnabled())
80             log.debug("Registering agent synchronization " + ticket);
81
82         if(DefaultAgentManager.getInstance().getSessionByAgentId(ticket)!=null) {
83             SessionInfo session = DefaultAgentManager.getInstance().getSessionByAgentId(ticket);
84             session.setSession(request.getSession());
85             
86             int timeout = Property.getPropertyInt(new ProfilePropertyKey(
87                 CoreUtil.getCurrentPropertyProfileId(request.getSession()),
88                 session.getUser().getPrincipalName(), "client.registration.synchronization.timeout", session.getUser().getRealm().getResourceId()));
89     
90             if (log.isDebugEnabled())
91                 log.debug("Waiting for agent registration (timeout " + timeout + ")");
92             
93             if (DefaultAgentManager.getInstance().waitForRegistrationAndSynchronization(ticket, timeout)) {
94                 if (log.isDebugEnabled())
95                     log.debug("Successfull agent registration");
96                 LogonControllerFactory.getInstance().removeAuthorizationTicket(ticket);
97                 Element root = new Element("success");
98                 Document doc = new Document(root);
99                 root.setText(resources.getMessage((Locale JavaDoc) request.getSession().getAttribute(Globals.LOCALE_KEY),
100                     "registerSync.message.ok"));
101                 sendDocument(doc, response);
102                 
103                 // Were complete
104
return null;
105             }
106             else {
107                 log.error("Registration of agent did not occur when the specified timeout of " + timeout + "ms");
108                 LogonControllerFactory.getInstance().removeAuthorizationTicket(ticket);
109             }
110         }
111         
112         if (log.isDebugEnabled())
113                 log.debug("Failed agent registration");
114         
115         sendError(resources.getMessage((Locale JavaDoc) request.getSession().getAttribute(Globals.LOCALE_KEY),
116                 "registerSync.message.failed"), response);
117
118         return null;
119     }
120 }
Popular Tags