Files
PrimAITE/src/primaite/simulator/domain/account.py

71 lines
1.8 KiB
Python
Raw Normal View History

2023-08-02 13:43:31 +01:00
"""User account simulation."""
from enum import Enum
2023-08-07 10:55:29 +01:00
from typing import Dict
2023-08-02 13:43:31 +01:00
from primaite import getLogger
from primaite.simulator.core import SimComponent
_LOGGER = getLogger(__name__)
class AccountType(Enum):
"""Whether the account is intended for a user to log in or for a service to use."""
2023-08-07 17:24:14 +01:00
SERVICE = 1
2023-08-02 13:43:31 +01:00
"Service accounts are used to grant permissions to software on nodes to perform actions"
2023-08-07 17:24:14 +01:00
USER = 2
2023-08-02 13:43:31 +01:00
"User accounts are used to allow agents to log in and perform actions"
class AccountStatus(Enum):
"""Whether the account is active."""
2023-08-07 17:24:14 +01:00
ENABLED = 1
DISABLED = 2
2023-08-02 13:43:31 +01:00
class PasswordPolicyLevel(Enum):
"""Complexity requirements for account passwords."""
2023-08-07 17:24:14 +01:00
LOW = 1
MEDIUM = 2
HIGH = 3
2023-08-02 13:43:31 +01:00
class Account(SimComponent):
"""User accounts."""
num_logons: int = 0
"The number of times this account was logged into since last reset."
num_logoffs: int = 0
"The number of times this account was logged out of since last reset."
num_group_changes: int = 0
"The number of times this account was moved in or out of an AccountGroup."
username: str
"Account username."
password: str
"Account password."
account_type: AccountType
"Account Type, currently this can be service account (used by apps) or user account."
2023-08-07 17:24:14 +01:00
status: AccountStatus = AccountStatus.DISABLED
2023-08-02 13:43:31 +01:00
2023-08-07 10:55:29 +01:00
def describe_state(self) -> Dict:
"""Describe state for agent observations."""
return super().describe_state()
def enable(self):
2023-08-02 13:43:31 +01:00
"""Set the status to enabled."""
2023-08-07 17:24:14 +01:00
self.status = AccountStatus.ENABLED
2023-08-02 13:43:31 +01:00
def disable(self):
2023-08-02 13:43:31 +01:00
"""Set the status to disabled."""
2023-08-07 17:24:14 +01:00
self.status = AccountStatus.DISABLED
2023-08-07 10:55:29 +01:00
def log_on(self) -> None:
"""TODO."""
self.num_logons += 1
def log_off(self) -> None:
"""TODO."""
self.num_logoffs += 1