5
5
from flask_security import Security
6
6
7
7
from common import DIContainer
8
- from common .agent_events import AbstractAgentEvent , AgentShutdownEvent
9
- from common .event_queue import IAgentEventQueue
10
- from common .types import AgentID
11
- from monkey_island .cc .event_queue import IIslandEventQueue , IslandEventTopic
8
+ from monkey_island .cc .event_queue import IIslandEventQueue
12
9
from monkey_island .cc .server_utils .encryption import ILockableEncryptor
13
10
14
11
from . import IOTPGenerator
17
14
from .configure_flask_security import configure_flask_security
18
15
from .flask_resources import register_resources
19
16
from .mongo_otp_repository import MongoOTPRepository
17
+ from .register_event_handlers import register_event_handlers
20
18
from .token_generator import TokenGenerator
21
19
from .token_parser import TokenParser
22
20
@@ -28,7 +26,7 @@ def setup_authentication(api, app: Flask, container: DIContainer, data_dir: Path
28
26
otp_generator = AuthenticationServiceOTPGenerator (authentication_facade )
29
27
container .register_instance (IOTPGenerator , otp_generator )
30
28
31
- _register_event_handlers (container , authentication_facade )
29
+ register_event_handlers (container , authentication_facade )
32
30
register_resources (api , authentication_facade , otp_generator , limiter )
33
31
34
32
# revoke all old tokens so that the user has to log in again on startup
@@ -54,32 +52,3 @@ def _build_authentication_facade(container: DIContainer, security: Security):
54
52
token_parser ,
55
53
container .resolve (MongoOTPRepository ),
56
54
)
57
-
58
-
59
- def _register_event_handlers (container : DIContainer , authentication_facade : AuthenticationFacade ):
60
- agent_event_queue = container .resolve (IAgentEventQueue )
61
- island_event_queue = container .resolve (IIslandEventQueue )
62
-
63
- agent_event_queue .subscribe_type (
64
- AgentShutdownEvent , unregister_agent_on_shutdown (authentication_facade )
65
- )
66
- island_event_queue .subscribe (
67
- IslandEventTopic .AGENT_TIMED_OUT , unregister_agent_on_timeout (authentication_facade )
68
- )
69
-
70
-
71
- class unregister_agent_on_shutdown :
72
- def __init__ (self , authentication_facade : AuthenticationFacade ):
73
- self ._authentication_facade = authentication_facade
74
-
75
- def __call__ (self , event : AbstractAgentEvent ):
76
- agent_id = event .source
77
- self ._authentication_facade .remove_user (str (agent_id ))
78
-
79
-
80
- class unregister_agent_on_timeout :
81
- def __init__ (self , authentication_facade : AuthenticationFacade ):
82
- self ._authentication_facade = authentication_facade
83
-
84
- def __call__ (self , agent_id : AgentID ):
85
- self ._authentication_facade .remove_user (str (agent_id ))
0 commit comments