Exemplo n.º 1
0
        public static ReadOnlySequence <byte> NewAuthResponse(string authMethod, AuthData clientData, int clientProtocolVersion, string clientVersion)
        {
            var authData = new AuthData {
                auth_data = clientData.auth_data, AuthMethodName = authMethod
            };

            var response = new CommandAuthResponse
            {
                Response        = authData,
                ProtocolVersion = clientProtocolVersion,
                ClientVersion   = clientVersion ?? "Pulsar Client"
            };

            return(Serializer.Serialize(response.ToBaseCommand()));
        }
Exemplo n.º 2
0
        public static ReadOnlySequence <byte> NewAuthChallenge(string authMethod, AuthData brokerData, int clientProtocolVersion)
        {
            var challenge = new CommandAuthChallenge();

            // If the broker supports a newer version of the protocol, it will anyway advertise the max version that the
            // client supports, to avoid confusing the client.
            var versionToAdvertise = Math.Min(Enum.GetValues(typeof(ProtocolVersion)).Cast <int>().Max(), clientProtocolVersion);

            challenge.ProtocolVersion = versionToAdvertise;

            challenge.Challenge = new AuthData
            {
                auth_data      = brokerData.auth_data,
                AuthMethodName = authMethod
            };
            //var challenge = challenge.Challenge().Build();

            return(Serializer.Serialize(challenge.ToBaseCommand()));
        }
Exemplo n.º 3
0
        public static ReadOnlySequence <byte> NewConnect(string authMethodName, AuthData authData, int protocolVersion, string libVersion, string targetBroker, string originalPrincipal, AuthData originalAuthData, string originalAuthMethod)
        {
            var connect = new CommandConnect
            {
                ClientVersion  = libVersion,
                AuthMethodName = authMethodName,
                FeatureFlags   = new FeatureFlags {
                    SupportsAuthRefresh = true
                }
            };

            if (!string.IsNullOrWhiteSpace(targetBroker))
            {
                // When connecting through a proxy, we need to specify which broker do we want to be proxied through
                connect.ProxyToBrokerUrl = targetBroker;
            }

            if (authData != null)
            {
                connect.AuthData = authData.auth_data;
            }

            if (!string.IsNullOrWhiteSpace(originalPrincipal))
            {
                connect.OriginalPrincipal = originalPrincipal;
            }

            if (originalAuthData != null)
            {
                connect.OriginalAuthData = Encoding.UTF8.GetString(originalAuthData.auth_data);
            }

            if (!string.IsNullOrWhiteSpace(originalAuthMethod))
            {
                connect.OriginalAuthMethod = originalAuthMethod;
            }
            connect.ProtocolVersion = protocolVersion;
            var ba = connect.ToBaseCommand();

            return(Serializer.Serialize(ba));
        }
Exemplo n.º 4
0
 public Builder()
 {
     _auth = new AuthData();
 }