From bfad0256f8ce794dc95a5dcae7cd5173f6631bce Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 7 Oct 2021 14:54:30 -0400 Subject: [PATCH] Island: Remove UserStore --- .../cc/environment/environment_config.py | 2 -- monkey/monkey_island/cc/resources/auth/auth.py | 14 +++++--------- .../monkey_island/cc/resources/auth/user_store.py | 13 ------------- 3 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 monkey/monkey_island/cc/resources/auth/user_store.py diff --git a/monkey/monkey_island/cc/environment/environment_config.py b/monkey/monkey_island/cc/environment/environment_config.py index 916fdb239..7b3c26d4b 100644 --- a/monkey/monkey_island/cc/environment/environment_config.py +++ b/monkey/monkey_island/cc/environment/environment_config.py @@ -6,7 +6,6 @@ from typing import Dict from monkey_island.cc.environment.user_creds import UserCreds from monkey_island.cc.resources.auth.auth_user import User -from monkey_island.cc.resources.auth.user_store import UserStore class EnvironmentConfig: @@ -58,7 +57,6 @@ class EnvironmentConfig: def add_user(self, credentials: UserCreds): self.user_creds = credentials self.save_to_file() - UserStore.set_users([self.get_user()]) def get_user(self) -> User: auth_user = self.user_creds.to_auth_user() diff --git a/monkey/monkey_island/cc/resources/auth/auth.py b/monkey/monkey_island/cc/resources/auth/auth.py index 4e31778bf..3fab5ef66 100644 --- a/monkey/monkey_island/cc/resources/auth/auth.py +++ b/monkey/monkey_island/cc/resources/auth/auth.py @@ -8,7 +8,6 @@ from flask_jwt_extended.exceptions import JWTExtendedException from jwt import PyJWTError import monkey_island.cc.environment.environment_singleton as env_singleton -import monkey_island.cc.resources.auth.user_store as user_store from monkey_island.cc.resources.auth.credential_utils import ( get_username_password_from_request, password_matches_hash, @@ -19,7 +18,6 @@ logger = logging.getLogger(__name__) def init_jwt(app): - user_store.UserStore.set_users(env_singleton.env.get_auth_users()) _ = flask_jwt_extended.JWTManager(app) logger.debug( "Initialized JWT with secret key that started with " + app.config["JWT_SECRET_KEY"][:4] @@ -52,18 +50,16 @@ class Authenticate(flask_restful.Resource): def _credentials_match_registered_user(username: str, password: str) -> bool: - user = user_store.UserStore.username_table.get(username, None) + registered_user = env_singleton.env.get_auth_users() - if user and password_matches_hash(password, user.secret): - return True + if not registered_user: + return False - return False + return (registered_user.username == username) and password_matches_hash(password, registered_user[0].secret) def _create_access_token(username): - access_token = flask_jwt_extended.create_access_token( - identity=user_store.UserStore.username_table[username].id - ) + access_token = flask_jwt_extended.create_access_token(identity=username) logger.debug(f"Created access token for user {username} that begins with {access_token[:4]}") return access_token diff --git a/monkey/monkey_island/cc/resources/auth/user_store.py b/monkey/monkey_island/cc/resources/auth/user_store.py deleted file mode 100644 index 3c5217f57..000000000 --- a/monkey/monkey_island/cc/resources/auth/user_store.py +++ /dev/null @@ -1,13 +0,0 @@ -from typing import List - -from monkey_island.cc.resources.auth.auth_user import User - - -class UserStore: - users = [] - username_table = {} - - @staticmethod - def set_users(users: List[User]): - UserStore.users = users - UserStore.username_table = {u.username: u for u in UserStore.users}