Search in sources :

Example 1 with UnauthorizedException

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

the class DbDispatcherInfoProvider method deleteDispatcherInfo.

/**
     * Deletes the DispatcherInfo Object from the given RequestQueue.
     * @param queueID the id of the RequestQueue.
     * @throws UnauthorizedException thrown if the user is not allowed to delete from the db.
     */
public void deleteDispatcherInfo(long queueID) throws UnauthorizedException {
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(DELETE_DISPATCHER);
        pstmt.setLong(1, queueID);
        pstmt.executeUpdate();
    } catch (SQLException e) {
        Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
        throw new UnauthorizedException();
    } finally {
        DbConnectionManager.closeConnection(pstmt, con);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) PreparedStatement(java.sql.PreparedStatement)

Example 2 with UnauthorizedException

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

the class FormManager method saveDataForm.

private void saveDataForm(Workgroup workgroup) {
    DataForm dataForm = new DataForm(DataForm.Type.form);
    WorkgroupForm form = getWebForm(workgroup);
    if (form.getTitle() != null) {
        dataForm.setTitle(form.getTitle());
    }
    if (form.getDescription() != null) {
        dataForm.addInstruction(form.getDescription());
    }
    List<FormElement> elems = new ArrayList<FormElement>();
    // Add normal elems
    int size = form.getFormElements().size();
    for (int j = 0; j < size; j++) {
        elems.add(form.getFormElementAt(j));
    }
    size = form.getHiddenVars().size();
    for (int k = 0; k < size; k++) {
        elems.add(form.getHiddenVars().get(k));
    }
    size = elems.size();
    for (int i = 0; i < size; i++) {
        FormElement elem = elems.get(i);
        FormField field = dataForm.addField();
        field.setLabel(elem.getLabel());
        field.setVariable(elem.getVariable());
        field.setRequired(elem.isRequired());
        if (elem.getDescription() != null) {
            field.setDescription(elem.getDescription());
        }
        if (elem.getAnswerType() == WorkgroupForm.FormEnum.textarea) {
            field.setType(FormField.Type.text_multi);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.textfield) {
            field.setType(FormField.Type.text_single);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.checkbox) {
            field.setType(FormField.Type.boolean_type);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.radio_button) {
            field.setType(FormField.Type.list_multi);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.dropdown_box) {
            field.setType(FormField.Type.list_single);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.hidden) {
            field.setType(FormField.Type.hidden);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.password) {
            field.setType(FormField.Type.text_private);
        }
        if (elem.getAnswers().size() > 0 && elem.getAnswerType() != WorkgroupForm.FormEnum.hidden) {
            for (String item : elem.getAnswers()) {
                field.addOption(item, item);
            }
        } else if (elem.getAnswers().size() > 0) {
            // Add hidden element values.
            for (String item : elem.getAnswers()) {
                field.addValue(item);
            }
        }
    }
    XStream xstream = new XStream();
    String xmlToSave = xstream.toXML(dataForm);
    DbProperties props = workgroup.getProperties();
    String context = "jive.dataform.wg";
    try {
        props.deleteProperty(context);
        props.setProperty(context, xmlToSave);
    } catch (UnauthorizedException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) DataForm(org.xmpp.forms.DataForm) ArrayList(java.util.ArrayList) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties) FormField(org.xmpp.forms.FormField)

Example 3 with UnauthorizedException

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

the class ChatSettingsCreator method createBotSettings.

/**
     * Adds the default bot settings to the database.
     *
     * @param workgroupJID - the JID of the workgroup to setup.
     */
private void createBotSettings(JID workgroupJID) {
    try {
        // Enable the workgroup chatbot by default
        Workgroup workgroup = WorkgroupManager.getInstance().getWorkgroup(workgroupJID);
        workgroup.chatbotEnabled(true);
        for (KeyEnum key : botMap.keySet()) {
            String value = botMap.get(key);
            createChatSetting(workgroupJID, key, ChatSettings.SettingType.bot_settings, value);
        }
    } catch (UserNotFoundException e) {
        Log.error(e.getMessage(), e);
    } catch (UnauthorizedException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup)

Example 4 with UnauthorizedException

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

the class FormManager method saveWorkgroupForm.

public void saveWorkgroupForm(Workgroup workgroup) {
    // Save Web Form for editing
    WorkgroupForm workgroupForm = getWebForm(workgroup);
    if (workgroupForm != null) {
        XStream xstream = new XStream();
        String xmlToSave = xstream.toXML(workgroupForm);
        DbProperties props = workgroup.getProperties();
        String context = "jive.webform.wg";
        try {
            props.deleteProperty(context);
            props.setProperty(context, xmlToSave);
        } catch (UnauthorizedException e) {
            Log.error(e.getMessage(), e);
        }
    }
    // Save DataForm for usage
    saveDataForm(workgroup);
}
Also used : XStream(com.thoughtworks.xstream.XStream) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties)

Example 5 with UnauthorizedException

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

the class MacroProvider method executeSet.

public void executeSet(IQ packet, Workgroup workgroup) {
    IQ reply;
    Element iq = packet.getChildElement();
    String personalMacro = iq.element("personalMacro").getTextTrim();
    try {
        // Verify that an agent is requesting this information.
        Agent agent = workgroup.getAgentManager().getAgent(packet.getFrom());
        DbProperties props = agent.getProperties();
        XStream xstream = new XStream();
        xstream.alias("macro", Macro.class);
        xstream.alias("macrogroup", MacroGroup.class);
        MacroGroup group = (MacroGroup) xstream.fromXML(personalMacro);
        String saveString = xstream.toXML(group);
        try {
            props.deleteProperty("personal.macro");
            props.setProperty("personal.macro", saveString);
        } catch (UnauthorizedException e) {
            Log.error(e.getMessage(), e);
        }
        reply = IQ.createResultIQ(packet);
    } catch (AgentNotFoundException e) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
    }
    workgroup.send(reply);
}
Also used : Agent(org.jivesoftware.xmpp.workgroup.Agent) XStream(com.thoughtworks.xstream.XStream) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties)

Aggregations

UnauthorizedException (org.jivesoftware.xmpp.workgroup.UnauthorizedException)8 DbProperties (org.jivesoftware.xmpp.workgroup.DbProperties)4 XStream (com.thoughtworks.xstream.XStream)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)1 Element (org.dom4j.Element)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 Agent (org.jivesoftware.xmpp.workgroup.Agent)1 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)1 Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)1 DataForm (org.xmpp.forms.DataForm)1 FormField (org.xmpp.forms.FormField)1 IQ (org.xmpp.packet.IQ)1 PacketError (org.xmpp.packet.PacketError)1