public interface SaslServer
LDAP服务器等服务器获取此类的实例,以执行由特定SASL机制定义的认证。 SaslServer实例上的调用方法根据SaslServer实现的SASL机制产生SaslServer 。 当认证进行时,该实例封装了SASL服务器的认证交换的状态。
以下是LDAP服务器如何使用SaslServer 。 它首先获得客户端请求的SASL机制的一个SaslServer的实例:
SaslServer ss = Sasl.createSaslServer(mechanism,
"ldap", myFQDN, props, callbackHandler);
然后可以继续使用服务器进行身份验证。
例如,假设LDAP服务器收到包含SASL机制的名称和(可选)初始响应的LDAP BIND请求。
然后可以使用服务器,如下所示:
while (!ss.isComplete()) { try { byte[] challenge = ss.evaluateResponse(response); if (ss.isComplete()) { status = ldap.sendBindResponse(mechanism, challenge, SUCCESS); } else { status = ldap.sendBindResponse(mechanism, challenge, SASL_BIND_IN_PROGRESS); response = ldap.readBindRequest(); } } catch (SaslException e) { status = ldap.sendErrorResponse(e); break; } } if (ss.isComplete() && status == SUCCESS) { String qop = (String) sc.getNegotiatedProperty(Sasl.QOP); if (qop != null && (qop.equalsIgnoreCase("auth-int") || qop.equalsIgnoreCase("auth-conf"))) { // Use SaslServer.wrap() and SaslServer.unwrap() for future // communication with client ldap.in = new SecureInputStream(ss, ldap.in); ldap.out = new SecureOutputStream(ss, ldap.out); } }
Sasl , SaslServerFactory
| Modifier and Type | Method and Description |
|---|---|
void |
dispose()
处理SaslServer可能使用的任何系统资源或安全敏感信息。
|
byte[] |
evaluateResponse(byte[] response)
评估响应数据并产生挑战。
|
String |
getAuthorizationID()
报告此会话客户端的授权ID。
|
String |
getMechanismName()
返回该SASL服务器的IANA注册的机制名称。
|
Object |
getNegotiatedProperty(String propName)
检索谈判的财产。
|
boolean |
isComplete()
确定认证交换是否已完成。
|
byte[] |
unwrap(byte[] incoming, int offset, int len)
解开从客户端接收的字节数组。
|
byte[] |
wrap(byte[] outgoing, int offset, int len)
包装要发送给客户端的字节数组。
|
String getMechanismName()
byte[] evaluateResponse(byte[] response)
throws SaslException
isComplete()应该每次调用之后调用evaluateResponse() ,以确定是否从所述客户端所需要的任何进一步的反应。
response - 客户端发送的非空(但可能为空)响应。
SaslException - 如果在处理响应或产生挑战时发生错误。
boolean isComplete()
evaluateResponse() ,确定认证是否已成功完成,还是应该继续下去。
String getAuthorizationID()
IllegalStateException - 如果此验证会话尚未完成
byte[] unwrap(byte[] incoming,
int offset,
int len)
throws SaslException
isComplete()返回true时),并且只有认证交换协商完整性和/或隐私作为保护质量,才可以调用此方法。
否则,抛出一个IllegalStateException 。
incoming是RFC 2222中定义的SASL缓冲区的内容,没有表示长度的前四个八位字节字段。 offset和len指定要使用的部分incoming 。
incoming - 包含客户端编码字节的非空字节数组。
offset - 起始位置在
incoming的字节使用。
len - 从
incoming使用的字节数。
SaslException - 如果
incoming无法成功解包。
IllegalStateException - 如果验证交换尚未完成,或者协商的保护质量既不完整也不具有隐私
byte[] wrap(byte[] outgoing,
int offset,
int len)
throws SaslException
isComplete()返回true时),并且只有认证交换协商完整性和/或隐私作为保护质量,才能调用此方法。
否则,抛出一个SaslException 。
该方法的结果将构成RFC 2222中定义的SASL缓冲区的内容,而不包含表示长度的前导四个八位字节字段。 offset和len指定要使用的部分outgoing 。
outgoing - 包含要编码的字节的非空字节数组。
offset - 起始位置在
outgoing的字节使用。
len - 从
outgoing使用的字节数。
SaslException - 如果
outgoing无法成功包装。
IllegalStateException - 如果认证交换尚未完成,或者协商的保护质量既不完整也不具有隐私。
Object getNegotiatedProperty(String propName)
isComplete()返回true时)。
否则,抛出IllegalStateException 。
propName - 该物业
IllegalStateException - 如果此认证交换尚未完成
void dispose()
throws SaslException
SaslException - 处理资源时遇到问题。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.