1 11 12 package org.jivesoftware.messenger.server; 13 14 import org.jivesoftware.messenger.*; 15 import org.jivesoftware.messenger.net.SocketConnection; 16 import org.jivesoftware.messenger.auth.UnauthorizedException; 17 import org.xmpp.packet.Packet; 18 import org.dom4j.io.XPPPacketReader; 19 import org.dom4j.Element; 20 import org.xmlpull.v1.XmlPullParserException; 21 import org.xmlpull.v1.XmlPullParser; 22 23 import java.io.IOException ; 24 import java.util.Collection ; 25 import java.util.ArrayList ; 26 import java.util.Collections ; 27 28 49 public class IncomingServerSession extends Session { 50 51 private Collection <String > validatedDomains = new ArrayList <String >(); 52 53 75 public static Session createSession(String serverName, XPPPacketReader reader, 76 SocketConnection connection) throws XmlPullParserException, IOException { 77 XmlPullParser xpp = reader.getXPPParser(); 78 if (xpp.getNamespace("db") != null) { 79 ServerDialback method = new ServerDialback(connection, serverName); 80 return method.createIncomingSession(reader); 81 } 82 connection.close(); 84 return null; 85 } 86 87 public IncomingServerSession(String serverName, Connection connection, StreamID streamID) { 88 super(serverName, connection, streamID); 89 } 90 91 public void process(Packet packet) throws UnauthorizedException, PacketException { 92 } 94 95 106 public boolean validateSubsequentDomain(Element dbResult) { 107 ServerDialback method = new ServerDialback(getConnection(), getServerName()); 108 if (method.validateRemoteDomain(dbResult, getStreamID())) { 109 addValidatedDomain(dbResult.attributeValue("from")); 110 return true; 111 } 112 return false; 113 } 114 115 127 public boolean isValidDomain(String domain) { 128 for (String validatedDomain : getValidatedDomains()) { 130 if (domain.contains(validatedDomain)) { 131 return true; 132 } 133 } 134 return false; 135 } 136 137 144 public Collection <String > getValidatedDomains() { 145 return Collections.unmodifiableCollection(validatedDomains); 146 } 147 148 154 public void addValidatedDomain(String domain) { 155 if (validatedDomains.add(domain)) { 156 SessionManager.getInstance().registerIncomingServerSession(domain, this); 158 } 159 } 160 161 169 public void removeValidatedDomain(String domain) { 170 validatedDomains.remove(domain); 171 SessionManager.getInstance().unregisterIncomingServerSession(domain); 173 } 174 175 182 public void verifyReceivedKey(Element doc) { 183 ServerDialback.verifyReceivedKey(doc, getConnection()); 184 } 185 } 186 | Popular Tags |