openfire登陆及密码验证过程
来源:互联网 发布:淘宝卖潮牌的店 编辑:程序博客网 时间:2024/06/01 10:16
QQ: 277869380. 因为sina博客改版后xml字符无法正常显示。现在把sina博客上的内容迁移过来
本文有点乱,是我在openfire开发过程中随手写下来的
openfire支持多种方式的登陆, 包括TLS安全登陆和多种账号密码验证方式。
openfire的密码获取和设置部分由authProvider(DefaultAuthProvider)完成。
authProvider.getPassword(username.toLowerCase()); 从数据库中获取密码并解密。
openfire使用Blowfish对明文密码进行加密。它是一种对称密钥的分组密码,使用32位至448位的可变长度密钥,应用于内部加密或加密输出。openfire首先通过lCBCIV = m_rndGen.nextLong();对每一个明文密码产生一个随机数lCBCIV(8字节),然后使用这个随机数(64位密钥)来加密明文密码,最后一起存放在数据库表ofuser内。
openfire非常灵活,在实际项目中可以在配置文件(ofproperty表)中修改authProvider,加入自己的密码验证方
式。
登陆密码验证由StazaHandler的
("auth".equals(tag)) {
// User is trying to authenticate using SASL
startedSASL = true;
// Process authentication stanza
saslStatus = SASLAuthentication.handle(session, doc);
处理。
最简单的当属PLAIN方式(base64编码)
SASLAuthentication 解码base64码
token = StringUtils.decodeBase64(doc.getText().trim());
SaslServerPlainImpl PLAIN码的验证
public byte[] evaluateResponse(byte[] response)
throws SaslException {
if (completed) {
throw new IllegalStateException("PLAIN authentication already completed");
}
if (aborted) {
throw new IllegalStateException("PLAIN authentication previously aborted due to error");
}
try {
if(response.length != 0) {
String data = new String(response, "UTF8");
StringTokenizer tokens = new StringTokenizer(data, "");
if (tokens.countTokens() > 2) {
username = tokens.nextToken();
principal = tokens.nextToken();
} else {