本文整理汇总了Java中javax.security.sasl.SaslClient.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java SaslClient.dispose方法的具体用法?Java SaslClient.dispose怎么用?Java SaslClient.dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.security.sasl.SaslClient
的用法示例。
在下文中一共展示了SaslClient.dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: destroy
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
@Override
public void destroy() {
for (SaslClient saslClient : saslClients) {
try {
saslClient.dispose();
} catch (SaslException e) {
// ignore
}
}
}
示例2: safeDispose
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
static void safeDispose(SaslClient saslClient) {
try {
saslClient.dispose();
} catch (SaslException e) {
LOG.error("Error disposing of SASL client", e);
}
}
示例3: main
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Map<String, String> props = new TreeMap<String, String>();
props.put(Sasl.QOP, "auth");
// client
SaslClient client = Sasl.createSaslClient(new String[]{ DIGEST_MD5 },
"user1", "xmpp", "127.0.0.1", props, authCallbackHandler);
if (client == null) {
throw new Exception("Unable to find client implementation for: " +
DIGEST_MD5);
}
byte[] response = client.hasInitialResponse()
? client.evaluateChallenge(EMPTY) : EMPTY;
logger.info("initial: " + new String(response));
// server
byte[] challenge = null;
SaslServer server = Sasl.createSaslServer(DIGEST_MD5, "xmpp",
"127.0.0.1", props, authCallbackHandler);
if (server == null) {
throw new Exception("Unable to find server implementation for: " +
DIGEST_MD5);
}
if (!client.isComplete() || !server.isComplete()) {
challenge = server.evaluateResponse(response);
logger.info("challenge: " + new String(challenge));
if (challenge != null) {
response = client.evaluateChallenge(challenge);
}
}
String challengeString = new String(challenge, "UTF-8").toLowerCase();
if (challengeString.indexOf("\"md5-sess\"") > 0 ||
challengeString.indexOf("\"utf-8\"") > 0) {
throw new Exception("The challenge string's charset and " +
"algorithm values must not be enclosed within quotes");
}
client.dispose();
server.dispose();
}
示例4: authenticate
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
@Override
public void authenticate(Socket sock, String hostName) throws IOException {
if (!quorumRequireSasl) { // let it through, we don't require auth
LOG.info("Skipping SASL authentication as {}={}",
QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED,
quorumRequireSasl);
return;
}
SaslClient sc = null;
String principalConfig = SecurityUtils
.getServerPrincipal(quorumServicePrincipal, hostName);
try {
DataOutputStream dout = new DataOutputStream(
sock.getOutputStream());
DataInputStream din = new DataInputStream(sock.getInputStream());
byte[] responseToken = new byte[0];
sc = SecurityUtils.createSaslClient(learnerLogin.getSubject(),
principalConfig,
QuorumAuth.QUORUM_SERVER_PROTOCOL_NAME,
QuorumAuth.QUORUM_SERVER_SASL_DIGEST, LOG, "QuorumLearner");
if (sc.hasInitialResponse()) {
responseToken = createSaslToken(new byte[0], sc, learnerLogin);
}
send(dout, responseToken);
QuorumAuthPacket authPacket = receive(din);
QuorumAuth.Status qpStatus = QuorumAuth.Status
.getStatus(authPacket.getStatus());
while (!sc.isComplete()) {
switch (qpStatus) {
case SUCCESS:
responseToken = createSaslToken(authPacket.getToken(), sc,
learnerLogin);
// we're done; don't expect to send another BIND
if (responseToken != null) {
throw new SaslException(
"Protocol error: attempting to send response after completion"
+ ". Server addr: "
+ sock.getRemoteSocketAddress());
}
break;
case IN_PROGRESS:
responseToken = createSaslToken(authPacket.getToken(), sc,
learnerLogin);
send(dout, responseToken);
authPacket = receive(din);
qpStatus = QuorumAuth.Status
.getStatus(authPacket.getStatus());
break;
case ERROR:
throw new SaslException(
"Authentication failed against server addr: "
+ sock.getRemoteSocketAddress());
default:
LOG.warn("Unknown status:{}!", qpStatus);
throw new SaslException(
"Authentication failed against server addr: "
+ sock.getRemoteSocketAddress());
}
}
// Validate status code at the end of authentication exchange.
checkAuthStatus(sock, qpStatus);
} finally {
if (sc != null) {
try {
sc.dispose();
} catch (SaslException e) {
LOG.error("SaslClient dispose() failed", e);
}
}
}
return;
}