示例#1
0
        protected override DescribedList GetStartCommand(string hostname)
        {
            SaslInit init = new SaslInit()
            {
                Mechanism = this.Mechanism,
                HostName  = hostname
            };

            return(init);
        }
            protected override DescribedList OnCommand(DescribedList command)
            {
                if (command.Descriptor.Code == Codec.SaslInit.Code)
                {
                    SaslInit init = (SaslInit)command;
                    SaslCode code = this.ValidateCredentials(init);
                    return(new SaslOutcome()
                    {
                        Code = code
                    });
                }

                throw new AmqpException(ErrorCode.NotAllowed, command.ToString());
            }
        protected override DescribedList GetStartCommand(string hostname)
        {
            byte[] b1      = Encoding.UTF8.GetBytes(this.user);
            byte[] b2      = Encoding.UTF8.GetBytes(this.password);
            byte[] message = new byte[2 + b1.Length + b2.Length];
            Array.Copy(b1, 0, message, 1, b1.Length);
            Array.Copy(b2, 0, message, b1.Length + 2, b2.Length);

            SaslInit init = new SaslInit()
            {
                Mechanism       = this.Mechanism,
                InitialResponse = message,
                HostName        = hostname
            };

            return(init);
        }
        protected override DescribedList GetStartCommand(string hostname)
        {
            byte[] b1 = Encoding.UTF8.GetBytes(this.user);
            byte[] b2 = Encoding.UTF8.GetBytes(this.password);
            byte[] message = new byte[2 + b1.Length + b2.Length];
            Array.Copy(b1, 0, message, 1, b1.Length);
            Array.Copy(b2, 0, message, b1.Length + 2, b2.Length);

            SaslInit init = new SaslInit()
            {
                Mechanism = Name,
                InitialResponse = message,
                HostName = hostname
            };

            return init;
        }
            SaslCode ValidateCredentials(SaslInit init)
            {
                byte[] response = init.InitialResponse;
                if (response.Length > 0)
                {
                    string   message = Encoding.UTF8.GetString(response, 0, response.Length);
                    string[] items   = message.Split('\0');
                    if (items.Length == 3 &&
                        string.Equals(this.mechanism.user, items[1], StringComparison.OrdinalIgnoreCase) &&
                        string.Equals(this.mechanism.password, items[2], StringComparison.Ordinal))
                    {
                        return(SaslCode.Ok);
                    }
                }

                return(SaslCode.Auth);
            }
示例#6
0
            SaslCode ValidateCredentials(SaslInit init)
            {
                byte[] response = init.InitialResponse;
                if (response.Length > 0)
                {
                    string message = Encoding.UTF8.GetString(response, 0, response.Length);
                    string[] items = message.Split('\0');
                    if (items.Length == 3 &&
                        string.Equals(this.mechanism.user, items[1], StringComparison.OrdinalIgnoreCase) &&
                        string.Equals(this.mechanism.password, items[2], StringComparison.Ordinal))
                    {
                        this.Principal = new GenericPrincipal(
                            new GenericIdentity(string.IsNullOrEmpty(items[2]) ? items[0] : items[2], this.mechanism.Name),
                            new string[0]);

                        return SaslCode.Ok;
                    }
                }

                return SaslCode.Auth;
            }
            SaslCode ValidateCredentials(SaslInit init)
            {
                byte[] response = init.InitialResponse;
                if (response.Length > 0)
                {
                    string message = Encoding.UTF8.GetString(response, 0, response.Length);
                    string[] items = message.Split('\0');
                    if (items.Length == 3 &&
                        string.Equals(this.mechanism.user, items[1], StringComparison.OrdinalIgnoreCase) &&
                        string.Equals(this.mechanism.password, items[2], StringComparison.Ordinal))
                    {
                        return SaslCode.Ok;
                    }
                }

                return SaslCode.Auth;
            }