Copy over riak_core_security from develop and reinstate some previous fixes.