use of org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult in project activemq-artemis by apache.
the class ProtonServerReceiverContext method initialise.
@Override
public void initialise() throws Exception {
super.initialise();
org.apache.qpid.proton.amqp.messaging.Target target = (org.apache.qpid.proton.amqp.messaging.Target) receiver.getRemoteTarget();
// Match the settlement mode of the remote instead of relying on the default of MIXED.
receiver.setSenderSettleMode(receiver.getRemoteSenderSettleMode());
// We don't currently support SECOND so enforce that the answer is anlways FIRST
receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST);
RoutingType defRoutingType;
if (target != null) {
if (target.getDynamic()) {
// if dynamic we have to create the node (queue) and set the address on the target, the node is temporary and
// will be deleted on closing of the session
address = SimpleString.toSimpleString(sessionSPI.tempQueueName());
defRoutingType = getRoutingType(target.getCapabilities(), address);
try {
sessionSPI.createTemporaryQueue(address, defRoutingType);
} catch (ActiveMQSecurityException e) {
throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingTempDestination(e.getMessage());
} catch (Exception e) {
throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
}
expiryPolicy = target.getExpiryPolicy() != null ? target.getExpiryPolicy() : TerminusExpiryPolicy.LINK_DETACH;
target.setAddress(address.toString());
} else {
// the target will have an address unless the remote is requesting an anonymous
// relay in which case the address in the incoming message's to field will be
// matched on receive of the message.
address = SimpleString.toSimpleString(target.getAddress());
if (address != null && !address.isEmpty()) {
defRoutingType = getRoutingType(target.getCapabilities(), address);
try {
if (!sessionSPI.bindingQuery(address, defRoutingType)) {
throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.addressDoesntExist();
}
} catch (ActiveMQAMQPNotFoundException e) {
throw e;
} catch (Exception e) {
log.debug(e.getMessage(), e);
throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
}
try {
sessionSPI.check(address, CheckType.SEND, new SecurityAuth() {
@Override
public String getUsername() {
String username = null;
SASLResult saslResult = connection.getSASLResult();
if (saslResult != null) {
username = saslResult.getUser();
}
return username;
}
@Override
public String getPassword() {
String password = null;
SASLResult saslResult = connection.getSASLResult();
if (saslResult != null) {
if (saslResult instanceof PlainSASLResult) {
password = ((PlainSASLResult) saslResult).getPassword();
}
}
return password;
}
@Override
public RemotingConnection getRemotingConnection() {
return connection.connectionCallback.getProtonConnectionDelegate();
}
});
} catch (ActiveMQSecurityException e) {
throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingProducer(e.getMessage());
}
}
}
Symbol[] remoteDesiredCapabilities = receiver.getRemoteDesiredCapabilities();
if (remoteDesiredCapabilities != null) {
List<Symbol> list = Arrays.asList(remoteDesiredCapabilities);
if (list.contains(AmqpSupport.DELAYED_DELIVERY)) {
receiver.setOfferedCapabilities(new Symbol[] { AmqpSupport.DELAYED_DELIVERY });
}
}
}
flow(amqpCredits, minCreditRefresh);
}
use of org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult in project activemq-artemis by apache.
the class ProtonHandler method onSaslOutcome.
@Override
public void onSaslOutcome(Sasl sasl, Transport transport) {
log.debug("onSaslOutcome: " + sasl);
switch(sasl.getState()) {
case PN_SASL_FAIL:
log.info("Outbound connection failed, authentication failure");
dispatchAuthFailed();
break;
case PN_SASL_PASS:
log.debug("Outbound connection succeeded");
if (sasl.pending() != 0) {
byte[] additionalData = new byte[sasl.pending()];
sasl.recv(additionalData, 0, additionalData.length);
clientSASLMechanism.getResponse(additionalData);
}
saslResult = new SASLResult() {
@Override
public String getUser() {
return null;
}
@Override
public Subject getSubject() {
return null;
}
@Override
public boolean isSuccess() {
return true;
}
};
dispatchAuthSuccess();
break;
default:
break;
}
}
Aggregations