Openstack Keystone 认证流程(六)--认证

1. 身份认证

在前一章中, 介绍了路由的过程, 这样我们就能URL中轻易地找到所对应的需要执行的代码。在这一章中, 我们看看具体的一个认证请求是如何被处理的。

假设有如下一个请求:

$ curl -s -X POST http://8.21.28.222:35357/v2.0/tokens \
            -H "Content-Type: application/json" \
            -d '{"auth": {"tenantName": "'"$OS_TENANT_NAME"'", "passwordCredentials":
            {"username": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"}}}' \
            | python -m json.tool

从Keystone.paste.ini中/v2.0 = admin_api, 可以找出对应的流水线为admin_api, 然后找到流水线的最一个点如下:

[app:admin_service]
paste.app_factory = keystone.service:admin_app_factory

最后可以在token/routers可以找到如下一条路由:

from keystone.token import controllers
...
token_controller = controllers.Auth()
mapper.connect('/tokens',
               controller=token_controller,
               action='authenticate',
               conditions=dict(method=['POST']))

所以对应的controller为keystone.token.controllers.Auth, action为authenticate,找到对应的方法, 其代码如下:

def authenticate(self, context, auth=None):
        """Authenticate credentials and return a token.

        Accept auth as a dict that looks like::

            {
                "auth":{
                    "passwordCredentials":{
                        "username":"test_user",
                        "password":"mypass"
                    },
                    "tenantName":"customer-x"
                }
            }

        In this case, tenant is optional, if not provided the token will be
        considered "unscoped" and can later be used to get a scoped token.

        Alternatively, this call accepts auth with only a token and tenant
        that will return a token that is scoped to that tenant.
        """

        if auth is None:
            raise exception.ValidationError(attribute='auth',
                                            target='request body')

        auth_token_data = None

        if "token" in auth:
            # Try to authenticate using a token
            auth_info = self._authenticate_token(
                context, auth)
        else:
            # Try external authentication
            try:
                auth_info = self._authenticate_external(
  
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值