[BUGFIX] Access security context only if it has been initialized

Entities create in CLI context don't have a proper security context initialized