use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class MultiUserChatManager method updateMultiUserChatService.
/**
* Updates the configuration of a MUC service. This is more involved than it may seem. If the
* subdomain is changed, we need to shut down the old service and start up the new one, registering
* the new subdomain and cleaning up the old one. Properties are tied to the ID, which will not change.
*
* @param serviceID The ID of the service to be updated.
* @param subdomain New subdomain to assign to the service.
* @param description New description to assign to the service.
* @throws NotFoundException if service was not found.
*/
public void updateMultiUserChatService(Long serviceID, String subdomain, String description) throws NotFoundException {
MultiUserChatServiceImpl muc = (MultiUserChatServiceImpl) getMultiUserChatService(serviceID);
if (muc == null)
throw new NotFoundException();
// A NotFoundException is thrown if the specified service was not found.
String oldsubdomain = muc.getServiceName();
if (!mucServices.containsKey(oldsubdomain)) {
// This should never occur, but just in case...
throw new NotFoundException();
}
if (oldsubdomain.equals(subdomain)) {
// Alright, all we're changing is the description. This is easy.
updateService(serviceID, subdomain, description);
// Update the existing service's description.
muc.setDescription(description);
} else {
// Changing the subdomain, here's where it gets complex.
// Unregister existing muc service
unregisterMultiUserChatService(subdomain);
// Update the information stored about the MUC service
updateService(serviceID, subdomain, description);
// Create new MUC service with new settings
muc = new MultiUserChatServiceImpl(subdomain, description, muc.isHidden());
// Register to new service
registerMultiUserChatService(muc);
}
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseTransport method interceptPacket.
/**
* Intercepts disco items packets to filter out users who aren't allowed to register.
*
* @see org.jivesoftware.openfire.interceptor.PacketInterceptor#interceptPacket(org.xmpp.packet.Packet, org.jivesoftware.openfire.session.Session, boolean, boolean)
*/
@SuppressWarnings("unchecked")
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) {
// If not IQ, return immediately.
if (!(packet instanceof IQ)) {
return;
}
// If it's a result IQ, process for possible filtering.
if (((IQ) packet).getType().equals(IQ.Type.result)) {
// If the packet is not outgoing back to the user or not processed yet, we don't care.
if (processed || incoming) {
return;
}
// If not query, return immediately.
Element child = packet.getElement().element("query");
if (child == null) {
return;
}
// If no namespace uri, return immediately.
if (child.getNamespaceURI() == null) {
return;
}
// If not disco#items, return immediately.
if (!child.getNamespaceURI().equals(NameSpace.DISCO_ITEMS)) {
return;
}
// If the node is null, we don't care, not directly related to a user.
JID to = packet.getTo();
if (to.getNode() == null) {
return;
}
JID from = packet.getFrom();
// If not from server itself, return immediately.
if (!XMPPServer.getInstance().isLocal(from)) {
return;
}
// If user registered, return immediately.
if (RegistrationManager.getInstance().isRegistered(to, transportType)) {
return;
}
// Check if allowed, if so return immediately.
if (permissionManager.hasAccess(to)) {
return;
}
// Filter out item associated with transport.
Iterator iter = child.elementIterator();
while (iter.hasNext()) {
Element elem = (Element) iter.next();
try {
if (elem.attribute("jid").getText().equals(this.jid.toString())) {
child.remove(elem);
}
} catch (Exception e) {
// No worries. Wasn't what we were looking for.
}
}
return;
}
// If it's a set IQ, process for possible roster activity.
if (((IQ) packet).getType().equals(IQ.Type.set)) {
// If the packet is not coming from the user, we don't care.
if (!incoming) {
return;
}
// If not query, return immediately.
Element child = packet.getElement().element("query");
if (child == null) {
return;
}
// If not jabber:iq:roster, return immediately.
if (!child.getNamespaceURI().equals(NameSpace.IQ_ROSTER)) {
return;
}
// Example items in roster modification.
Iterator iter = child.elementIterator();
while (iter.hasNext()) {
Element elem = (Element) iter.next();
if (!elem.getName().equals("item")) {
continue;
}
String jidStr;
String nickname = null;
String sub = null;
ArrayList<String> groups = new ArrayList<String>();
try {
jidStr = elem.attributeValue("jid");
} catch (Exception e) {
// No JID found, we don't want this then.
continue;
}
JID jid = new JID(jidStr);
if (!jid.getDomain().equals(this.getJID().toString())) {
// Not for our domain, moving on.
continue;
}
if (jid.getNode() == null) {
// Gateway itself, don't care.
return;
}
try {
nickname = elem.attributeValue("name");
} catch (Exception e) {
// No nickname, ok then.
}
try {
sub = elem.attributeValue("subscription");
} catch (Exception e) {
// No subscription, no worries.
}
Iterator groupIter = elem.elementIterator();
while (groupIter.hasNext()) {
Element groupElem = (Element) groupIter.next();
if (!groupElem.getName().equals("group")) {
continue;
}
groups.add(groupElem.getText());
}
if (sub != null && sub.equals("remove")) {
try {
TransportSession trSession = sessionManager.getSession(session.getAddress().getNode());
if (!trSession.isRosterLocked(jid.toString())) {
Log.debug(getType().toString() + ": contact delete " + session.getAddress().getNode() + ":" + jid);
trSession.getBuddyManager().removeBuddy(convertJIDToID(jid));
}
} catch (NotFoundException e) {
// Well we just don't care then.
}
} else {
try {
TransportSession trSession = sessionManager.getSession(session.getAddress().getNode());
if (!trSession.isRosterLocked(jid.toString())) {
try {
TransportBuddy buddy = trSession.getBuddyManager().getBuddy(jid);
Log.debug(getType().toString() + ": contact update " + session.getAddress().getNode() + ":" + jid + ":" + nickname + ":" + groups);
buddy.setNicknameAndGroups(nickname, groups);
} catch (NotFoundException e) {
Log.debug(getType().toString() + ": contact add " + session.getAddress().getNode() + ":" + jid + ":" + nickname + ":" + groups);
trSession.addContact(jid, nickname, groups);
}
}
} catch (NotFoundException e) {
// Well we just don't care then.
}
}
}
}
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseTransport method vCardCreated.
/**
* VCard was just created.
*
* @see org.jivesoftware.openfire.vcard.VCardListener#vCardCreated(String, Element)
*/
public void vCardCreated(String username, Element vcardElem) {
if (vcardElem != null) {
if (JiveGlobals.getBooleanProperty("plugin.gateway." + getType() + ".avatars", true)) {
Element photoElem = vcardElem.element("PHOTO");
if (photoElem != null) {
Element typeElem = photoElem.element("TYPE");
Element binElem = photoElem.element("BINVAL");
if (typeElem != null && binElem != null) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] imageData = Base64.decode(binElem.getText());
md.update(imageData);
String xmppHash = StringUtils.encodeHex(md.digest());
try {
TransportSession<B> trSession = sessionManager.getSession(username);
if (trSession.getAvatar() == null || !trSession.getAvatar().getXmppHash().equals(xmppHash)) {
// Store a cache of the avatar
trSession.setAvatar(new Avatar(trSession.getJID(), imageData));
trSession.updateLegacyAvatar(typeElem.getText(), imageData);
}
} catch (NotFoundException e) {
// Not an active session, ignore.
}
} catch (NoSuchAlgorithmException e) {
Log.error("Gateway: Unable to find support for SHA algorith?");
}
}
}
}
}
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseTransport method sendMessage.
/**
* Sends a simple message through he component manager.
*
* @param to Who the message is for.
* @param from Who the message is from.
* @param msg Message to be send.
* @param type Type of message to be sent.
*/
public void sendMessage(JID to, JID from, String msg, Message.Type type) {
Message m = new Message();
m.setType(type);
m.setFrom(from);
m.setTo(to);
m.setBody(net.sf.kraken.util.StringUtils.removeInvalidXMLCharacters(msg));
if (msg.length() == 0) {
Log.debug("Dropping empty message packet.");
return;
}
if (type.equals(Message.Type.chat) || type.equals(Message.Type.normal)) {
chatStateEventSource.isActive(from, to);
m.addChildElement("active", NameSpace.CHATSTATES);
if (JiveGlobals.getBooleanProperty("plugin.gateway.globsl.messageeventing", true)) {
Element xEvent = m.addChildElement("x", "jabber:x:event");
// xEvent.addElement("id");
xEvent.addElement("composing");
}
} else if (type.equals(Message.Type.error)) {
// Error responses require error elements, even if we aren't going to do it "right" yet
// TODO: All -real- error handling
m.setError(Condition.undefined_condition);
}
try {
TransportSession session = sessionManager.getSession(to);
if (session.getDetachTimestamp() != 0) {
// This is a detached session then, so lets store the packet instead of delivering.
session.storePendingPacket(m);
return;
}
} catch (NotFoundException e) {
// No session? That's "fine", allow it through, it's probably something from the transport itself.
}
sendPacket(m);
}
use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.
the class BaseTransport method handleIQLast.
/**
* Handle last request.
*
* @param packet An IQ packet in the jabber:iq:last namespace.
* @return A list of IQ packets to be returned to the user.
*/
private List<Packet> handleIQLast(IQ packet) {
List<Packet> reply = new ArrayList<Packet>();
JID from = packet.getFrom();
JID to = packet.getTo();
if (packet.getType() == IQ.Type.get) {
IQ result = IQ.createResultIQ(packet);
if (from.getNode() != null) {
try {
TransportSession<B> session = sessionManager.getSession(from);
Element response = DocumentHelper.createElement(QName.get("query", NameSpace.IQ_LAST));
Long timestamp = session.getBuddyManager().getBuddy(to).getLastActivityTimestamp();
String lastevent = session.getBuddyManager().getBuddy(to).getLastActivityEvent();
response.addAttribute("seconds", new Long(new Date().getTime() - timestamp).toString());
if (lastevent != null) {
response.addCDATA(lastevent);
}
result.setChildElement(response);
} catch (NotFoundException e) {
Log.debug("Contact not found while retrieving last activity for: " + from);
result.setError(Condition.item_not_found);
}
} else {
result.setError(Condition.feature_not_implemented);
}
reply.add(result);
} else if (packet.getType() == IQ.Type.set) {
IQ result = IQ.createResultIQ(packet);
result.setError(Condition.forbidden);
reply.add(result);
}
return reply;
}
Aggregations