@@ -137,25 +137,27 @@ void flashmq_plugin_poll_event_received(void *thread_data, int fd, uint32_t even
137137
138138
139139enum class Allowed_Access {
140- playbook,
141- bettingClient,
142- sportsClient,
143- pump,
140+ playbook,
141+ bettingClient,
142+ sportsClient,
143+ pump,
144144};
145145
146- std::map<Allowed_Access, std::string> allowed_user_access_map = {
147- {Allowed_Access::playbook, " playbook" },
148- {Allowed_Access::sportsClient, " sports-client" },
149- {Allowed_Access::bettingClient, " anonymous-betting-client" },
150- {Allowed_Access::pump, " pump" },
151- };
152-
153- std::string allowed_user_access_check (Allowed_Access username) {
154- auto it = allowed_user_access_map.find (username);
155- if (it != allowed_user_access_map.end ()) {
156- return it->second ;
157- }
158- return " Unknown" ; // Handle invalid enum values
146+ bool allow_user_access (const std::string &username)
147+ {
148+ const std::map<Allowed_Access, std::string> allowmap = {
149+ {Allowed_Access::playbook, " playbook" },
150+ {Allowed_Access::sportsClient, " sports-client" },
151+ {Allowed_Access::bettingClient, " anonymous-betting-client" },
152+ {Allowed_Access::pump, " pump" },
153+ };
154+
155+ for (const auto &kv : allowmap) {
156+ if (kv.second == username) {
157+ return true ;
158+ }
159+ }
160+ return false ;
159161}
160162
161163std::string get_env_var ( std::string const & key )
@@ -184,31 +186,27 @@ std::string base64_decode(const std::string &in) {
184186 BIO_free_all (bio);
185187 return out;
186188}
189+
187190AuthResult flashmq_plugin_login_check (void *thread_data, const std::string &clientid, const std::string &username, const std::string &password,
188191 const std::vector<std::pair<std::string, std::string>> *userProperties, const std::weak_ptr<Client> &client)
189192{
190193 (void )clientid;
191194 (void )userProperties;
192195 (void )client;
193- (void )username;
194- (void )password;
196+
195197
196198 flashmq_logf (LOG_INFO, " username: %s" , username.c_str ());
197199
198- for (const auto &grant : {Allowed_Access::playbook, Allowed_Access::sportsClient,
199- Allowed_Access::bettingClient, Allowed_Access::pump})
200- {
201- if (username == allowed_user_access_check (grant))
202- {
203- return AuthResult::success;
204- }
200+ if (allow_user_access (username)){
201+ return AuthResult::success;
205202 }
206203
207204 // base64 decode the environment variable AUTH_PUBLICKEY
208205 const std::string rsa_pub_env_key = get_env_var (" AUTH_PUBLICKEY" );
209206 const std::string rsa_pub_key = base64_decode (rsa_pub_env_key);
210207
211- const std::string token = username; // In a real application, you would get the token from the username or password field.
208+ const std::string token = password;
209+ flashmq_logf (LOG_INFO, " token: %s" , token.c_str ());
212210 if (token.empty ())
213211 {
214212 flashmq_logf (LOG_ERR, " No token found for username: %s" , username.c_str ());
@@ -222,19 +220,11 @@ AuthResult flashmq_plugin_login_check(void *thread_data, const std::string &clie
222220 auto verify = jwt::verify ()
223221 // We only need an RSA public key to verify tokens
224222 .allow_algorithm (jwt::algorithm::rs256 (rsa_pub_key, " " , " " , " " ));
225- /* [allow rsa algorithm] */
226-
227- // Decode the JWT token
228223 /* [decode jwt token] */
229- auto decoded = jwt::decode (username );
224+ auto decoded = jwt::decode (token );
230225 flashmq_logf (LOG_INFO, " Decoded JWT token successfully" );
231226 verify.verify (decoded);
232227 flashmq_logf (LOG_INFO, " Verified JWT token successfully with public key" );
233- // for (auto& e : decoded.get_header_json())
234- // std::cout << e.first << " = " << e.second << '\n';
235- // for (auto& e : decoded.get_payload_json())
236- // std::cout << e.first << " = " << e.second << '\n';
237-
238228
239229 return AuthResult::success;
240230 } catch (const std::exception &e) {
@@ -249,19 +239,23 @@ AuthResult flashmq_plugin_login_check(void *thread_data, const std::string &clie
249239}
250240
251241AuthResult flashmq_plugin_acl_check (void *thread_data, const AclAccess access, const std::string &clientid, const std::string &username,
252- const std::string &topic, const std::vector<std::string> &subtopics, std::string_view payload, const uint8_t qos,
253- const bool retain, const std::vector<std::pair<std::string, std::string>> *userProperties)
242+ const std::string &topic, const std::vector<std::string> &subtopics, const std::string &shareName,
243+ std::string_view payload, const uint8_t qos, const bool retain,
244+ const std::optional<std::string> &correlationData, const std::optional<std::string> &responseTopic,
245+ const std::vector<std::pair<std::string, std::string>> *userProperties)
254246{
255247 (void )thread_data;
256248 (void )access;
257249 (void )clientid;
258- (void )username;
259250 (void )subtopics;
260251 (void )qos;
261252 (void )(retain);
262253 (void )userProperties;
263254 (void )topic;
264255 (void )payload;
256+ (void )shareName;
257+ (void )correlationData;
258+ (void )responseTopic;
265259
266260 return AuthResult::success;
267261}
0 commit comments