Search in sources :

Example 16 with Workgroup

use of org.jivesoftware.xmpp.workgroup.Workgroup in project Openfire by igniterealtime.

the class WorkgroupUtils method toggleStatus.

public static void toggleStatus(String workgroupName) {
    final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    Workgroup workgroup;
    try {
        workgroup = workgroupManager.getWorkgroup(new JID(workgroupName));
    } catch (UserNotFoundException e) {
        return;
    }
    Workgroup.Status status = workgroup.getStatus();
    if (status == Workgroup.Status.READY) {
        workgroup.setStatus(Workgroup.Status.CLOSED);
    } else {
        workgroup.setStatus(Workgroup.Status.READY);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

Example 17 with Workgroup

use of org.jivesoftware.xmpp.workgroup.Workgroup in project Openfire by igniterealtime.

the class IQDiscoInfoHandler method handleIQ.

public IQ handleIQ(IQ packet) {
    if (packet.getType() == IQ.Type.result) {
        List<Element> features = packet.getChildElement().elements("feature");
        // Detect if this item is the MUC service
        for (Element feature : features) {
            String variable = feature.attributeValue("var");
            if ("http://jabber.org/protocol/muc".equals(variable)) {
                workgroupManager.setMUCServiceName(packet.getFrom().getDomain());
            }
        }
        return null;
    }
    // Create a copy of the sent pack that will be used as the reply
    // we only need to add the requested info to the reply if any, otherwise add
    // a not found error
    IQ reply = IQ.createResultIQ(packet);
    // Check if the disco#info was sent to the workgroup service itself
    if (workgroupManager.getAddress().equals(packet.getTo())) {
        Element iq = packet.getChildElement();
        String node = iq.attributeValue("node");
        reply.setChildElement(iq.createCopy());
        Element queryElement = reply.getChildElement();
        if (node == null) {
            // Create and add a the identity of the workgroup service
            Element identity = queryElement.addElement("identity");
            identity.addAttribute("category", "collaboration");
            // TODO Get the name from a property
            identity.addAttribute("name", "Fastpath");
            identity.addAttribute("type", "workgroup");
            // Create and add a the feature provided by the workgroup service
            Element feature = queryElement.addElement("feature");
            feature.addAttribute("var", "http://jabber.org/protocol/workgroup");
            // Create and add a the disco#info feature
            feature = queryElement.addElement("feature");
            feature.addAttribute("var", "http://jabber.org/protocol/disco#info");
            // Indicate that we can provide information about the software version being used
            feature = queryElement.addElement("feature");
            feature.addAttribute("var", "jabber:iq:version");
            // Indicate that we support ad-hoc commands
            feature = queryElement.addElement("feature");
            feature.addAttribute("var", "http://jabber.org/protocol/commands");
            // Add the features provided by the features providers
            for (DiscoFeaturesProvider provider : featuresProviders) {
                for (String newFeature : provider.getFeatures()) {
                    feature = queryElement.addElement("feature");
                    feature.addAttribute("var", newFeature);
                }
            }
        } else if ("http://jabber.org/protocol/commands".equals(node)) {
            // Create and add a the identity of the workgroup service
            Element identity = queryElement.addElement("identity");
            identity.addAttribute("category", "collaboration");
            // TODO Get the name from a property
            identity.addAttribute("name", "Fastpath");
            identity.addAttribute("type", "workgroup");
            // Create and add a the disco#info feature
            Element feature = queryElement.addElement("feature");
            feature.addAttribute("var", "http://jabber.org/protocol/disco#info");
            // Indicate that we support ad-hoc commands
            feature = queryElement.addElement("feature");
            feature.addAttribute("var", "http://jabber.org/protocol/commands");
        } else {
            // Check if the node matches a supported command
            boolean found = false;
            for (AdHocCommand command : commandManager.getCommands()) {
                if (node.equals(command.getCode())) {
                    found = true;
                    // Only include commands that the sender can invoke (i.e. has enough permissions)
                    if (command.hasPermission(packet.getFrom())) {
                        // Create and add a the identity of the command
                        Element identity = queryElement.addElement("identity");
                        identity.addAttribute("category", "automation");
                        identity.addAttribute("name", command.getLabel());
                        identity.addAttribute("type", "command-node");
                        // Indicate that we support ad-hoc commands
                        Element feature = queryElement.addElement("feature");
                        feature.addAttribute("var", "http://jabber.org/protocol/commands");
                    } else {
                        // Return Forbidden error
                        reply.setError(PacketError.Condition.forbidden);
                    }
                }
            }
            if (!found) {
                // Return item_not_found error
                reply.setError(PacketError.Condition.item_not_found);
            }
        }
    } else {
        // Check if the disco#info was sent to a given workgroup
        try {
            Workgroup workgroup = workgroupManager.getWorkgroup(packet.getTo());
            Element iq = packet.getChildElement();
            reply.setChildElement(iq.createCopy());
            Element queryElement = reply.getChildElement();
            // Create and add a the identity of the workgroup service
            Element identity = queryElement.addElement("identity");
            identity.addAttribute("category", "collaboration");
            identity.addAttribute("name", workgroup.getJID().getNode());
            identity.addAttribute("type", "workgroup");
            // Create and add a the disco#info feature
            Element feature = queryElement.addElement("feature");
            feature.addAttribute("var", "http://jabber.org/protocol/disco#info");
            Element form = queryElement.addElement("x", "jabber:x:data");
            form.addAttribute("type", "result");
            // Add static field
            Element field = form.addElement("field");
            field.addAttribute("var", "FORM_TYPE");
            field.addAttribute("type", "hidden");
            field.addElement("value").setText("http://jabber.org/protocol/workgroup#workgroupinfo");
            // Add workgroup description
            field = form.addElement("field");
            field.addAttribute("var", "workgroup#description");
            field.addAttribute("label", "Description");
            field.addElement("value").setText(workgroup.getDescription() == null ? "" : workgroup.getDescription());
            // Add workgroup online status
            field = form.addElement("field");
            field.addAttribute("var", "workgroup#online");
            field.addAttribute("label", "Status");
            field.addElement("value").setText(workgroup.getStatus().name());
        } catch (UserNotFoundException e) {
            // If we didn't find a workgroup then answer a not found error
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.item_not_found);
        }
    }
    return reply;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) AdHocCommand(org.jivesoftware.openfire.commands.AdHocCommand) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup)

