本文整理汇总了Java中javax.security.sasl.SaslClient.hasInitialResponse方法的典型用法代码示例。如果您正苦于以下问题:Java SaslClient.hasInitialResponse方法的具体用法?Java SaslClient.hasInitialResponse怎么用?Java SaslClient.hasInitialResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.security.sasl.SaslClient
的用法示例。
在下文中一共展示了SaslClient.hasInitialResponse方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initiate
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
public void initiate(final String mechanismName) {
logger.trace("Initiating SASL exchange.");
try {
final ByteString responseData;
final SaslClient saslClient = connection.getSaslClient();
if (saslClient.hasInitialResponse()) {
responseData = ByteString.copyFrom(evaluateChallenge(ugi, saslClient, new byte[0]));
} else {
responseData = ByteString.EMPTY;
}
client.send(new AuthenticationOutcomeListener<>(client, connection, saslRpcType, ugi, completionListener),
connection,
saslRpcType,
SaslMessage.newBuilder()
.setMechanism(mechanismName)
.setStatus(SaslStatus.SASL_START)
.setData(responseData)
.build(),
SaslMessage.class,
true /* the connection will not be backed up at this point */);
logger.trace("Initiated SASL exchange.");
} catch (final Exception e) {
completionListener.failed(RpcException.mapException(e));
}
}
示例2: handleSaslStartMessage
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
/**
* Performs the client side of the initial portion of the Thrift SASL
* protocol. Generates and sends the initial response to the server, including
* which mechanism this client wants to use.
*/
@Override
protected void handleSaslStartMessage() throws TTransportException, SaslException {
SaslClient saslClient = getSaslClient();
byte[] initialResponse = new byte[0];
if (saslClient.hasInitialResponse())
initialResponse = saslClient.evaluateChallenge(initialResponse);
LOGGER.debug("Sending mechanism name {} and initial response of length {}", mechanism,
initialResponse.length);
byte[] mechanismBytes = mechanism.getBytes();
sendSaslMessage(NegotiationStatus.START,
mechanismBytes);
// Send initial response
sendSaslMessage(saslClient.isComplete() ? NegotiationStatus.COMPLETE : NegotiationStatus.OK,
initialResponse);
underlyingTransport.flush();
}
示例3: startAuthentication
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
/**
* Starts to authenticate the user with the specified credentials.
*
* @param credentials
* The credentials to use to login to the database.
* @param connection
* The connection to authenticate the user with.
* @throws MongoDbAuthenticationException
* On a failure in the protocol to authenticate the user on the
* connection.
*/
public void startAuthentication(final Credential credentials,
final Connection connection) throws MongoDbAuthenticationException {
try {
final SaslClient client = createSaslClient(credentials, connection);
if (client != null) {
byte[] payload = EMPTY_BYTES;
if (client.hasInitialResponse()) {
payload = client.evaluateChallenge(payload);
}
sendStart(payload, connection, new SaslResponseCallback(client,
connection, myResults));
}
else {
throw new MongoDbAuthenticationException(
"Could not locate a SASL provider.");
}
}
catch (final SaslException e) {
throw new MongoDbAuthenticationException(e);
}
}
示例4: testSaslServerClient
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
private void testSaslServerClient(SaslServer server, SaslClient client) throws SaslException {
byte[] message = new byte[]{};
if (client.hasInitialResponse()) message = client.evaluateChallenge(message);
while(!server.isComplete() || !client.isComplete()) {
if (!server.isComplete()) message = server.evaluateResponse(message);
if (!client.isComplete()) message = client.evaluateChallenge(message);
}
}
示例5: buildResponse
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
@Override
protected byte[] buildResponse(SaslClient sc) throws SaslException {
return sc.hasInitialResponse() ?
sc.evaluateChallenge(challenge)
: EMPTY_BYTES;
}
示例6: 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();
}
示例7: run
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
public void run() throws Exception {
System.out.println("Host:" + host + " port: "
+ port);
try (SaslEndpoint endpoint = SaslEndpoint.create(host, port)) {
negotiateMechanism(endpoint);
SaslClient client = createSaslClient();
byte[] data = new byte[0];
if (client.hasInitialResponse()) {
data = client.evaluateChallenge(data);
}
endpoint.send(new Message(SaslStatus.CONTINUE, data));
Message msg = getMessage(endpoint.receive());
while (!client.isComplete()
&& msg.getStatus() != SaslStatus.FAILURE) {
switch (msg.getStatus()) {
case CONTINUE:
System.out.println("client continues");
data = client.evaluateChallenge(msg.getData());
endpoint.send(new Message(SaslStatus.CONTINUE,
data));
msg = getMessage(endpoint.receive());
break;
case SUCCESS:
System.out.println("client succeeded");
data = client.evaluateChallenge(msg.getData());
if (data != null) {
throw new SaslException("data should be null");
}
break;
default:
throw new RuntimeException("Wrong status:"
+ msg.getStatus());
}
}
if (msg.getStatus() == SaslStatus.FAILURE) {
throw new RuntimeException("Status is FAILURE");
}
}
System.out.println("Done");
}
示例8: main
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length == 0) {
pwfile = "pw.properties";
namesfile = "names.properties";
auto = true;
} else {
int i = 0;
if (args[i].equals("-m")) {
i++;
auto = false;
}
if (args.length > i) {
pwfile = args[i++];
if (args.length > i) {
namesfile = args[i++];
}
} else {
pwfile = "pw.properties";
namesfile = "names.properties";
}
}
CallbackHandler clntCbh = new ClientCallbackHandler(auto);
CallbackHandler srvCbh =
new PropertiesFileCallbackHandler(pwfile, namesfile, null);
SaslClient clnt = Sasl.createSaslClient(
new String[]{MECH}, null, PROTOCOL, SERVER_FQDN, null, clntCbh);
SaslServer srv = Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN, null,
srvCbh);
if (clnt == null) {
throw new IllegalStateException(
"Unable to find client impl for " + MECH);
}
if (srv == null) {
throw new IllegalStateException(
"Unable to find server impl for " + MECH);
}
byte[] response = (clnt.hasInitialResponse()?
clnt.evaluateChallenge(EMPTY) : EMPTY);
byte[] challenge;
while (!clnt.isComplete() || !srv.isComplete()) {
challenge = srv.evaluateResponse(response);
if (challenge != null) {
response = clnt.evaluateChallenge(challenge);
}
}
if (clnt.isComplete() && srv.isComplete()) {
if (verbose) {
System.out.println("SUCCESS");
System.out.println("authzid is " + srv.getAuthorizationID());
}
} else {
throw new IllegalStateException("FAILURE: mismatched state:" +
" client complete? " + clnt.isComplete() +
" server complete? " + srv.isComplete());
}
}
示例9: 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;
}
示例10: buildResponse
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
@Override
protected byte[] buildResponse(SaslClient sc) throws SaslException {
return sc.hasInitialResponse() ? sc.evaluateChallenge(challenge)
: EMPTY_BYTES;
}
示例11: connectionStart
import javax.security.sasl.SaslClient; //导入方法依赖的package包/类
@Override
public void connectionStart(Connection conn, ConnectionStart start)
{
Map<String,Object> clientProperties = new HashMap<String,Object>();
if(this.conSettings.getClientProperties() != null)
{
clientProperties.putAll(this.conSettings.getClientProperties());
}
clientProperties.put("qpid.session_flow", 1);
clientProperties.put("qpid.client_pid",getPID());
clientProperties.put("qpid.client_process",
System.getProperty("qpid.client_process","Qpid Java Client"));
List<Object> brokerMechs = start.getMechanisms();
if (brokerMechs == null || brokerMechs.isEmpty())
{
conn.connectionStartOk
(clientProperties, null, null, conn.getLocale());
return;
}
List<String> choosenMechs = new ArrayList<String>();
for (String mech:clientMechs)
{
if (brokerMechs.contains(mech))
{
choosenMechs.add(mech);
}
}
if (choosenMechs.size() == 0)
{
conn.exception(new ConnectionException("The following SASL mechanisms " +
clientMechs.toString() +
" specified by the client are not supported by the broker"));
return;
}
String[] mechs = new String[choosenMechs.size()];
choosenMechs.toArray(mechs);
conn.setServerProperties(start.getServerProperties());
try
{
Map<String,Object> saslProps = new HashMap<String,Object>();
if (conSettings.isUseSASLEncryption())
{
saslProps.put(Sasl.QOP, "auth-conf");
}
UsernamePasswordCallbackHandler handler =
new UsernamePasswordCallbackHandler();
handler.initialise(conSettings.getUsername(), conSettings.getPassword());
SaslClient sc = Sasl.createSaslClient
(mechs, null, conSettings.getSaslProtocol(), conSettings.getSaslServerName(), saslProps, handler);
conn.setSaslClient(sc);
byte[] response = sc.hasInitialResponse() ?
sc.evaluateChallenge(new byte[0]) : null;
conn.connectionStartOk
(clientProperties, sc.getMechanismName(), response,
conn.getLocale());
}
catch (SaslException e)
{
conn.exception(e);
}
}