use of org.jivesoftware.openfire.session.LocalIncomingServerSession in project Openfire by igniterealtime.
the class SessionManager method restoreCacheContent.
private void restoreCacheContent() {
// Add external component sessions hosted locally to the cache (using new nodeID)
for (Session session : localSessionManager.getComponentsSessions()) {
componentSessionsCache.put(session.getAddress().toString(), server.getNodeID().toByteArray());
}
// Add connection multiplexer sessions hosted locally to the cache (using new nodeID)
for (String address : localSessionManager.getConnnectionManagerSessions().keySet()) {
multiplexerSessionsCache.put(address, server.getNodeID().toByteArray());
}
// Add incoming server sessions hosted locally to the cache (using new nodeID)
for (LocalIncomingServerSession session : localSessionManager.getIncomingServerSessions()) {
StreamID streamID = session.getStreamID();
incomingServerSessionsCache.put(streamID, server.getNodeID().toByteArray());
for (String hostname : session.getValidatedDomains()) {
// Update list of sockets/sessions coming from the same remote hostname
Lock lock = CacheFactory.getLock(hostname, hostnameSessionsCache);
try {
lock.lock();
List<StreamID> streamIDs = hostnameSessionsCache.get(hostname);
if (streamIDs == null) {
streamIDs = new ArrayList<>();
}
streamIDs.add(streamID);
hostnameSessionsCache.put(hostname, streamIDs);
} finally {
lock.unlock();
}
// Add to clustered cache
lock = CacheFactory.getLock(streamID, validatedDomainsCache);
try {
lock.lock();
Set<String> validatedDomains = validatedDomainsCache.get(streamID);
if (validatedDomains == null) {
validatedDomains = new HashSet<>();
}
boolean added = validatedDomains.add(hostname);
if (added) {
validatedDomainsCache.put(streamID, validatedDomains);
}
} finally {
lock.unlock();
}
}
}
}
use of org.jivesoftware.openfire.session.LocalIncomingServerSession in project Openfire by igniterealtime.
the class SessionManager method createIncomingServerSession.
/**
* Creates a session for a remote server. The session should be created only after the
* remote server has been authenticated either using "server dialback" or SASL.
*
* @param conn the connection to the remote server.
* @param id the stream ID used in the stream element when authenticating the server.
* @return the newly created {@link IncomingServerSession}.
* @throws UnauthorizedException if the local server has not been initialized yet.
*/
public LocalIncomingServerSession createIncomingServerSession(Connection conn, StreamID id, String fromDomain) throws UnauthorizedException {
if (serverName == null) {
throw new UnauthorizedException("Server not initialized");
}
LocalIncomingServerSession session = new LocalIncomingServerSession(serverName, conn, id, fromDomain);
conn.init(session);
// Register to receive close notification on this session so we can
// remove its route from the sessions set
conn.registerCloseListener(incomingServerListener, session);
return session;
}
use of org.jivesoftware.openfire.session.LocalIncomingServerSession in project Openfire by igniterealtime.
the class ServerSocketReader method packetReceived.
/**
* Make sure that the received packet has a TO and FROM values defined and that it was sent
* from a previously validated domain. If the packet does not matches any of the above
* conditions then a PacketRejectedException will be thrown.
*
* @param packet the received packet.
* @throws PacketRejectedException if the packet does not include a TO or FROM or if the packet
* was sent from a domain that was not previously validated.
*/
private void packetReceived(Packet packet) throws PacketRejectedException {
if (packet.getTo() == null || packet.getFrom() == null) {
Log.debug("Closing IncomingServerSession due to packet with no TO or FROM: " + packet.toXML());
// Send a stream error saying that the packet includes no TO or FROM
StreamError error = new StreamError(StreamError.Condition.improper_addressing);
connection.deliverRawText(error.toXML());
// Close the underlying connection
connection.close();
open = false;
throw new PacketRejectedException("Packet with no TO or FROM attributes");
} else if (!((LocalIncomingServerSession) session).isValidDomain(packet.getFrom().getDomain())) {
Log.debug("Closing IncomingServerSession due to packet with invalid domain: " + packet.toXML());
// Send a stream error saying that the packet includes an invalid FROM
StreamError error = new StreamError(StreamError.Condition.invalid_from);
connection.deliverRawText(error.toXML());
// Close the underlying connection
connection.close();
open = false;
throw new PacketRejectedException("Packet with no TO or FROM attributes");
}
}
use of org.jivesoftware.openfire.session.LocalIncomingServerSession in project Openfire by igniterealtime.
the class LocalSessionManager method stop.
public void stop() {
try {
// Send the close stream header to all connected connections
Set<LocalSession> sessions = new HashSet<>();
sessions.addAll(preAuthenticatedSessions.values());
sessions.addAll(componentsSessions);
for (LocalIncomingServerSession incomingSession : incomingServerSessions.values()) {
sessions.add(incomingSession);
}
for (LocalConnectionMultiplexerSession multiplexer : connnectionManagerSessions.values()) {
sessions.add(multiplexer);
}
for (LocalSession session : sessions) {
try {
// Notify connected client that the server is being shut down
if (!session.isDetached()) {
session.getConnection().systemShutdown();
}
} catch (Throwable t) {
// Ignore.
}
}
} catch (Exception e) {
// Ignore.
}
}
use of org.jivesoftware.openfire.session.LocalIncomingServerSession in project Openfire by igniterealtime.
the class SaslServerFactoryImpl method createSaslServer.
@Override
public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map<String, ?> props, CallbackHandler cbh) throws SaslException {
if (!Arrays.asList(getMechanismNames(props)).contains(mechanism)) {
Log.debug("This implementation is unable to create a SaslServer instance for the {} mechanism using the provided properties.", mechanism);
return null;
}
switch(mechanism.toUpperCase()) {
case "PLAIN":
if (cbh == null) {
Log.debug("Unable to instantiate {} SaslServer: A callbackHandler with support for Password, Name, and AuthorizeCallback required.", mechanism);
return null;
}
return new SaslServerPlainImpl(protocol, serverName, props, cbh);
case "SCRAM-SHA-1":
return new ScramSha1SaslServer();
case "ANONYMOUS":
if (!props.containsKey(LocalSession.class.getCanonicalName())) {
Log.debug("Unable to instantiate {} SaslServer: Provided properties do not contain a LocalSession instance.", mechanism);
return null;
} else {
final LocalSession session = (LocalSession) props.get(LocalSession.class.getCanonicalName());
return new AnonymousSaslServer(session);
}
case "EXTERNAL":
if (!props.containsKey(LocalSession.class.getCanonicalName())) {
Log.debug("Unable to instantiate {} SaslServer: Provided properties do not contain a LocalSession instance.", mechanism);
return null;
} else {
final Object session = props.get(LocalSession.class.getCanonicalName());
if (session instanceof LocalClientSession) {
return new ExternalClientSaslServer((LocalClientSession) session);
}
if (session instanceof LocalIncomingServerSession) {
return new ExternalServerSaslServer((LocalIncomingServerSession) session);
}
Log.debug("Unable to instantiate {} Sasl Server: Provided properties contains neither LocalClientSession nor LocalIncomingServerSession instance.", mechanism);
return null;
}
case JiveSharedSecretSaslServer.NAME:
return new JiveSharedSecretSaslServer();
default:
// Fail fast - this should not be possible, as the first check in this method already verifies wether the mechanism is supported.
throw new IllegalStateException();
}
}
Aggregations