use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class SparkManager method notifyDiscoInfoChanged.
/**
* Notify all users who have requested disco information from this component that settings have been changed.
* Clients should perform a new service discovery to see what has changed.
*/
public void notifyDiscoInfoChanged() {
final Message message = new Message();
message.setFrom(serviceName + "." + componentManager.getServerName());
Element child = message.addChildElement("event", "http://jabber.org/protocol/disco#info");
buildFeatureSet(child);
sessionManager.broadcast(message);
}
use of org.xmpp.packet.Message 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.Message in project Openfire by igniterealtime.
the class BroadcastPlugin method processPacket.
public void processPacket(Packet packet) {
boolean canProceed = false;
Group group = null;
String toNode = packet.getTo().getNode();
// Check if user is allowed to send packet to this service[+group]
boolean targetAll = "all".equals(toNode);
if (targetAll) {
// See if the user is allowed to send the packet.
JID address = new JID(packet.getFrom().toBareJID());
if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
canProceed = true;
}
} else {
try {
if (toNode != null) {
group = groupManager.getGroup(toNode);
boolean isGroupUser = group.isUser(packet.getFrom()) || group.isUser(new JID(packet.getFrom().toBareJID()));
if (disableGroupPermissions || (groupMembersAllowed && isGroupUser) || allowedUsers.contains(new JID(packet.getFrom().toBareJID()))) {
canProceed = true;
}
}
} catch (GroupNotFoundException e) {
// Ignore.
}
}
if (packet instanceof Message) {
// Respond to incoming messages
Message message = (Message) packet;
processMessage(message, targetAll, group, canProceed);
} else if (packet instanceof Presence) {
// Respond to presence subscription request or presence probe
Presence presence = (Presence) packet;
processPresence(canProceed, presence);
} else if (packet instanceof IQ) {
// Handle disco packets
IQ iq = (IQ) packet;
// Ignore IQs of type ERROR or RESULT
if (IQ.Type.error == iq.getType() || IQ.Type.result == iq.getType()) {
return;
}
processIQ(iq, targetAll, group, canProceed);
}
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class BroadcastPlugin method processMessage.
private void processMessage(Message message, boolean targetAll, Group group, boolean canProceed) {
// Check to see if trying to broadcast to all connected users.
if (targetAll) {
if (!canProceed) {
Message error = new Message();
if (message.getID() != null) {
error.setID(message.getID());
}
error.setError(PacketError.Condition.not_allowed);
error.setTo(message.getFrom());
error.setFrom(message.getTo());
error.setSubject("Error sending broadcast message");
error.setBody("Not allowed to send a broadcast message to " + message.getTo());
try {
componentManager.sendPacket(this, error);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
return;
}
if ((messagePrefix != null) && (message.getBody() != null)) {
message.setBody(messagePrefix + " " + message.getBody());
}
if (all2ofline == false) {
// send to online users
sessionManager.broadcast(message);
} else {
// send to all users
Collection<User> users = userManager.getUsers();
String xmppdomain = "@" + JiveGlobals.getProperty("xmpp.domain");
for (User u : users) {
Message newMessage = message.createCopy();
newMessage.setTo(u.getUsername() + xmppdomain);
try {
componentManager.sendPacket(this, newMessage);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
}
} else // See if the name is a group.
{
if (group == null) {
// The address is not recognized so send an error message back.
Message error = new Message();
if (message.getID() != null) {
error.setID(message.getID());
}
error.setTo(message.getFrom());
error.setFrom(message.getTo());
error.setError(PacketError.Condition.not_allowed);
error.setSubject("Error sending broadcast message");
error.setBody("Address not valid: " + message.getTo());
try {
componentManager.sendPacket(this, error);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
} else if (canProceed) {
// the message when they come back online
if ((messagePrefix != null) && (message.getBody() != null)) {
message.setBody(messagePrefix + " " + message.getBody());
}
for (JID userJID : group.getMembers()) {
Message newMessage = message.createCopy();
newMessage.setTo(userJID);
try {
componentManager.sendPacket(this, newMessage);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
} else {
// Otherwise, the address is recognized so send an error message back.
Message error = new Message();
if (message.getID() != null) {
error.setID(message.getID());
}
error.setTo(message.getFrom());
error.setFrom(message.getTo());
error.setError(PacketError.Condition.not_allowed);
error.setSubject("Error sending broadcast message");
error.setBody("Not allowed to send a broadcast message to " + message.getTo());
try {
componentManager.sendPacket(this, error);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
}
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class emailOnAway method createServerMessage.
private Message createServerMessage(String to, String from, String emailTo) {
Message message = new Message();
message.setTo(to);
message.setFrom(from);
message.setSubject("I'm away");
if (JiveGlobals.getBooleanProperty("plugin.emailonaway.showemail", true)) {
message.setBody("I'm currently away. Your message has been forwarded to my email address (" + emailTo + ").");
} else {
message.setBody("I'm currently away. Your message has been forwarded to my email address.");
}
return message;
}
Aggregations