我正在研究使用Java在ejabberd中实现外部身份验证的任务。

我在Internet上搜索了示例,并在PHP,Perl,Python中找到了示例,但在Java中找不到任何示例。

我知道在'ejabberd.cfg'文件中需要进行的配置。

Java中的任何代码示例都将非常有帮助。

最佳答案

尝试这个:

public static void main(String[] args) {
    try {

        outerloop: while (true) {
            byte[] lB = new byte[2];

            int startPos = 0;

            while (startPos < lB.length) {

                int ret = System.in.read(lB, startPos,
                        (lB.length - startPos));

                if (ret < 0) {

                    break outerloop;
                }
                startPos += ret;
            }

            int streamLen = System.in.available();

            byte[] rd = new byte[streamLen];

            startPos = 0;

            while (startPos < streamLen) {

                int ret = System.in.read(rd, startPos,
                        (streamLen - startPos));
                if (ret < 0) {

                    break outerloop;
                }
                startPos += ret;
            }

            String inputArgs = new String(rd, "ASCII");

            String[] arguments = inputArgs.split(":");

            String userName = arguments[1];
            String password = arguments[3];
            //
            // Here do the authentication
            //

            boolean resultOfAuthentication = // Result of Authentication;

            byte[] res = new byte[4];
            res[0] = 0;
            res[1] = 2;
            res[2] = 0;

            if (resultOfAuthentication) {
                res[3] = 1;
            } else {
                res[3] = 0;
            }
            System.out.write(res, 0, res.length);
            System.out.flush();
        }
    } catch (Exception e) {
        System.out.println("ERROR");

    }

}

10-05 22:12
查看更多