1 19 20 package com.sslexplorer.agent.actions; 21 22 import java.util.Locale ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 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 59 public class RegisterClientSynchronizationAction extends XMLOutputAction { 60 61 final static Log log = LogFactory.getLog(RegisterClientSynchronizationAction.class); 62 63 71 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 72 throws Exception { 73 74 MessageResources resources = CoreUtil.getMessageResources(request.getSession(), "agent"); 75 76 String 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 ) request.getSession().getAttribute(Globals.LOCALE_KEY), 100 "registerSync.message.ok")); 101 sendDocument(doc, response); 102 103 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 ) request.getSession().getAttribute(Globals.LOCALE_KEY), 116 "registerSync.message.failed"), response); 117 118 return null; 119 } 120 } | Popular Tags |