Authorization and authentication middleware for REST server