Exemplo n.º 1
0
 internal AmqpChannelProperties()
 {
     this.brokerHost               = AmqpDefaults.BrokerHost;
     this.brokerPort               = AmqpDefaults.BrokerPort;
     this.transferMode             = AmqpDefaults.TransferMode;
     this.defaultMessageProperties = null;
     this.amqpSecurityMode         = AmqpSecurityMode.None;
     this.amqpTransportSecurity    = null;
     this.amqpCredential           = null;
     this.maxBufferPoolSize        = AmqpDefaults.MaxBufferPoolSize;
     this.maxReceivedMessageSize   = AmqpDefaults.MaxReceivedMessageSize;
 }
Exemplo n.º 2
0
        internal static void FindAuthenticationCredentials(AmqpChannelProperties channelProperties,
                                                           BindingContext bindingContext)
        {
            AmqpTransportSecurity tsec = channelProperties.AmqpTransportSecurity;

            if (tsec == null)
            {
                // no auth
                return;
            }

            if (tsec.CredentialType == AmqpCredentialType.Anonymous)
            {
                // no auth
                return;
            }

            // credentials search order: specific AmqpCredentials, specific
            // ClientCredentials (if applicable), binding's default credentials

            AmqpCredential amqpCred = bindingContext.BindingParameters.Find <AmqpCredential>();

            if (amqpCred != null)
            {
                channelProperties.AmqpCredential = amqpCred.Clone();
                return;
            }

            if (!tsec.IgnoreEndpointClientCredentials)
            {
                ClientCredentials cliCred = bindingContext.BindingParameters.Find <ClientCredentials>();
                if (cliCred != null)
                {
                    if (cliCred.UserName != null)
                    {
                        if (cliCred.UserName.UserName != null)
                        {
                            channelProperties.AmqpCredential = new AmqpCredential(cliCred.UserName.UserName,
                                                                                  cliCred.UserName.Password);
                            return;
                        }
                    }
                }
            }

            if (tsec.DefaultCredential != null)
            {
                channelProperties.AmqpCredential = tsec.DefaultCredential.Clone();
            }
        }
Exemplo n.º 3
0
        public AmqpChannelProperties Clone()
        {
            AmqpChannelProperties props = (AmqpChannelProperties)this.MemberwiseClone();

            if (this.defaultMessageProperties != null)
            {
                props.defaultMessageProperties = this.defaultMessageProperties.Clone();
            }

            if (this.amqpTransportSecurity != null)
            {
                props.amqpTransportSecurity = this.amqpTransportSecurity.Clone();
            }

            if (this.amqpCredential != null)
            {
                this.amqpCredential = this.amqpCredential.Clone();
            }

            return(props);
        }
Exemplo n.º 4
0
        private static string MakeKey(AmqpChannelProperties props)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(props.BrokerHost);
            sb.Append(':');
            sb.Append(props.BrokerPort);
            sb.Append(':');
            sb.Append(props.TransferMode);

            AmqpTransportSecurity sec = props.AmqpTransportSecurity;

            if (sec == null)
            {
                return(sb.ToString());
            }

            if (sec.UseSSL)
            {
                sb.Append(":SSL");
            }

            if (sec.CredentialType == AmqpCredentialType.Plain)
            {
                sb.Append(":saslP");
                AmqpCredential cred = props.AmqpCredential;
                if (cred != null)
                {
                    sb.Append(":NM:");
                    sb.Append(cred.UserName);
                    sb.Append(":PW:");
                    sb.Append(cred.Password);
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 5
0
            public object GetLink(AmqpChannelProperties channelProperties, bool sessionSharing, string inputQueue, string outputQueue)
            {
                AmqpConnection connection    = null;
                AmqpSession    session       = null;
                Object         link          = null;
                bool           newConnection = false;
                //bool newSession = false;
                bool success = false;

                // when called in the non-shared case, only stack variables should be used for holding connections/sessions/links

                if (this.shared)
                {
                    Monitor.Enter(this); // lock
                }

                try
                {
                    if (this.shared)
                    {
                        // TODO: check shared connection not closed (i.e. network drop) and refresh this instance if needed
                        if (sessionSharing)
                        {
                            throw new NotImplementedException("shared session");

                            /* * ... once we have a defined shared session config parameter:
                             *
                             * // lazilly create
                             * if (this.sharedSessions == null)
                             * {
                             *  this.sharedSessions = new Dictionary<string, AmqpSession>();
                             * }
                             *
                             * alreadydeclaredstring sessionKey = channelProperties.name_of_key_goes_here;
                             * this.sharedSessions.TryGetValue(sessionKey, out session);
                             *
                             * */
                        }

                        if (this.sharedConnection != null)
                        {
                            connection = this.sharedConnection;
                        }
                    }

                    if (connection == null)
                    {
                        if (channelProperties.AmqpSecurityMode != AmqpSecurityMode.None)
                        {
                            string user      = null;
                            string passwd    = null;
                            bool   ssl       = false;
                            bool   saslPlain = false;

                            AmqpTransportSecurity tsec = channelProperties.AmqpTransportSecurity;
                            if (tsec.UseSSL)
                            {
                                ssl = true;
                            }

                            if (tsec.CredentialType == AmqpCredentialType.Plain)
                            {
                                saslPlain = true;
                                AmqpCredential plainCred = channelProperties.AmqpCredential;
                                if (plainCred != null)
                                {
                                    user   = plainCred.UserName;
                                    passwd = plainCred.Password;
                                }
                            }

                            connection = new AmqpConnection(channelProperties.BrokerHost, channelProperties.BrokerPort,
                                                            ssl, saslPlain, user, passwd);
                        }
                        else
                        {
                            connection = new AmqpConnection(channelProperties.BrokerHost, channelProperties.BrokerPort);
                        }

                        newConnection = true;
                        if (this.shared)
                        {
                            connection.OnConnectionIdle += new ConnectionIdleEventHandler(this.IdleConnectionHandler);
                        }
                        else
                        {
                            connection.OnConnectionIdle += new ConnectionIdleEventHandler(UnsharedIdleConnectionHandler);
                        }
                    }

                    if (session == null)
                    {
                        session = connection.CreateSession();
                        //newSession = true;
                    }

                    if (inputQueue != null)
                    {
                        link = session.CreateInputLink(inputQueue);
                    }
                    else
                    {
                        link = session.CreateOutputLink(outputQueue);
                    }

                    if (this.shared)
                    {
                        if (newConnection)
                        {
                            this.sharedConnection = connection;
                        }

                        /*
                         * if (newSession)
                         * {
                         *  sharedSessions.Add(foo, session);
                         * }
                         * */
                    }

                    success = true;
                }
                finally
                {
                    if (this.shared)
                    {
                        Monitor.Exit(this);
                    }
                    if (!success)
                    {
                        /*
                         * if (newSession)
                         * {
                         *  session.Close();
                         * }
                         */
                        if (newConnection)
                        {
                            connection.Close();
                        }
                    }
                }

                return(link);
            }