使用机制平原GROUPCHAT SASL身份验证失败 [英] Groupchat SASL authentication failed using mechanism PLAIN

查看:159
本文介绍了使用机制平原GROUPCHAT SASL身份验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 在org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:341)在org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:204)在org.jivesoftware.smack.Connection.login(Connection.java:357)

//这是我的code ...

 进口的java.util.ArrayList;
进口java.util.Iterator的;
进口的java.util.List;进口org.jivesoftware.smack.Chat;
进口org.jivesoftware.smack.ChatManager;
进口org.jivesoftware.smack.Connection;
进口org.jivesoftware.smack.ConnectionConfiguration;
进口org.jivesoftware.smack.PacketListener;
进口org.jivesoftware.smack.SASLAuthentication;
进口org.jivesoftware.smack.SmackConfiguration;
进口org.jivesoftware.smack.XMPPConnection;
进口org.jivesoftware.smack.XMPPException;
进口org.jivesoftware.smack.packet.Packet;
进口org.jivesoftware.smackx.Form;
进口org.jivesoftware.smackx.FormField;
进口org.jivesoftware.smackx.muc.DiscussionHistory;
进口org.jivesoftware.smackx.muc.MultiUserChat;进口android.content.Context;
进口android.util.Log;进口com.quickblox.module.chat.QBChat;公共类GroupChatController {    // ================= QuickBlox =====步骤8 =================
    //获取QuickBlox聊天服务器域。
    //这里将创建与下面的聊天服务器的连接。
    公共静态最后弦乐CHAT_SERVER = QBChat.getChatServerDomain();    私人XMPPConnection连接;    私人ConnectionConfiguration配置;
    私人聊天群聊;    私人字符串chatLogin;
    私人字符串密码;
    私人字符串的groupName;    私人字符串passgroupName;    上下文语境;    私人字符串quickusername;    私人ChatManager chatManager;  //私人布尔isGroupchat;    MultiUserChat睦;    公共GroupChatController(字符串chatLogin,字符串密码){        this.chatLogin = chatLogin;        this.password =密码;
    }

//这里我GROUPCHAT启动

 公共无效为startChat(最后弦乐组名){        this.groupName =组名;
       // this.isGroupchat = isGroup;        新主题(新的Runnable接口(){
            @覆盖
            公共无效的run(){
                //聊天动作1 - 创建连接。                Connection.DEBUG_ENABLED = TRUE;                配置=新ConnectionConfiguration(CHAT_SERVER);                连接=新XMPPConnection(配置);                尝试
                {                //这里是显示错误的连接                    connection.connect();                    connection.login(chatLogin,密码);                        //布尔型支架= MultiUserChat.isServiceEnabled(连接,chatLogin +@ muc.chat.quickblox.com);                           //例416_sedin@muc.chat.quickblox.com                            睦=新MultiUserChat(连接,组名+@ muc.chat.quickblox.com);                            DiscussionHistory历史=新DiscussionHistory();                            history.setMaxStanzas(3);                            muc.join(chatLogin,密码,历史,SmackConfiguration.getPacketReplyTimeout());                            muc.addMessageListener(groupchatManagerListener);
                }赶上(XMPPException E){                    e.printStackTrace();                } / *赶上(例外五){
                    // TODO:处理异常
                } * /
                }        })。开始();
    }

//创建MYGROUP

 公共无效createGroupChat(最后弦乐组名,最后弦乐qucikusername){        this.passgroupName =组名;        this.quickusername = qucikusername;       // this.isGroupchat = isGroup;        新主题(新的Runnable接口(){
            @覆盖
            公共无效的run(){
                //聊天动作1 - 创建连接。                Connection.DEBUG_ENABLED = TRUE;                配置=新ConnectionConfiguration(CHAT_SERVER);                连接=新XMPPConnection(配置);                尝试                {                    //SASLAuthentication.supportSASLMechanism(\"PLAIN,0);                    connection.connect();                    connection.login(chatLogin,密码);                            MultiUserChat睦=新MultiUserChat(联系,组ID _+组名+@ muc.chat.quickblox.com);                           // INT的appid = context.getResources()getInteger(R.integer.QuickBoxid)。                           // Log.i(TAG QUICKID,QUICKBOX检查身份证直接+的appid);                            muc.create(qucikusername);                            //muc.create(appid+\"_\"+groupName);                           // muc.sendConfigurationForm(新表格(Form.TYPE_SUBMIT));
                }赶上(XMPPException E){                    e.printStackTrace();                }
            }
        })。开始();
    }
