Exemplo n.º 1
0
        private void RTSP_ProcessAuthorization(RtspRequest message, RtspListener listener)
        {
            bool authorized = false;

            if (message.Headers.ContainsKey("Authorization") == true)
            {
                // The Header contained Authorization
                // Check the message has the correct Authorization
                // If it does not have the correct Authorization then close the RTSP connection
                authorized = _auth.IsValid(message);

                if (authorized == false)
                {
                    // Send a 401 Authentication Failed reply, then close the RTSP Socket
                    Rtsp.Messages.RtspResponse authorization_response = message.CreateResponse(_logger);
                    authorization_response.AddHeader("WWW-Authenticate: " + _auth.GetHeader());
                    authorization_response.ReturnCode = 401;
                    listener.SendMessage(authorization_response);

                    CloseConnection("unauthorized");
                    listener.Dispose();
                    return;
                }
            }
            if ((message.Headers.ContainsKey("Authorization") == false))
            {
                // Send a 401 Authentication Failed with extra info in WWW-Authenticate
                // to tell the Client if we are using Basic or Digest Authentication
                Rtsp.Messages.RtspResponse authorization_response = message.CreateResponse(_logger);
                authorization_response.AddHeader("WWW-Authenticate: " + _auth.GetHeader()); // 'Basic' or 'Digest'
                authorization_response.ReturnCode = 401;
                listener.SendMessage(authorization_response);
                return;
            }
        }