use of org.jivesoftware.openfire.session.ComponentSession in project Openfire by igniterealtime.
the class ComponentStanzaHandler method processUnknowPacket.
@Override
boolean processUnknowPacket(Element doc) throws UnauthorizedException {
String tag = doc.getName();
if ("handshake".equals(tag)) {
// External component is trying to authenticate
if (!((LocalComponentSession) session).authenticate(doc.getStringValue())) {
session.close();
}
return true;
} else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
session.close();
return true;
} else if ("bind".equals(tag)) {
// Handle subsequent bind packets
LocalComponentSession componentSession = (LocalComponentSession) session;
// Get the external component of this session
ComponentSession.ExternalComponent component = componentSession.getExternalComponent();
String initialDomain = component.getInitialSubdomain();
String extraDomain = doc.attributeValue("name");
String allowMultiple = doc.attributeValue("allowMultiple");
if (extraDomain == null || "".equals(extraDomain)) {
// No new bind domain was specified so return a bad_request error
Element reply = doc.createCopy();
reply.add(new PacketError(PacketError.Condition.bad_request).getElement());
connection.deliverRawText(reply.asXML());
} else if (extraDomain.equals(initialDomain)) {
// Component is binding initial domain that is already registered
// Send confirmation that the new domain has been registered
connection.deliverRawText("<bind/>");
} else if (extraDomain.endsWith(initialDomain)) {
// Only accept subdomains under the initial registered domain
if (allowMultiple != null && component.getSubdomains().contains(extraDomain)) {
// Domain already in use so return a conflict error
Element reply = doc.createCopy();
reply.add(new PacketError(PacketError.Condition.conflict).getElement());
connection.deliverRawText(reply.asXML());
} else {
try {
// Get the requested subdomain
String subdomain = extraDomain;
int index = extraDomain.indexOf(XMPPServer.getInstance().getServerInfo().getXMPPDomain());
if (index > -1) {
subdomain = extraDomain.substring(0, index - 1);
}
InternalComponentManager.getInstance().addComponent(subdomain, component);
// Send confirmation that the new domain has been registered
connection.deliverRawText("<bind/>");
} catch (ComponentException e) {
Log.error("Error binding extra domain: " + extraDomain + " to component: " + component, e);
// Return internal server error
Element reply = doc.createCopy();
reply.add(new PacketError(PacketError.Condition.internal_server_error).getElement());
connection.deliverRawText(reply.asXML());
}
}
} else {
// Return forbidden error since we only allow subdomains of the intial domain
// to be used by the same external component
Element reply = doc.createCopy();
reply.add(new PacketError(PacketError.Condition.forbidden).getElement());
connection.deliverRawText(reply.asXML());
}
return true;
}
return false;
}
use of org.jivesoftware.openfire.session.ComponentSession in project Openfire by igniterealtime.
the class SessionManager method getComponentSessions.
/**
* Returns a collection with the established sessions from external components.
*
* @return a collection with the established sessions from external components.
*/
public Collection<ComponentSession> getComponentSessions() {
List<ComponentSession> sessions = new ArrayList<>();
// Add sessions of external components connected to this JVM
sessions.addAll(localSessionManager.getComponentsSessions());
// Add sessions of external components connected to other cluster nodes
RemoteSessionLocator locator = server.getRemoteSessionLocator();
if (locator != null) {
for (Map.Entry<String, byte[]> entry : componentSessionsCache.entrySet()) {
if (!server.getNodeID().equals(entry.getValue())) {
sessions.add(locator.getComponentSession(entry.getValue(), new JID(entry.getKey())));
}
}
}
return sessions;
}
Aggregations