You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by gk...@apache.org on 2025/07/24 08:14:17 UTC

(iggy) 01/01: feat(io_uring): fix session auth for http protocol

This is an automated email from the ASF dual-hosted git repository.

gkoszyk pushed a commit to branch fix_session_auth
in repository https://gitbox.apache.org/repos/asf/iggy.git

commit ee8cab1a4855c401f41391bde9c18c3c55c423ca
Author: numminex <g....@gmail.com>
AuthorDate: Thu Jul 24 10:14:05 2025 +0200

    feat(io_uring): fix session auth for http protocol
---
 core/server/src/shard/mod.rs        | 27 ++++++++++++---------------
 core/server/src/tcp/tcp_listener.rs |  2 ++
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/core/server/src/shard/mod.rs b/core/server/src/shard/mod.rs
index ce83359b..8aaca93b 100644
--- a/core/server/src/shard/mod.rs
+++ b/core/server/src/shard/mod.rs
@@ -961,20 +961,17 @@ impl IggyShard {
         }
     }
 
-    pub fn ensure_authenticated(&self, session: &Session) -> Result<u32, IggyError> {
-        let active_sessions = self.active_sessions.borrow();
-        let user_id = active_sessions
-            .iter()
-            .find(|s| s.get_user_id() == session.get_user_id())
-            .ok_or_else(|| IggyError::Unauthenticated)
-            .and_then(|session| {
-                if session.is_authenticated() {
-                    Ok(session.get_user_id())
-                } else {
-                    error!("{COMPONENT} - unauthenticated access attempt, session: {session}");
-                    Err(IggyError::Unauthenticated)
-                }
-            })?;
-        Ok(user_id)
+    pub fn ensure_authenticated(&self, session: &Session) -> Result<(), IggyError> {
+        if !session.is_active() {
+            error!("{COMPONENT} - session is inactive, session: {session}");
+            return Err(IggyError::StaleClient);
+        }
+
+        if session.is_authenticated() {
+            Ok(())
+        } else {
+            error!("{COMPONENT} - unauthenticated access attempt, session: {session}");
+            Err(IggyError::Unauthenticated)
+        }
     }
 }
diff --git a/core/server/src/tcp/tcp_listener.rs b/core/server/src/tcp/tcp_listener.rs
index 67f25f02..449c2716 100644
--- a/core/server/src/tcp/tcp_listener.rs
+++ b/core/server/src/tcp/tcp_listener.rs
@@ -70,6 +70,7 @@ pub async fn start(
     config: &TcpSocketConfig,
     shard: Rc<IggyShard>,
 ) -> Result<(), IggyError> {
+    //TODO: Fix me, this needs to take into account that first shard id potentially can be greater than 0.
     if shard.id != 0 && addr.port() == 0 {
         shard_info!(shard.id, "Waiting for TCP address from shard 0...");
         loop {
@@ -99,6 +100,7 @@ pub async fn start(
         actual_addr
     );
 
+    //TODO: Fix me, this needs to take into account that first shard id potentially can be greater than 0.
     if shard.id == 0 {
         if addr.port() == 0 {
             let event = ShardEvent::TcpBound {