//为听者群聊    私人PacketListener groupchatManagerListener =新PacketListener(){
        @覆盖
        公共无效processPacket(分组数据包){            如果(onMessageReceivedListener!= NULL){                onMessageReceivedListener.onGroupMessageReceived(包);
            }        }
    };

//这里发送群消息

 公共无效sendGroupMessage(字符串消息){        尝试{            如果(MUC!= NULL)
            {
                muc.sendMessage(消息);
            }        }赶上(XMPPException xmppe){            xmppe.printStackTrace();
        }
    }   / *公共无效的sendMessage(字符串消息){
        尝试{onMessageReceivedListener
            如果(聊天!= NULL){
                chat.sendMessage(消息);
            }
        }赶上(XMPPException E){
            e.printStackTrace();
        }
    } * /   / *私人消息监听消息监听=新的MessageListener(){
        @覆盖
        公共无效而processMessage(聊天,留言消息){
            //从和到字段包含发件人的ID,例如
            // 17792-1028@chat.quickblox.com/mac-167
            // 17744-1028@chat.quickblox.com/Smack
            从= message.getFrom()分裂(@)的String [0];
            字符串= message.getTo()分裂(@)[0]。            的System.out.println(的String.format(>>>接收到的信息(从=%s为止,=%S):%S,
                    从到,message.getBody()));            如果(onMessageReceivedListener!= NULL){
                onMessageReceivedListener.onMessageReceived(消息);
            }
        }
    }; * /    公共静态界面OnGroupMessageReceivedListener {
        无效onGroupMessageReceived(分组数据包);
    }    私人OnGroupMessageReceivedListener onMessageReceivedListener;    公共OnGroupMessageReceivedListener getOnMessageReceivedListener(){        返回onMessageReceivedListener;    }    公共无效setOnMessageReceivedListener(OnGroupMessageReceivedListener onMessageReceivedListener){        this.onMessageReceivedListener = onMessageReceivedListener;    }    //回调时,设备检索传入消息执行。
  / *私人OnMessageReceivedListener onMessageReceivedListener;    公共OnMessageReceivedListener getOnMessageReceivedListener(){
        返回onMessageReceivedListener;
    }    公共无效setOnMessageReceivedListener(OnMessageReceivedListener onMessageReceivedListener){
        this.onMessageReceivedListener = onMessageReceivedListener;
    } * /
}


解决方案

有连接成功后,检查用户进行身份验证(指记录或没有)。
所以采用这种

  connection.isAuthenticated();

配置MUC前...

at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:341)

at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:204)

at org.jivesoftware.smack.Connection.login(Connection.java:357)

// This is my code...

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.muc.DiscussionHistory;
import org.jivesoftware.smackx.muc.MultiUserChat;

import android.content.Context;
import android.util.Log;

import com.quickblox.module.chat.QBChat;



public class GroupChatController {

    // ================= QuickBlox ===== Step 8 =================
    // Get QuickBlox chat server domain.
    // There will be created connection with chat server below.
    public static final String CHAT_SERVER = QBChat.getChatServerDomain();

    private XMPPConnection connection;

    private ConnectionConfiguration config;
    private Chat groupChat;

    private String chatLogin;
    private String password;
    private String groupName;

    private String passgroupName;

    Context context;



    private String quickusername;

    private ChatManager chatManager;

  //  private boolean isGroupchat;

    MultiUserChat muc;

    public GroupChatController(String chatLogin, String password) {

        this.chatLogin = chatLogin;

        this.password = password;
    }

//Here My Groupchat start

