Fixes #3407: Prevent NPE when publishing event

Fixes #3407: Prevent NPE
I am working on a different fix . What I am planning to do is do not register an clientEndpoint to endpoints if it is not authenticated so that it will never have null principal. We can close this one.