Respond with error to hello, fix disconnect

This commit is contained in:
badaix 2025-02-11 22:44:29 +01:00 committed by Johannes Pohl
parent 9ce96a5cfe
commit 81f849bea9
3 changed files with 49 additions and 14 deletions

View file

@ -322,26 +322,26 @@ void Server::onMessageReceived(const std::shared_ptr<StreamSession>& streamSessi
if (auth.has_value())
ec = streamSession->authinfo.authenticate(auth->scheme, auth->param);
std::shared_ptr<msg::Error> error_msg;
if (!auth.has_value() || ec)
{
if (ec)
LOG(ERROR, LOG_TAG) << "Authentication failed: " << ec.detailed_message() << "\n";
else
LOG(ERROR, LOG_TAG) << "Authentication required\n";
auto error_msg = make_shared<msg::Error>(401, "Unauthorized", ec ? ec.detailed_message() : "Authentication required");
streamSession->send(error_msg, [streamSession](boost::system::error_code ec, std::size_t length)
{
LOG(DEBUG, LOG_TAG) << "Sent result: " << ec << ", len: " << length << "\n";
streamSession->stop();
});
return;
error_msg = make_shared<msg::Error>(401, "Unauthorized", ec ? ec.detailed_message() : "Authentication required");
}
if (!streamSession->authinfo.hasPermission("Streaming"))
{
std::string error = "Permission 'Streaming' missing";
LOG(ERROR, LOG_TAG) << error << "\n";
auto error_msg = make_shared<msg::Error>(403, "Forbidden", error);
error_msg = make_shared<msg::Error>(403, "Forbidden", error);
}
if (error_msg)
{
error_msg->refersTo = helloMsg.id;
streamSession->send(error_msg, [streamSession](boost::system::error_code ec, std::size_t length)
{
LOG(DEBUG, LOG_TAG) << "Sent result: " << ec << ", len: " << length << "\n";