use of org.xmpp.packet.StreamError in project Openfire by igniterealtime.
the class SessionController method removeUserSessions.
/**
* Removes the user sessions.
*
* @param username the username
* @throws ServiceException the service exception
*/
public void removeUserSessions(String username) throws ServiceException {
final StreamError error = new StreamError(StreamError.Condition.not_authorized);
for (ClientSession session : SessionManager.getInstance().getSessions(username)) {
session.deliverRawText(error.toXML());
session.close();
}
}
use of org.xmpp.packet.StreamError in project Openfire by igniterealtime.
the class JustMarriedController method deleteUser.
/**
* Delete user.
*
* @param oldUser
* the old user
*/
private static void deleteUser(User oldUser) {
UserManager.getInstance().deleteUser(oldUser);
LockOutManager.getInstance().enableAccount(oldUser.getUsername());
final StreamError error = new StreamError(StreamError.Condition.not_authorized);
for (ClientSession sess : SessionManager.getInstance().getSessions(oldUser.getUsername())) {
sess.deliverRawText(error.toXML());
sess.close();
}
}
use of org.xmpp.packet.StreamError in project Openfire by igniterealtime.
the class SparkManager method closeSession.
/**
* Sends an unsupported version error and name of client the user attempted to connect with.
*
* @param session the users current session.
* @param clientName the name of the client they were connecting with.
*/
private void closeSession(final Session session, String clientName) {
// Increase the number of logins not allowed by 1.
disconnects.incrementAndGet();
Log.debug("Closed connection to client attempting to connect from " + clientName);
// Send message information user.
final Message message = new Message();
message.setFrom(serviceName + "." + componentManager.getServerName());
message.setTo(session.getAddress());
message.setBody("You are using an invalid client, and therefore will be disconnected. " + "Please ask your system administrator for client choices.");
// Send Message
sendPacket(message);
// Disconnect user after 5 seconds.
taskEngine.schedule(new TimerTask() {
@Override
public void run() {
// Include the not-authorized error in the response
StreamError error = new StreamError(StreamError.Condition.policy_violation);
session.deliverRawText(error.toXML());
// Close the underlying connection
session.close();
}
}, 5000);
}
use of org.xmpp.packet.StreamError in project Openfire by igniterealtime.
the class ServerDialback method createOutgoingSession.
/**
* Creates a new connection from the Originating Server to the Receiving Server for
* authenticating the specified domain.
*
* @param localDomain domain of the Originating Server to authenticate with the Receiving Server.
* @param remoteDomain IP address or hostname of the Receiving Server.
* @param port port of the Receiving Server.
* @return an OutgoingServerSession if the domain was authenticated or <tt>null</tt> if none.
*/
public LocalOutgoingServerSession createOutgoingSession(String localDomain, String remoteDomain, int port) {
final Logger log = LoggerFactory.getLogger(Log.getName() + "[Acting as Originating Server: Create Outgoing Session from: " + localDomain + " to RS at: " + remoteDomain + " (port: " + port + ")]");
log.debug("Creating new outgoing session...");
String hostname = null;
int realPort = port;
try {
// Establish a TCP connection to the Receiving Server
final Socket socket = SocketUtil.createSocketToXmppDomain(remoteDomain, port);
if (socket == null) {
log.info("Unable to create new outgoing session: Cannot create a plain socket connection with any applicable remote host.");
return null;
}
connection = new SocketConnection(XMPPServer.getInstance().getPacketDeliverer(), socket, false);
log.debug("Send the stream header and wait for response...");
StringBuilder stream = new StringBuilder();
stream.append("<stream:stream");
stream.append(" xmlns:stream=\"http://etherx.jabber.org/streams\"");
stream.append(" xmlns=\"jabber:server\"");
stream.append(" to=\"").append(remoteDomain).append("\"");
stream.append(" from=\"").append(localDomain).append("\"");
stream.append(" xmlns:db=\"jabber:server:dialback\"");
stream.append(">");
connection.deliverRawText(stream.toString());
// Set a read timeout (of 5 seconds) so we don't keep waiting forever
int soTimeout = socket.getSoTimeout();
socket.setSoTimeout(RemoteServerManager.getSocketTimeout());
XMPPPacketReader reader = new XMPPPacketReader();
reader.setXPPFactory(FACTORY);
reader.getXPPParser().setInput(new InputStreamReader(ServerTrafficCounter.wrapInputStream(socket.getInputStream()), CHARSET));
// Get the answer from the Receiving Server
XmlPullParser xpp = reader.getXPPParser();
for (int eventType = xpp.getEventType(); eventType != XmlPullParser.START_TAG; ) {
eventType = xpp.next();
}
log.debug("Got a response. Check if the remote server supports dialback...");
if ("jabber:server:dialback".equals(xpp.getNamespace("db"))) {
log.debug("Dialback seems to be supported by the remote server.");
// Restore default timeout
socket.setSoTimeout(soTimeout);
String id = xpp.getAttributeValue("", "id");
OutgoingServerSocketReader socketReader = new OutgoingServerSocketReader(reader);
if (authenticateDomain(socketReader, localDomain, remoteDomain, id)) {
log.debug("Successfully authenticated the connection with dialback.");
// Domain was validated so create a new OutgoingServerSession
StreamID streamID = BasicStreamIDFactory.createStreamID(id);
LocalOutgoingServerSession session = new LocalOutgoingServerSession(localDomain, connection, socketReader, streamID);
connection.init(session);
// Set the hostname as the address of the session
session.setAddress(new JID(null, remoteDomain, null));
log.debug("Successfully created new outgoing session!");
return session;
} else {
log.debug("Failed to authenticate the connection with dialback.");
// Close the connection
connection.close();
}
} else {
log.debug("Error! Invalid namespace in packet: '{}'. Closing connection.", xpp.getText());
// Send an invalid-namespace stream error condition in the response
connection.deliverRawText(new StreamError(StreamError.Condition.invalid_namespace).toXML());
// Close the connection
connection.close();
}
} catch (Exception e) {
log.error("An exception occurred while creating outgoing session to remote server:", e);
// Close the connection
if (connection != null) {
connection.close();
}
}
log.warn("Unable to create a new outgoing session");
return null;
}
use of org.xmpp.packet.StreamError in project Openfire by igniterealtime.
the class XmppWebSocket method processStanza.
// helper/utility methods
/*
* Process stream headers/footers and authentication stanzas locally;
* otherwise delegate stanza handling to the session packet router.
*/
private void processStanza(Element stanza) {
try {
String tag = stanza.getName();
if (STREAM_FOOTER.equals(tag)) {
closeStream(null);
} else if ("auth".equals(tag)) {
// User is trying to authenticate using SASL
startedSASL = true;
// Process authentication stanza
xmppSession.incrementClientPacketCount();
saslStatus = SASLAuthentication.handle(xmppSession, stanza);
} else if (startedSASL && "response".equals(tag) || "abort".equals(tag)) {
// User is responding to SASL challenge. Process response
xmppSession.incrementClientPacketCount();
saslStatus = SASLAuthentication.handle(xmppSession, stanza);
} else if (STREAM_HEADER.equals(tag)) {
// restart the stream
openStream(stanza.attributeValue(QName.get("lang", XMLConstants.XML_NS_URI), "en"), stanza.attributeValue("from"));
configureStream();
} else if (Status.authenticated.equals(saslStatus)) {
if (router == null) {
if (isStreamManagementAvailable()) {
router = new StreamManagementPacketRouter(xmppSession);
} else {
// fall back for older Openfire installations
router = new SessionPacketRouter(xmppSession);
}
}
router.route(stanza);
} else {
// require authentication
Log.warn("Not authorized: " + stanza.asXML());
sendPacketError(stanza, PacketError.Condition.not_authorized);
}
} catch (UnknownStanzaException use) {
Log.warn("Received invalid stanza: " + stanza.asXML());
sendPacketError(stanza, PacketError.Condition.bad_request);
} catch (Exception ex) {
Log.error("Failed to process incoming stanza: " + stanza.asXML(), ex);
closeStream(new StreamError(StreamError.Condition.internal_server_error));
}
}
Aggregations