Stefan's Security Manager subsystem

Passes tests, ready for upstream.