Search in sources :

Example 1 with PlainSASLResult

use of org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult in project activemq-artemis by apache.

the class AMQPSessionCallback method init.

public void init(AMQPSessionContext protonSession, SASLResult saslResult) throws Exception {
    this.protonSession = protonSession;
    String name = UUIDGenerator.getInstance().generateStringUUID();
    String user = null;
    String passcode = null;
    if (saslResult != null) {
        user = saslResult.getUser();
        if (saslResult instanceof PlainSASLResult) {
            passcode = ((PlainSASLResult) saslResult).getPassword();
        }
    }
    serverSession = // RemotingConnection remotingConnection,
    manager.getServer().createSession(// RemotingConnection remotingConnection,
    name, // RemotingConnection remotingConnection,
    user, // RemotingConnection remotingConnection,
    passcode, // RemotingConnection remotingConnection,
    ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, // RemotingConnection remotingConnection,
    protonSPI.getProtonConnectionDelegate(), // boolean autoCommitSends
    false, // boolean autoCommitAcks,
    false, // boolean preAcknowledge,
    false, // boolean xa,
    true, (String) null, this, true, operationContext, manager.getPrefixes());
}
Also used : PlainSASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 2 with PlainSASLResult

use of org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult 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)

Aggregations

SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 PlainSASLResult (org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult)2 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)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 SASLResult (org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult)1 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)1 Symbol (org.apache.qpid.proton.amqp.Symbol)1