[BUGFIX] Security context cannot always be used

There were some errors with too early accesses to the security context.
Therefore we now check first if it can be initialized and then use it
only if that's the case.