'Authenticate incoming request.'

def __call__(self, env, start_response):

    username = env.get('HTTP_X_AUTH_USER')
    password = env.get('HTTP_X_AUTH_KEY')
    tenant = env.get('PATH_INFO').split('/')[1]
    auth_url = env.get('HTTP_X_AUTH_URL')
    user_domain_id = env.get('HTTP_X_USER_DOMAIN_ID')
    if (not tenant):
        return self._reject_request(env, start_response, auth_url)
    try:
        ctx = context.RequestContext(username=username, password=password, tenant=tenant, auth_url=auth_url, user_domain_id=user_domain_id, is_admin=False)
        auth_ref = ctx.auth_plugin.get_access(self.session)
    except (keystone_exceptions.Unauthorized, keystone_exceptions.Forbidden, keystone_exceptions.NotFound, keystone_exceptions.AuthorizationFailure):
        return self._reject_request(env, start_response, auth_url)
    env.update(self._build_user_headers(auth_ref))
    return self.app(env, start_response)