Example 18 with Workgroup

use of org.jivesoftware.xmpp.workgroup.Workgroup in project Openfire by igniterealtime.

the class IQDiscoItemsHandler method handleIQ.

public IQ handleIQ(IQ packet) {
    if (packet.getType() == IQ.Type.result) {
        List<Element> items = packet.getChildElement().elements("item");
        // Send a disco#info to each discovered item
        for (Element item : items) {
            String jid = item.attributeValue("jid");
            IQ disco = new IQ(IQ.Type.get);
            disco.setTo(jid);
            disco.setFrom(packet.getTo());
            disco.setChildElement("query", "http://jabber.org/protocol/disco#info");
            workgroupManager.send(disco);
        }
        return null;
    }
    // Create a copy of the sent pack that will be used as the reply
    // we only need to add the requested info to the reply if any, otherwise add
    // a not found error
    IQ reply = IQ.createResultIQ(packet);
    if (IQ.Type.set == packet.getType()) {
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.bad_request);
        return reply;
    }
    // Check if the disco#items was sent to the workgroup service itself
    if (workgroupManager.getAddress().equals(packet.getTo())) {
        Element iq = packet.getChildElement();
        String node = iq.attributeValue("node");
        reply.setChildElement(iq.createCopy());
        Element queryElement = reply.getChildElement();
        if (node == null) {
            // Add the hosted workgroups to the reply
            for (Workgroup workgroup : workgroupManager.getWorkgroups()) {
                Element item = queryElement.addElement("item");
                item.addAttribute("jid", workgroup.getJID().toString());
                item.addAttribute("name", workgroup.getJID().getNode());
            }
        } else if ("http://jabber.org/protocol/commands".equals(node)) {
            for (AdHocCommand command : commandManager.getCommands()) {
                // Only include commands that the sender can invoke (i.e. has enough permissions)
                if (command.hasPermission(packet.getFrom())) {
                    Element item = queryElement.addElement("item");
                    item.addAttribute("jid", workgroupManager.getAddress().toString());
                    item.addAttribute("node", command.getCode());
                    item.addAttribute("name", command.getLabel());
                }
            }
        } else {
            // Unknown node. Service not available
            reply.setError(PacketError.Condition.service_unavailable);
        }
    } else {
        // Answer an error if the user is trying to discover items of a workgroup
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.not_acceptable);
    }
    return reply;
}
Also used : AdHocCommand(org.jivesoftware.openfire.commands.AdHocCommand) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup)

