©
本文档使用
php.cn手册 发布
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
上一个类 下一个类 | 框架 无框架 | |||||||||
摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 |
1 |
|
以客户端的身份执行 SASL 验证。
为了执行具体 SASL 机制所定义的验证,协议库(例如用于 LDAP 的库)要获得此类的一个实例。调用 SaslClient 实例的方法可处理 challenge,并创建与 SaslClient 所实现的 SASL 机制相对应的响应。随着验证的进行,该实例会封装 SASL 客户端的验证交换状态。
以下是 LDAP 库如何使用 SaslClient 的一个示例。它首先获得 SaslClient 的一个实例:
然后它可继续使用该客户端进行验证。例如,LDAP 库可能按如下方式使用该客户端:
1
2
SaslClient sc = Sasl.createSaslClient(mechanisms,
authorizationId, protocol, serverName, props, callbackHandler);
如果该机制有初始响应,则库可调用带有空 challenge 的 evaluateChallenge() 来获得该初始响应。诸如 IMAP4 等此类协议在其送往服务器的第一个验证命令中不包括初始响应,所以可无需首先调用 hasInitialResponse() 或 evaluateChallenge() 即可发起验证。当服务器响应该命令时,它会发送初始 challenge。对于客户端首先发送数据的 SASL 机制而言,服务器应该发出一个没有数据的 challenge。然后,这会导致带有空 challenge 的 evaluateChallenge() 调用(在客户端上)。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Get initial response and send to server
byte[] response = (sc.hasInitialResponse() ? sc.evaluateChallenge(
new
byte[0]) :
null);
LdapResult res = ldap.sendBindRequest(dn, sc.getName(), response);
while
(!sc.isComplete() &&
(res.status == SASL_BIND_IN_PROGRESS || res.status == SUCCESS)) {
response = sc.evaluateChallenge(res.getBytes());
if
(res.status == SUCCESS) {
// we're done; don't expect to send another BIND
if
(response != null) {
throw
new
SaslException(
"Protocol error: attempting to send response after completion"
);
}
break
;
}
res = ldap.sendBindRequest(dn, sc.getName(), response);
}
if
(sc.isComplete() && res.status == SUCCESS) {
String qop = (String) sc.getNegotiatedProperty(Sasl.QOP);
if
(qop != null
&& (qop.equalsIgnoreCase(
"auth-int"
)
|| qop.equalsIgnoreCase(
"auth-conf"
))) {
// Use SaslClient.wrap() and SaslClient.unwrap() for future
// communication with server
ldap.in =
new
SecureInputStream(sc, ldap.in);
ldap.out =
new
SecureOutputStream(sc, ldap.out);
}
}
Sasl
,
SaslClientFactory
方法摘要 | |
---|---|
void |
dispose()
处置 SaslClient 可能使用的所有系统资源或安全敏感信息。 |
byte[] |
evaluateChallenge(byte[] challenge)
评估 challenge 数据并生成一个响应。 |
String |
getMechanismName()
返回此 SASL 客户端的 IANA 注册机制名。 |
Object |
getNegotiatedProperty(String propName)
获取已协商的属性。 |
boolean |
hasInitialResponse()
确定此机制是否具有可选的初始响应。 |
boolean |
isComplete()
确定验证交换是否已完成。 |
byte[] |
unwrap(byte[] incoming,
int offset,
int len)
解包接收自服务器的 byte 数组。 |
byte[] |
wrap(byte[] outgoing,
int offset,
int len)
包装要发送到服务器的 byte 数组。 |
方法详细信息 |
---|
1 |
|
1 |
|
1 2 |
|
challenge
- 服务器发送的非 null challenge。该 challenge 数组的长度可以为零。
SaslException
- 如果处理 challenge 或生成响应时发生错误。1 |
|
1 2 3 4 |
|
incoming 是 SASL 缓冲区的内容(在 RFC 2222 中定义),没有表示长度的前导 4 个八位组字段。offset 和 len 指定了要使用的 incoming 部分。
incoming
- 非 null 的 byte 数组,包含取自服务器的已编码字节。offset
- 所用字节在 incoming 中的开始位置。len
- 要使用的 incoming 中的字节数。
SaslException
- 如果无法成功解包 incoming。
IllegalStateException
- 如果验证交换未完成,如果协商的保护级别既没有完整性,也没有机密性。1 2 3 4 |
|
此方法的结果会组成 SASL 缓冲区的内容(在 RFC 2222 中定义),没有表示长度的前导 4 个八位组字段。offset 和 len 指定了要使用的 outgoing 部分。
outgoing
- 非 null 的 byte 数组,包含要编码的字节。offset
- 所用字节在 outgoing 中的开始位置。len
- 要使用的 outgoing 中的字节数。
SaslException
- 如果无法成功包装 outgoing。
IllegalStateException
- 如果验证交换未完成,如果协商的保护级别既没有完整性,也没有机密性。1 |
|
propName
- 非 null 的属性名。
IllegalStateException
- 如果未完成此验证交换。1 2 |
|
SaslException
- 如果释放资源时遇到问题。
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
上一个类 下一个类 | 框架 无框架 | |||||||||
摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 |
版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。