    public void startChat(final String groupName) {

        this.groupName = groupName;


       // this.isGroupchat = isGroup;

        new Thread(new Runnable() {
            @Override
            public void run() {
                // Chat action 1 -- create connection.

                Connection.DEBUG_ENABLED = true;

                config = new ConnectionConfiguration(CHAT_SERVER);

                connection = new XMPPConnection(config);

                try 
                {

                //Here is showing error connections

                    connection.connect();

                    connection.login(chatLogin, password);

                        //boolean supports = MultiUserChat.isServiceEnabled(connection, chatLogin+"@muc.chat.quickblox.com");

                           // Example 416_sedin@muc.chat.quickblox.com

                            muc = new MultiUserChat(connection,groupName+"@muc.chat.quickblox.com");

                            DiscussionHistory history = new DiscussionHistory();

                            history.setMaxStanzas(3);

                            muc.join(chatLogin, password, history, SmackConfiguration.getPacketReplyTimeout());

                            muc.addMessageListener(groupchatManagerListener);                           


                } catch (XMPPException e) {

                    e.printStackTrace();

                }/*catch (Exception e) {
                    // TODO: handle exception
                }*/
                }



        }).start();
    }

//Create Mygroup

 public void createGroupChat(final String groupName,final String qucikusername) {

        this.passgroupName = groupName;

        this.quickusername=qucikusername;

       // this.isGroupchat = isGroup;

        new Thread(new Runnable() {
            @Override
            public void run() {
                // Chat action 1 -- create connection.

                Connection.DEBUG_ENABLED = true;

                config = new ConnectionConfiguration(CHAT_SERVER);

                connection = new XMPPConnection(config);

                try 

                {

                    //SASLAuthentication.supportSASLMechanism("PLAIN", 0);

                    connection.connect();

                    connection.login(chatLogin, password);

                            MultiUserChat muc = new MultiUserChat(connection,"groupid_"+groupName+"@muc.chat.quickblox.com");

                           // int appid= context.getResources().getInteger(R.integer.QuickBoxid);

                           // Log.i("TAG QUICKID", "QUICKBOX ID CHECK direct"+appid);

                            muc.create(qucikusername);

                            //muc.create(appid+"_"+groupName);

                           // muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));       


                } catch (XMPPException e) {

                    e.printStackTrace();

                }
            }
        }).start();
    }


//Listner for groupchat   

    private PacketListener groupchatManagerListener = new PacketListener() {


        @Override
        public void processPacket(Packet packet) {

            if (onMessageReceivedListener != null) {

                onMessageReceivedListener.onGroupMessageReceived(packet);
            }    

        }
    };

//Here sending group messages

    public void sendGroupMessage(String message) {

        try {

            if(muc!=null)
            {               
                muc.sendMessage(message);
            }

        }catch(XMPPException xmppe) {

            xmppe.printStackTrace();
        }


    }

   /* public void sendMessage(String message) {
        try {onMessageReceivedListener
            if (chat != null) {
                chat.sendMessage(message);
            }
        } catch (XMPPException e) {
            e.printStackTrace();
        }
    }*/

   /* private MessageListener messageListener = new MessageListener() {
        @Override
        public void processMessage(Chat chat, Message message) {
            // 'from' and 'to' fields contains senders ids, e.g.
            // 17792-1028@chat.quickblox.com/mac-167
            // 17744-1028@chat.quickblox.com/Smack
            String from = message.getFrom().split("@")[0];
            String to = message.getTo().split("@")[0];



            System.out.println(String.format(">>> Message received (from=%s, to=%s): %s",
                    from, to, message.getBody()));

            if (onMessageReceivedListener != null) {
                onMessageReceivedListener.onMessageReceived(message);
            }
        }
    };*/

    public static interface OnGroupMessageReceivedListener {
        void onGroupMessageReceived(Packet packet);
    }    

    private OnGroupMessageReceivedListener onMessageReceivedListener;

    public OnGroupMessageReceivedListener getOnMessageReceivedListener() {

        return onMessageReceivedListener;

    }

    public void setOnMessageReceivedListener(OnGroupMessageReceivedListener onMessageReceivedListener) {

        this.onMessageReceivedListener = onMessageReceivedListener;

    }

    // Callback that performs when device retrieves incoming message.
  /*  private OnMessageReceivedListener onMessageReceivedListener;

    public OnMessageReceivedListener getOnMessageReceivedListener() {
        return onMessageReceivedListener;
    }

    public void setOnMessageReceivedListener(OnMessageReceivedListener onMessageReceivedListener) {
        this.onMessageReceivedListener = onMessageReceivedListener;
    }*/
}

解决方案

After having successful connection, check that user is authenticated (means logging or not). So use this

connection.isAuthenticated();

before configuring MUC...

这篇关于使用机制平原GROUPCHAT SASL身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