public void MethodReceived(AMQStateManager stateManager, AMQMethodEvent evt) { ISaslClient saslClient = evt.ProtocolSession.SaslClient; if (saslClient == null) { throw new AMQException("No SASL client set up - cannot proceed with authentication"); } ConnectionSecureBody body = (ConnectionSecureBody)evt.Method; try { // Evaluate server challenge byte[] response = saslClient.EvaluateChallenge(body.Challenge); // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0) // TODO: Connect this to the session version obtained from ProtocolInitiation for this session. // Be aware of possible changes to parameter order as versions change. AMQFrame responseFrame = ConnectionSecureOkBody.CreateAMQFrame( evt.ChannelId, response); evt.ProtocolSession.WriteFrame(responseFrame); } catch (SaslException e) { throw new AMQException("Error processing SASL challenge: " + e, e); } }
protected virtual ZooKeeper CreateClientWithSasl(IWatcher watcher, ISaslClient saslClient) { // "Only" use a 10s session timeout as failed tests can // otherwise spin for a very long time in the client's // Dispose method. return(new ZooKeeper("127.0.0.1:2181", new TimeSpan(0, 0, 0, 10), watcher, saslClient)); }
public void ChoosesStrongerMechanism() { Hashtable props = new Hashtable(); string[] mechanisms = new string[] { "PLAIN", "OTHER", "CRAM-MD5" }; ISaslClient client = Sasl.CreateClient(mechanisms, "", "", "", props, this); Assert.IsNotNull(client); Assert.IsInstanceOfType(typeof(CramMD5SaslClient), client); }
public void CanCreateExternal() { Hashtable props = new Hashtable(); string[] mechanisms = new string[] { "EXTERNAL", "OTHER" }; ISaslClient client = Sasl.CreateClient(mechanisms, "", "", "", props, this); Assert.IsNotNull(client); Assert.IsInstanceOfType(typeof(ExternalSaslClient), client); }
public void ReturnsNullIfNoFactoryFound() { Hashtable props = new Hashtable(); props.Add(SaslProperties.PolicyNoPlainText, true); string[] mechanisms = new string[] { "PLAIN", "OTHER" }; ISaslClient client = Sasl.CreateClient(mechanisms, "", "", "", props, this); Assert.IsNull(client); }
public void CanCreateDigest() { Hashtable props = new Hashtable(); string[] mechanisms = new string[] { "DIGEST-MD5", "OTHER" }; ISaslClient client = Sasl.CreateClient(mechanisms, "", "", "", props, this); Assert.IsNotNull(client); Assert.IsInstanceOfType(typeof(DigestSaslClient), client); }
public void CanCreateAnonymous() { Hashtable props = new Hashtable(); string[] mechanisms = new string[] { "ANONYMOUS", "OTHER" }; ISaslClient client = Sasl.CreateClient(mechanisms, "", "", "", props, this); Assert.IsNotNull(client); Assert.IsInstanceOfType(typeof(AnonymousSaslClient), client); }
public void CanCreatePlain() { Hashtable props = new Hashtable(); string[] mechanisms = new string[] { "PLAIN", "OTHER" }; ISaslClient client = Sasl.CreateClient(mechanisms, "", "", "", props, this); Assert.IsNotNull(client); Assert.IsInstanceOfType(typeof(PlainSaslClient), client); }
public void ParsesConfigurationSection() { // if the TEST mechanism is available, then we know // the configuration section worked! Hashtable props = new Hashtable(); string[] mechanisms = new string[] { "TEST" }; ISaslClient client = Sasl.CreateClient(mechanisms, "", "", "", props, this); Assert.IsNotNull(client); Assert.IsInstanceOfType(typeof(TestSaslClient), client); }
/// <summary> /// Initializes a new instance of the <see cref="ClientConnection"/> class. /// </summary> /// <param name="hosts">The hosts.</param> /// <param name="sessionTimeout">The session timeout.</param> /// <param name="zooKeeper">The zoo keeper.</param> /// <param name="watcher">The watch manager.</param> /// <param name="saslClient">The SASL client.</param> /// <param name="sessionId">The session id.</param> /// <param name="sessionPasswd">The session passwd.</param> /// <param name="connectTimeout">Connection Timeout.</param> public ClientConnection(string hosts, TimeSpan sessionTimeout, ZooKeeper zooKeeper, ZKWatchManager watcher, ISaslClient saslClient, long sessionId, byte[] sessionPasswd, TimeSpan connectTimeout) { this.hosts = hosts; this.zooKeeper = zooKeeper; this.watcher = watcher; this.saslClient = saslClient; SessionTimeout = sessionTimeout; SessionId = sessionId; SessionPassword = sessionPasswd; ConnectionTimeout = connectTimeout; // parse out chroot, if any hosts = SetChrootPath(); GetHosts(hosts); SetTimeouts(sessionTimeout); CreateConsumer(); CreateProducer(); }
private byte[] DoAuthentication(string selectedMechanism, AMQProtocolSession ps) { ISaslClient saslClient = Sasl.Sasl.CreateClient( new string[] { selectedMechanism }, null, "AMQP", "localhost", new Hashtable(), CreateCallbackHandler(selectedMechanism, ps) ); if (saslClient == null) { throw new AMQException("Client SASL configuration error: no SaslClient could be created for mechanism " + selectedMechanism); } ps.SaslClient = saslClient; try { return(saslClient.HasInitialResponse ? saslClient.EvaluateChallenge(new byte[0]) : null); } catch (Exception ex) { ps.SaslClient = null; throw new AMQException("Unable to create SASL client", ex); } }
public ZooKeeper(string connectstring, TimeSpan sessionTimeout, IWatcher watcher, ISaslClient saslClient, long sessionId, byte[] sessionPasswd) { LOG.InfoFormat("Initiating client connection, connectstring={0} sessionTimeout={1} watcher={2} sessionId={3} sessionPasswd={4}", connectstring, sessionTimeout, watcher, sessionId, (sessionPasswd == null ? "<null>" : "<hidden>")); watchManager.DefaultWatcher = watcher; cnxn = new ClientConnection(connectstring, sessionTimeout, this, watchManager, saslClient, sessionId, sessionPasswd); cnxn.Start(); }
/// <param name="saslClient"> /// An optional object implementing the <see cref="ISaslClient"/> interface which will be used by the /// <see cref="ClientConnection"/> to authenticate with the server immediately after (re)connect. /// </param> public ZooKeeper(string connectstring, TimeSpan sessionTimeout, IWatcher watcher, ISaslClient saslClient) { LOG.InfoFormat("Initiating client connection, connectstring={0} sessionTimeout={1} watcher={2}", connectstring, sessionTimeout, watcher); watchManager.DefaultWatcher = watcher; cnxn = new ClientConnection(connectstring, sessionTimeout, this, watchManager, saslClient); cnxn.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="ClientConnection"/> class. /// </summary> /// <param name="hosts">The hosts.</param> /// <param name="sessionTimeout">The session timeout.</param> /// <param name="zooKeeper">The zoo keeper.</param> /// <param name="watcher">The watch manager.</param> /// <param name="saslClient">The SASL client.</param> /// <param name="sessionId">The session id.</param> /// <param name="sessionPasswd">The session passwd.</param> public ClientConnection(string hosts, TimeSpan sessionTimeout, ZooKeeper zooKeeper, ZKWatchManager watcher, ISaslClient saslClient, long sessionId, byte[] sessionPasswd) : this(hosts, sessionTimeout, zooKeeper, watcher, saslClient, 0, new byte[16], DefaultConnectTimeout) { }
public void ReturnsRightMechanismName() { ISaslClient client = CreateClient(); Assert.AreEqual("DIGEST-MD5", client.MechanismName); }
public void HasInitialResponseReturnsFalse() { ISaslClient client = CreateClient(); Assert.IsFalse(client.HasInitialResponse); }
/// <summary> /// Initializes a new instance of the <see cref="ClientConnection"/> class. /// </summary> /// <param name="connectionString">The connection string.</param> /// <param name="sessionTimeout">The session timeout.</param> /// <param name="zooKeeper">The zoo keeper.</param> /// <param name="watcher">The watch manager.</param> /// <param name="saslClient">The SASL client.</param> public ClientConnection(string connectionString, TimeSpan sessionTimeout, ZooKeeper zooKeeper, ZKWatchManager watcher, ISaslClient saslClient) : this(connectionString, sessionTimeout, zooKeeper, watcher, saslClient, 0, new byte[16], DefaultConnectTimeout) { }