'Authenticate user.'

def authenticate(self, request, auth_info, auth_context):

    if (not isinstance(auth_context, core.AuthContext)):
        LOG.error('`auth_context`    passed    to    the    Auth    controller    `authenticate`    method    is    not    of    type    `keystone.auth.controllers.AuthContext`.    For    security    purposes    this    is    required.    This    is    likely    a    programming    error.    Received    object    of    type    `%s`', type(auth_context))
        raise exception.Unauthorized(_('Cannot    Authenticate    due    to    internal    error.'))
    if request.remote_user:
        try:
            external = core.get_auth_method('external')
            resp = external.authenticate(request, auth_info)
            if (resp and resp.status):
                auth_context.setdefault('method_names', []).insert(0, 'external')
                auth_context.update((resp.response_data or {}))
        except exception.AuthMethodNotSupported:
            LOG.debug("No    'external'    plugin    is    registered.")
        except exception.Unauthorized:
            LOG.debug("Authorization    failed    for    'external'    auth    method.")
    auth_response = {'methods': []}
    for method_name in auth_info.get_method_names():
        method = core.get_auth_method(method_name)
        resp = method.authenticate(request, auth_info.get_method_data(method_name))
        if resp:
            if resp.status:
                auth_context.setdefault('method_names', []).insert(0, method_name)
                resp_method_names = resp.response_data.pop('method_names', [])
                auth_context['method_names'].extend(resp_method_names)
                auth_context.update((resp.response_data or {}))
            elif resp.response_body:
                auth_response['methods'].append(method_name)
                auth_response[method_name] = resp.response_body
    if auth_response['methods']:
        raise exception.AdditionalAuthRequired(auth_response)
    if ('user_id' not in auth_context):
        msg = _('User    not    found    by    auth    plugin;    authentication    failed')
        LOG.warning(msg)
        raise exception.Unauthorized(msg)