Example 19 with Workgroup

use of org.jivesoftware.xmpp.workgroup.Workgroup in project Openfire by igniterealtime.

the class InterceptorManager method loadLocalInterceptors.

private void loadLocalInterceptors(String workgroupJID) throws UserNotFoundException {
    Workgroup workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupJID));
    int interceptorCount = 0;
    String iCount = workgroup.getProperties().getProperty("jive.interceptor." + getPropertySuffix() + ".interceptorCount");
    if (iCount != null) {
        try {
            interceptorCount = Integer.parseInt(iCount);
        } catch (NumberFormatException nfe) {
        /* ignore */
        }
    }
    // Load up all intercpetors.
    List<PacketInterceptor> interceptorList = new ArrayList<PacketInterceptor>(interceptorCount);
    for (int i = 0; i < interceptorCount; i++) {
        try {
            String interceptorContext = "jive.interceptor." + getPropertySuffix() + ".interceptor" + i + ".";
            String className = workgroup.getProperties().getProperty(interceptorContext + "className");
            Class interceptorClass = loadClass(className);
            interceptorList.add((PacketInterceptor) interceptorClass.newInstance());
            // Load properties.
            Map<String, String> interceptorProps = new HashMap<String, String>();
            for (String key : getChildrenPropertyNames(interceptorContext + "properties", workgroup.getProperties().getPropertyNames())) {
                String value = workgroup.getProperties().getProperty(key);
                // Get the bean property name, which is everything after the last '.' in the
                // xml property name.
                interceptorProps.put(key.substring(key.lastIndexOf(".") + 1), value);
            }
            // Set properties on the bean
            BeanUtils.setProperties(interceptorList.get(i), interceptorProps);
        } catch (Exception e) {
            Log.error("Error loading local interceptor " + i, e);
        }
    }
    localInterceptors.put(workgroupJID, new CopyOnWriteArrayList<PacketInterceptor>(interceptorList));
}
Also used : JID(org.xmpp.packet.JID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 20 with Workgroup

use of org.jivesoftware.xmpp.workgroup.Workgroup in project Openfire by igniterealtime.

the class InterceptorManager method saveInterceptors.

public synchronized void saveInterceptors() {
    // Delete all global interceptors stored as properties.
    JiveGlobals.deleteProperty("interceptor.global." + getPropertySuffix());
    // Delete all the workgroup interceptors stored as properties.
    for (String jid : localInterceptors.keySet()) {
        try {
            Workgroup workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(jid));
            Collection<String> propertyNames = workgroup.getProperties().getPropertyNames();
            for (String propertyName : propertyNames) {
                if (propertyName.startsWith("jive.interceptor." + getPropertySuffix())) {
                    workgroup.getProperties().deleteProperty(propertyName);
                }
            }
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
    // Save the global interceptors as system properties
    JiveGlobals.setProperties(getPropertiesMap(globalInterceptors, "interceptor.global." + getPropertySuffix() + "."));
    // Save all the workgroup interceptors as properties of the workgroups.
    for (String jid : localInterceptors.keySet()) {
        try {
            Workgroup workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(jid));
            Map propertyMap = getPropertiesMap(localInterceptors.get(jid), "jive.interceptor." + getPropertySuffix() + ".");
            for (Iterator i = propertyMap.keySet().iterator(); i.hasNext(); ) {
                String name = (String) i.next();
                String value = (String) propertyMap.get(name);
                workgroup.getProperties().setProperty(name, value);
            }
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
}
Also used : JID(org.xmpp.packet.JID) Iterator(java.util.Iterator) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Aggregations

Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)25 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)19 JID (org.xmpp.packet.JID)15 SQLException (java.sql.SQLException)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)6 Element (org.dom4j.Element)4 AgentSession (org.jivesoftware.xmpp.workgroup.AgentSession)4 RequestQueue (org.jivesoftware.xmpp.workgroup.RequestQueue)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 NotFoundException (org.jivesoftware.util.NotFoundException)3 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)3 UnauthorizedException (org.jivesoftware.xmpp.workgroup.UnauthorizedException)3 IQ (org.xmpp.packet.IQ)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AdHocCommand (org.jivesoftware.openfire.commands.AdHocCommand)2 AgentSessionList (org.jivesoftware.xmpp.workgroup.AgentSessionList)2