CALL gql.authenticate_user(username, password) YIELD authenticated, user_id, username, roles Authenticates a user with username and password
(&self, args: Vec<Value>)
| 971 | /// CALL gql.authenticate_user(username, password) YIELD authenticated, user_id, username, roles |
| 972 | /// Authenticates a user with username and password |
| 973 | fn authenticate_user(&self, args: Vec<Value>) -> Result<QueryResult, ExecutionError> { |
| 974 | // Validate exactly 2 arguments |
| 975 | if args.len() != 2 { |
| 976 | return Err(ExecutionError::RuntimeError(format!( |
| 977 | "authenticate_user expects exactly 2 arguments, got {}", |
| 978 | args.len() |
| 979 | ))); |
| 980 | } |
| 981 | |
| 982 | // Validate argument types |
| 983 | let username = match &args[0] { |
| 984 | Value::String(s) => s.clone(), |
| 985 | _ => { |
| 986 | return Err(ExecutionError::RuntimeError( |
| 987 | "First argument (username) must be a string".to_string(), |
| 988 | )) |
| 989 | } |
| 990 | }; |
| 991 | |
| 992 | let password = match &args[1] { |
| 993 | Value::String(s) => s.clone(), |
| 994 | _ => { |
| 995 | return Err(ExecutionError::RuntimeError( |
| 996 | "Second argument (password) must be a string".to_string(), |
| 997 | )) |
| 998 | } |
| 999 | }; |
| 1000 | |
| 1001 | // Query the security catalog for authentication |
| 1002 | let mut catalog_manager = self.catalog_manager.write().map_err(|_| { |
| 1003 | ExecutionError::RuntimeError("Failed to acquire catalog manager lock".to_string()) |
| 1004 | })?; |
| 1005 | |
| 1006 | let auth_params = json!({ |
| 1007 | "username": username, |
| 1008 | "password": password |
| 1009 | }); |
| 1010 | |
| 1011 | let result = catalog_manager |
| 1012 | .execute( |
| 1013 | "security", |
| 1014 | CatalogOperation::Query { |
| 1015 | query_type: QueryType::Authenticate, |
| 1016 | params: auth_params, |
| 1017 | }, |
| 1018 | ) |
| 1019 | .map_err(|e| ExecutionError::RuntimeError(format!("Authentication failed: {}", e)))?; |
| 1020 | |
| 1021 | // Parse authentication response |
| 1022 | if let CatalogResponse::Query { results } = result { |
| 1023 | if results |
| 1024 | .get("authenticated") |
| 1025 | .and_then(|v| v.as_bool()) |
| 1026 | .unwrap_or(false) |
| 1027 | { |
| 1028 | // Authentication successful |
| 1029 | let user_id = results |
| 1030 | .get("user_id") |