1 19 20 package com.sslexplorer.notification.agent; 21 22 import java.io.IOException ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import com.maverick.multiplex.Request; 30 import com.maverick.util.ByteArrayWriter; 31 import com.sslexplorer.agent.AgentTunnel; 32 import com.sslexplorer.agent.DefaultAgentManager; 33 import com.sslexplorer.notification.Message; 34 import com.sslexplorer.notification.MessageSink; 35 import com.sslexplorer.notification.Notifier; 36 import com.sslexplorer.notification.Recipient; 37 import com.sslexplorer.security.LogonControllerFactory; 38 import com.sslexplorer.security.SessionInfo; 39 40 public class AgentMessageSink implements MessageSink { 41 final static Log log = LogFactory.getLog(AgentMessageSink.class); 42 private Notifier notifier; 43 44 public AgentMessageSink() { 45 super(); 46 } 47 48 public void start(Notifier notifier) throws Exception { 49 this.notifier = notifier; 50 } 51 52 public void stop() throws Exception { 53 } 54 55 public boolean send(Message message) throws Exception { 56 int sent = 0; 58 List l = notifier.getFullRecipientListAsUsers(message.getRecipients()); 59 for (Iterator i = l.iterator(); i.hasNext();) { 60 Recipient r = (Recipient) i.next(); 61 List sessionInfo = LogonControllerFactory.getInstance().getSessionInfo(r.getRecipientAlias(), SessionInfo.UI); 62 if (sessionInfo != null) { 63 for (Iterator j = sessionInfo.iterator(); j.hasNext();) { 64 SessionInfo info = (SessionInfo) j.next(); 65 66 ByteArrayWriter msg = new ByteArrayWriter(); 67 msg.writeString(message.getSubject()); 68 msg.writeInt(0); 69 msg.writeString(message.getContent()); 70 71 if(DefaultAgentManager.getInstance().hasActiveAgent(info) && info.getUser().getPrincipalName().equals(r.getRecipientAlias())) { 72 try { 73 Request request = new Request("agentMessage@3sp.com", msg.toByteArray()); 74 AgentTunnel tunnel = DefaultAgentManager.getInstance().getAgentBySession(info); 75 if(tunnel!=null) { 76 tunnel.sendRequest(request, false, 0); 77 sent++; 78 } 79 } catch (IOException e) { 80 log.error("Failed to send message to agent. Did it disconnect before we could send it?", e); 81 } 82 } 83 84 } 85 } 86 } 87 return sent > 0; 88 } 89 90 public String getName() { 91 return "AGENT"; 92 } 93 94 public String getShortNameKey() { 95 return "notification.vpnClient.shortName"; 96 } 97 98 public String getDescriptionKey() { 99 return "notification.vpnClient.description"; 100 } 101 102 public String getBundle() { 103 return "setup"; 104 } 105 } 106 | Popular Tags |