Search in sources :

Example 1 with SASLResult

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);
}
Also used : ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) Symbol(org.apache.qpid.proton.amqp.Symbol) SecurityAuth(org.apache.activemq.artemis.core.security.SecurityAuth) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) PlainSASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) SASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult) PlainSASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 2 with SASLResult

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;
    }
}
Also used : SASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult) Subject(javax.security.auth.Subject)

Aggregations

SASLResult (org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult)2 Subject (javax.security.auth.Subject)1 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 SecurityAuth (org.apache.activemq.artemis.core.security.SecurityAuth)1 ActiveMQAMQPException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException)1 ActiveMQAMQPInternalErrorException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException)1 ActiveMQAMQPNotFoundException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException)1 PlainSASLResult (org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult)1 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)1 Symbol (org.apache.qpid.proton.amqp.Symbol)1