本文整理汇总了Java中org.apache.qpid.proton.engine.Sasl.client方法的典型用法代码示例。如果您正苦于以下问题:Java Sasl.client方法的具体用法?Java Sasl.client怎么用?Java Sasl.client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.qpid.proton.engine.Sasl
的用法示例。
在下文中一共展示了Sasl.client方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.qpid.proton.engine.Sasl; //导入方法依赖的package包/类
void init() throws NetworkException
{
synchronized (_lock)
{
_collector = Collector.Factory.create();
_transport = Transport.Factory.create();
_connection = Connection.Factory.create();
String id = _settings.getId();
_connection.collect(_collector);
_connection.setContainer(id == null || id.trim().equals("") ? UUID.randomUUID().toString() : id);
_connection.setHostname(_settings.getHost());
_transport.bind(_connection);
Sasl sasl = _transport.sasl();
sasl.client();
sasl.setMechanisms(new String[] { "ANONYMOUS" });
_connection.open();
_connected.set(true);
write();
}
}
示例2: makeTransport
import org.apache.qpid.proton.engine.Sasl; //导入方法依赖的package包/类
private static Transport makeTransport(Connection conn) {
Transport transport = Transport.Factory.create();
Sasl sasl = transport.sasl();
sasl.setMechanisms("ANONYMOUS");
sasl.client();
transport.bind(conn);
return transport;
}
示例3: handleOpen
import org.apache.qpid.proton.engine.Sasl; //导入方法依赖的package包/类
private void handleOpen(Reactor reactor, Event event) {
Connection connection = event.getConnection();
if (connection.getRemoteState() != EndpointState.UNINITIALIZED) {
return;
}
// Outgoing Reactor connections set the virtual host automatically using the
// following rules:
String vhost = connection.getHostname();
if (vhost == null) {
// setHostname never called, use the host from the connection's
// socket address as the default virtual host:
String conAddr = reactor.getConnectionAddress(connection);
if (conAddr != null) {
Address addr = new Address(conAddr);
connection.setHostname(addr.getHost());
}
} else if (vhost.isEmpty()) {
// setHostname called explictly with a null string. This allows
// the application to completely avoid sending a virtual host
// name
connection.setHostname(null);
} else {
// setHostname set by application - use it.
}
Transport transport = Proton.transport();
int maxFrameSizeOption = reactor.getOptions().getMaxFrameSize();
if (maxFrameSizeOption != 0) {
transport.setMaxFrameSize(maxFrameSizeOption);
}
if (reactor.getOptions().isEnableSaslByDefault()) {
Sasl sasl = transport.sasl();
sasl.client();
sasl.setMechanisms("ANONYMOUS");
}
transport.bind(connection);
}
示例4: testOptionalChallengeResponseStepOmitted
import org.apache.qpid.proton.engine.Sasl; //导入方法依赖的package包/类
/** 5.3.2 SASL Negotiation. ...challenge/response step can occur zero or more times*/
@Test
public void testOptionalChallengeResponseStepOmitted() throws Exception
{
getClient().transport = Proton.transport();
getServer().transport = Proton.transport();
Sasl clientSasl = getClient().transport.sasl();
clientSasl.client();
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
Sasl serverSasl = getServer().transport.sasl();
serverSasl.server();
serverSasl.setMechanisms(TESTMECH1);
assertEquals("Server should not yet know the remote's chosen mechanism.",
0,
serverSasl.getRemoteMechanisms().length);
pumpClientToServer();
pumpServerToClient();
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
clientSasl.setMechanisms(TESTMECH1);
pumpClientToServer();
serverSasl.done(SaslOutcome.PN_SASL_OK);
pumpServerToClient();
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_OK, clientSasl.getOutcome());
}
示例5: testAuthenticationFails
import org.apache.qpid.proton.engine.Sasl; //导入方法依赖的package包/类
/**
* 5.3.3.6 Connection authentication failed due to an unspecified problem with the supplied credentials.
*/
@Test
public void testAuthenticationFails() throws Exception
{
getClient().transport = Proton.transport();
getServer().transport = Proton.transport();
Sasl clientSasl = getClient().transport.sasl();
clientSasl.client();
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
Sasl serverSasl = getServer().transport.sasl();
serverSasl.server();
serverSasl.setMechanisms(TESTMECH1);
pumpClientToServer();
pumpServerToClient();
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
clientSasl.setMechanisms(TESTMECH1);
pumpClientToServer();
serverSasl.done(SaslOutcome.PN_SASL_AUTH);
pumpServerToClient();
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_AUTH, clientSasl.getOutcome());
}
示例6: login
import org.apache.qpid.proton.engine.Sasl; //导入方法依赖的package包/类
@Override
public boolean login() throws LoginException {
boolean success = false;
try {
List<X509Certificate> certs = new ArrayList<>();
if(isAuthenticatedUsingCerts(certs)) {
success = populateUserAndRolesFromCert(certs.get(0));
} else {
Transport transport = Proton.transport();
Connection connection = Proton.connection();
transport.bind(connection);
Sasl sasl = transport.sasl();
sasl.client();
Socket socket = createSocket();
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
transport.open();
// write Headers
writeToNetwork(connection, out);
SaslMechanism mechanism = chooseSaslMechanismAndSendInit(connection, in, out);
performSaslSteps(connection, in, out, mechanism);
if (isSaslAuthenticated(connection, mechanism)) {
performConnectionOpen(connection, in, out);
getUserAndRolesFromConnection(connection);
success = true;
} else {
LOG.debug("Login failed");
}
connection.close();
transport.close();
socket.close();
}
} catch (IOException | UnsupportedCallbackException | InvalidNameException e) {
LoginException loginException = new LoginException("Exception attempting to authenticate using SASL delegation");
loginException.initCause(e);
LOG.warn(e);
throw loginException;
}
loginSucceeded = success;
return success;
}
示例7: testSaslNegotiation
import org.apache.qpid.proton.engine.Sasl; //导入方法依赖的package包/类
/** 5.3.2 SASL Negotiation. */
@Test
public void testSaslNegotiation() throws Exception
{
getClient().transport = Proton.transport();
getServer().transport = Proton.transport();
Sasl clientSasl = getClient().transport.sasl();
clientSasl.client();
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
Sasl serverSasl = getServer().transport.sasl();
serverSasl.server();
serverSasl.setMechanisms(TESTMECH1, TESTMECH2);
assertEquals("Server should not yet know the remote's chosen mechanism.",
0,
serverSasl.getRemoteMechanisms().length);
pumpClientToServer();
pumpServerToClient();
assertArrayEquals("Client should now know the server's mechanisms.",
new String[]{TESTMECH1, TESTMECH2},
clientSasl.getRemoteMechanisms());
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
clientSasl.setMechanisms(TESTMECH1);
pumpClientToServer();
assertArrayEquals("Server should now know the client's chosen mechanism.",
new String[]{TESTMECH1},
serverSasl.getRemoteMechanisms());
serverSasl.send(CHALLENGE_BYTES, 0, CHALLENGE_BYTES.length);
pumpServerToClient();
byte[] clientReceivedChallengeBytes = new byte[clientSasl.pending()];
clientSasl.recv(clientReceivedChallengeBytes, 0, clientReceivedChallengeBytes.length);
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
assertArrayEquals("Client should now know the server's challenge",
CHALLENGE_BYTES,
clientReceivedChallengeBytes);
clientSasl.send(RESPONSE_BYTES, 0, RESPONSE_BYTES.length);
pumpClientToServer();
byte[] serverReceivedResponseBytes = new byte[serverSasl.pending()];
serverSasl.recv(serverReceivedResponseBytes, 0, serverReceivedResponseBytes.length);
assertArrayEquals("Server should now know the client's response",
RESPONSE_BYTES,
serverReceivedResponseBytes);
serverSasl.done(SaslOutcome.PN_SASL_OK);
pumpServerToClient();
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_OK, clientSasl.getOutcome());
}
示例8: testOutcomeAdditionalData
import org.apache.qpid.proton.engine.Sasl; //导入方法依赖的package包/类
/**
* 5.3.3.5 The additional-data field carries additional data on successful authentication outcome as specified
* by the SASL specification [RFC4422].
*/
@Test
public void testOutcomeAdditionalData() throws Exception
{
getClient().transport = Proton.transport();
getServer().transport = Proton.transport();
Sasl clientSasl = getClient().transport.sasl();
clientSasl.client();
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
Sasl serverSasl = getServer().transport.sasl();
serverSasl.server();
serverSasl.setMechanisms(TESTMECH1);
pumpClientToServer();
pumpServerToClient();
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
clientSasl.setMechanisms(TESTMECH1);
pumpClientToServer();
serverSasl.send(CHALLENGE_BYTES, 0, CHALLENGE_BYTES.length);
pumpServerToClient();
byte[] clientReceivedChallengeBytes = new byte[clientSasl.pending()];
clientSasl.recv(clientReceivedChallengeBytes, 0, clientReceivedChallengeBytes.length);
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_NONE, clientSasl.getOutcome());
clientSasl.send(RESPONSE_BYTES, 0, RESPONSE_BYTES.length);
pumpClientToServer();
byte[] serverReceivedResponseBytes = new byte[serverSasl.pending()];
serverSasl.recv(serverReceivedResponseBytes, 0, serverReceivedResponseBytes.length);
serverSasl.send(ADDITIONAL_DATA_BYTES, 0, ADDITIONAL_DATA_BYTES.length);
serverSasl.done(SaslOutcome.PN_SASL_OK);
pumpServerToClient();
byte[] clientReceivedAdditionalDataBytes = new byte[clientSasl.pending()];
clientSasl.recv(clientReceivedAdditionalDataBytes, 0, clientReceivedAdditionalDataBytes.length);
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_OK, clientSasl.getOutcome());
assertArrayEquals("Client should now know the serrver's additional-data",
ADDITIONAL_DATA_BYTES,
clientReceivedAdditionalDataBytes);
}
示例9: testSaslNegotiationUsingListener
import org.apache.qpid.proton.engine.Sasl; //导入方法依赖的package包/类
@Test
public void testSaslNegotiationUsingListener() throws Exception
{
getClient().transport = Proton.transport();
getServer().transport = Proton.transport();
AtomicBoolean mechanismsReceived = new AtomicBoolean();
AtomicBoolean challengeReceived = new AtomicBoolean();
AtomicBoolean outcomeReceived = new AtomicBoolean();
Sasl clientSasl = getClient().transport.sasl();
clientSasl.client();
clientSasl.setListener(new ClientSaslHandling(mechanismsReceived, challengeReceived, outcomeReceived));
AtomicBoolean initReceived = new AtomicBoolean();
AtomicBoolean responseReceived = new AtomicBoolean();
Sasl serverSasl = getServer().transport.sasl();
serverSasl.server();
serverSasl.setMechanisms(TESTMECH1, TESTMECH2);
serverSasl.setListener(new ServerSaslHandling(initReceived, responseReceived));
pumpClientToServer();
pumpServerToClient();
assertTrue("mechanisms were not received by client", mechanismsReceived.get());
assertFalse("init was received by server", initReceived.get());
pumpClientToServer();
assertTrue("init was not received by server", initReceived.get());
assertFalse("challenge was received by client", challengeReceived.get());
pumpServerToClient();
assertTrue("challenge was not received by client", challengeReceived.get());
assertFalse("response was received by server", responseReceived.get());
pumpClientToServer();
assertTrue("response was received by server", responseReceived.get());
assertFalse("outcome was received by client", outcomeReceived.get());
pumpServerToClient();
assertTrue("outcome was received by client", outcomeReceived.get());
assertEquals("Unexpected SASL outcome at client", SaslOutcome.PN_SASL_OK, clientSasl.getOutcome());
}