use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class RosterAccess method canSubscribe.
@Override
public boolean canSubscribe(Node node, JID owner, JID subscriber) {
// Let node owners and sysadmins always subscribe to the node
if (node.isAdmin(owner)) {
return true;
}
for (JID nodeOwner : node.getOwners()) {
if (nodeOwner.equals(owner)) {
return true;
}
}
// Check that the subscriber is a local user
XMPPServer server = XMPPServer.getInstance();
if (server.isLocal(owner)) {
GroupManager gMgr = GroupManager.getInstance();
Collection<String> nodeGroups = node.getRosterGroupsAllowed();
for (String groupName : nodeGroups) {
try {
Group group = gMgr.getGroup(groupName);
// access allowed if the node group is visible to the subscriber
if (server.getRosterManager().isGroupVisible(group, owner)) {
return true;
}
} catch (GroupNotFoundException gnfe) {
// ignore
}
}
} else {
// Subscriber is a remote user. This should never happen.
Log.warn("Node with access model Roster has a remote user as subscriber: " + node.getNodeID());
}
return false;
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class PubSubEngine method probePresences.
private void probePresences(final PubSubService service) {
Set<JID> affiliates = new HashSet<>();
for (Node node : service.getNodes()) {
affiliates.addAll(node.getPresenceBasedSubscribers());
}
for (JID jid : affiliates) {
// Send probe presence
Presence subscription = new Presence(Presence.Type.probe);
subscription.setTo(jid);
subscription.setFrom(service.getAddress());
service.send(subscription);
}
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class PubSubEngine method getAffiliations.
private void getAffiliations(PubSubService service, IQ iq, Element childElement) {
// TODO Assuming that owner is the bare JID (as defined in the JEP). This can be replaced with an explicit owner specified in the packet
JID owner = iq.getFrom().asBareJID();
// Collect affiliations of owner for all nodes at the service
Collection<NodeAffiliate> affiliations = new ArrayList<>();
for (Node node : service.getNodes()) {
NodeAffiliate nodeAffiliate = node.getAffiliate(owner);
if (nodeAffiliate != null) {
affiliations.add(nodeAffiliate);
}
}
// Create reply to send
IQ reply = IQ.createResultIQ(iq);
Element replyChildElement = childElement.createCopy();
reply.setChildElement(replyChildElement);
if (affiliations.isEmpty()) {
// User does not have any affiliation or subscription with the pubsub service
reply.setError(PacketError.Condition.item_not_found);
} else {
Element affiliationsElement = replyChildElement.element("affiliations");
// Add information about affiliations without subscriptions
for (NodeAffiliate affiliate : affiliations) {
Element affiliateElement = affiliationsElement.addElement("affiliation");
// Do not include the node id when node is the root collection node
if (!affiliate.getNode().isRootCollectionNode()) {
affiliateElement.addAttribute("node", affiliate.getNode().getNodeID());
}
affiliateElement.addAttribute("jid", affiliate.getJID().toString());
affiliateElement.addAttribute("affiliation", affiliate.getAffiliation().name());
}
}
// Send reply
router.route(reply);
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class PubSubModule method getItems.
@Override
public Iterator<DiscoServerItem> getItems() {
// Check if the service is disabled. Info is not available when disabled.
if (!isServiceEnabled()) {
return null;
}
ArrayList<DiscoServerItem> items = new ArrayList<>();
final DiscoServerItem item = new DiscoServerItem(new JID(getServiceDomain()), "Publish-Subscribe service", null, null, this, this);
items.add(item);
return items.iterator();
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class PubSubEngine method publishItemsToNode.
private void publishItemsToNode(PubSubService service, IQ iq, Element publishElement) {
String nodeID = publishElement.attributeValue("node");
Node node;
JID from = iq.getFrom();
// TODO Assuming that owner is the bare JID (as defined in the JEP). This can be replaced with an explicit owner specified in the packet
JID owner = from.asBareJID();
if (nodeID == null) {
// XEP-0060 Section 7.2.3.3 - No node was specified. Return bad_request error
// This suggests that Instant nodes should not be auto-created
Element pubsubError = DocumentHelper.createElement(QName.get("nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
} else {
// Look for the specified node
node = service.getNode(nodeID);
if (node == null) {
if (service instanceof PEPService && service.isServiceAdmin(owner)) {
// If it is a PEP service & publisher is service owner -
// auto create nodes.
Element childElement = iq.getChildElement();
Element createElement = publishElement.element("publish");
CreateNodeResponse response = createNodeHelper(service, iq, childElement, createElement);
if (response.newNode == null) {
// New node creation failed. Since pep#auto-create is advertised
// in disco#info, node creation error should be sent to the client.
sendErrorPacket(iq, response.creationStatus, response.pubsubError);
} else {
// Node creation succeeded, set node to newNode.
node = response.newNode;
}
} else {
// Node does not exist. Return item-not-found error
sendErrorPacket(iq, PacketError.Condition.item_not_found, null);
return;
}
}
}
if (!node.getPublisherModel().canPublish(node, owner) && !service.isServiceAdmin(owner)) {
// Entity does not have sufficient privileges to publish to node
sendErrorPacket(iq, PacketError.Condition.forbidden, null);
return;
}
if (node.isCollectionNode()) {
// Node is a collection node. Return feature-not-implemented error
Element pubsubError = DocumentHelper.createElement(QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors"));
pubsubError.addAttribute("feature", "publish");
sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);
return;
}
LeafNode leafNode = (LeafNode) node;
Iterator itemElements = publishElement.elementIterator("item");
// Check that an item was included if node persist items or includes payload
if (!itemElements.hasNext() && leafNode.isItemRequired()) {
Element pubsubError = DocumentHelper.createElement(QName.get("item-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
// includes payload
if (itemElements.hasNext() && !leafNode.isItemRequired()) {
Element pubsubError = DocumentHelper.createElement(QName.get("item-forbidden", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
List<Element> items = new ArrayList<>();
List entries;
Element payload;
while (itemElements.hasNext()) {
Element item = (Element) itemElements.next();
entries = item.elements();
payload = entries.isEmpty() ? null : (Element) entries.get(0);
// in notifications
if (payload == null && leafNode.isPayloadDelivered()) {
Element pubsubError = DocumentHelper.createElement(QName.get("payload-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
// Check that the payload (if any) contains only one child element
if (entries.size() > 1) {
Element pubsubError = DocumentHelper.createElement(QName.get("invalid-payload", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
items.add(item);
}
// Return success operation
router.route(IQ.createResultIQ(iq));
// Publish item and send event notifications to subscribers
leafNode.publishItems(from, items);
}
Aggregations