internal AmqpSecurity(AmqpTransportSecurity tsec) { if (tsec == null) { throw new ArgumentNullException("AmqpTransportSecurity"); } this.mode = AmqpSecurityMode.Transport; this.transportSecurity = tsec; }
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; }
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(); } }
protected override void InitializeFrom(Binding binding) { base.InitializeFrom(binding); AmqpBinding amqpBinding = (AmqpBinding)binding; this.BrokerHost = amqpBinding.BrokerHost; this.BrokerPort = amqpBinding.BrokerPort; this.TransferMode = amqpBinding.TransferMode; this.Shared = amqpBinding.Shared; this.PrefetchLimit = amqpBinding.PrefetchLimit; if (!amqpBinding.SecurityEnabled) { this.Security = null; } else { if (this.Security == null) { this.Security = new AmqpSecurityElement(); } AmqpTransportSecurity sec = amqpBinding.Security.Transport; this.Security.Mode = AmqpSecurityMode.Transport; if (this.Security.Transport == null) { this.Security.Transport = new AmqpTransportSecurityElement(); } this.Security.Transport.CredentialType = sec.CredentialType; this.Security.Transport.IgnoreEndpointCredentials = sec.IgnoreEndpointClientCredentials; this.Security.Transport.UseSSL = sec.UseSSL; if (sec.DefaultCredential == null) { this.Security.Transport.DefaultCredential = null; } else { this.Security.Transport.DefaultCredential = new AmqpCredentialElement(); this.Security.Transport.DefaultCredential.UserName = sec.DefaultCredential.UserName; this.Security.Transport.DefaultCredential.Password = sec.DefaultCredential.Password; } } AmqpProperties props = amqpBinding.DefaultMessageProperties; }
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()); }
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); }