REST Security and General Improvements

Commit message for details.
Sorry for the rather large single commit.