Island: Remove UserStore

This commit is contained in:
Mike Salvatore 2021-10-07 14:54:30 -04:00
parent bb806522a1
commit bfad0256f8
3 changed files with 5 additions and 24 deletions

View File

@ -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()

View File

@ -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

View File

@ -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}