use of org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms in project qpid-broker-j by apache.
the class SaslTest method saslUnsuccessfulAuthentication.
@Test
@SpecificationTest(section = "5.3.2", description = "SASL Negotiation")
public void saslUnsuccessfulAuthentication() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
try (FrameTransport transport = new FrameTransport(addr, true).connect()) {
final Interaction interaction = transport.newInteraction();
final byte[] saslHeaderResponse = interaction.protocolHeader(SASL_AMQP_HEADER_BYTES).negotiateProtocol().consumeResponse().getLatestResponse(byte[].class);
assertThat(saslHeaderResponse, is(equalTo(SASL_AMQP_HEADER_BYTES)));
SaslMechanisms saslMechanismsResponse = interaction.consumeResponse().getLatestResponse(SaslMechanisms.class);
assertThat(Arrays.asList(saslMechanismsResponse.getSaslServerMechanisms()), hasItem(PLAIN));
final Binary initialResponse = new Binary(String.format("\0%s\0badpassword", _username).getBytes(StandardCharsets.US_ASCII));
SaslOutcome saslOutcome = interaction.saslMechanism(PLAIN).saslInitialResponse(initialResponse).saslInit().consumeResponse().getLatestResponse(SaslOutcome.class);
assertThat(saslOutcome.getCode(), equalTo(SaslCode.AUTH));
transport.assertNoMoreResponsesAndChannelClosed();
}
}
use of org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms in project qpid-broker-j by apache.
the class SaslTest method clientSendsSaslMechanisms.
@Test
@SpecificationTest(section = "5.3.2", description = "The peer acting as the SASL server MUST announce supported authentication mechanisms using" + "the sasl-mechanisms frame.")
public void clientSendsSaslMechanisms() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
try (FrameTransport transport = new FrameTransport(addr, true).connect()) {
SaslMechanisms clientMechs = new SaslMechanisms();
clientMechs.setSaslServerMechanisms(new Symbol[] { Symbol.valueOf("CLIENT-MECH") });
transport.newInteraction().protocolHeader(SASL_AMQP_HEADER_BYTES).negotiateProtocol().consumeResponse().consumeResponse(SaslMechanisms.class).sendPerformative(clientMechs).sync();
transport.assertNoMoreResponsesAndChannelClosed();
}
}
use of org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms in project qpid-broker-j by apache.
the class SaslTest method saslSuccessfulAuthentication.
@Test
@SpecificationTest(section = "5.3.2", description = "SASL Negotiation [...] challenge/response step occurs zero times")
public void saslSuccessfulAuthentication() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
try (FrameTransport transport = new FrameTransport(addr, true).connect()) {
final Interaction interaction = transport.newInteraction();
final byte[] saslHeaderResponse = interaction.protocolHeader(SASL_AMQP_HEADER_BYTES).negotiateProtocol().consumeResponse().getLatestResponse(byte[].class);
assertThat(saslHeaderResponse, is(equalTo(SASL_AMQP_HEADER_BYTES)));
SaslMechanisms saslMechanismsResponse = interaction.consumeResponse().getLatestResponse(SaslMechanisms.class);
assertThat(Arrays.asList(saslMechanismsResponse.getSaslServerMechanisms()), hasItem(PLAIN));
final Binary initialResponse = new Binary(String.format("\0%s\0%s", _username, _password).getBytes(StandardCharsets.US_ASCII));
SaslOutcome saslOutcome = interaction.saslMechanism(PLAIN).saslInitialResponse(initialResponse).saslInit().consumeResponse().getLatestResponse(SaslOutcome.class);
assertThat(saslOutcome.getCode(), equalTo(SaslCode.OK));
final byte[] headerResponse = interaction.protocolHeader(AMQP_HEADER_BYTES).negotiateProtocol().consumeResponse().getLatestResponse(byte[].class);
assertThat(headerResponse, is(equalTo(AMQP_HEADER_BYTES)));
transport.assertNoMoreResponses();
}
}
use of org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms in project qpid-broker-j by apache.
the class SaslAuthenticationTimeoutTest method authenticationTimeout.
@Test
public void authenticationTimeout() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
try (FrameTransport transport = new FrameTransport(addr, true).connect()) {
final Interaction interaction = transport.newInteraction();
final byte[] saslHeaderResponse = interaction.protocolHeader(SASL_AMQP_HEADER_BYTES).negotiateProtocol().consumeResponse().getLatestResponse(byte[].class);
assertThat(saslHeaderResponse, is(equalTo(SASL_AMQP_HEADER_BYTES)));
SaslMechanisms mechanismsResponse = interaction.consumeResponse().getLatestResponse(SaslMechanisms.class);
assertThat(Arrays.asList(mechanismsResponse.getSaslServerMechanisms()), hasItem(PLAIN));
transport.assertNoMoreResponsesAndChannelClosed();
}
}
use of org.apache.qpid.server.protocol.v1_0.type.security.SaslMechanisms in project qpid-broker-j by apache.
the class SaslMechanisms method toString.
@Override
public String toString() {
StringBuilder builder = new StringBuilder("SaslMechanisms{");
final int origLength = builder.length();
if (_saslServerMechanisms != null) {
if (builder.length() != origLength) {
builder.append(',');
}
builder.append("saslServerMechanisms=").append(Arrays.asList(_saslServerMechanisms));
}
builder.append('}');
return builder.toString();
}
Aggregations