【发布时间】:2013-12-20 20:38:40
【问题描述】:
我正在处理使用 java 在 ejabberd 中实现外部身份验证的任务。
我在网上搜索了示例,找到了 PHP、Perl、Python 中的示例,但在 java 中找不到任何示例。
我知道需要在“ejabberd.cfg”文件中进行的配置。
java 中的任何代码示例都会很有帮助。
【问题讨论】:
-
ejabberd.yml 中运行 java 类文件需要什么配置?我无法让它工作
我正在处理使用 java 在 ejabberd 中实现外部身份验证的任务。
我在网上搜索了示例,找到了 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");
}
}
【讨论】: