Debian Codegraph @

keystoneclient/auth/identity/v3/federated.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 import abc
14
15 from oslo_config import cfg
16
17 from keystoneclient.auth.identity.v3 import base
18 from keystoneclient.auth.identity.v3 import token
19
20 __all__ = ('FederatedBaseAuth',)
21
22
23 class FederatedBaseAuth(base.BaseAuth, metaclass=abc.ABCMeta):
24
25 rescoping_plugin = token.Token
26
27 def __init__(self, auth_url, identity_provider, protocol, **kwargs):
28 """Class constructor for federated authentication plugins.
29
30 Accepting following parameters:
31
32 :param auth_url: URL of the Identity Service
33 :type auth_url: string
34 :param identity_provider: Name of the Identity Provider the client
35 will authenticate against. This parameter
36 will be used to build a dynamic URL used to
37 obtain unscoped OpenStack token.
38 :type identity_provider: string
39 :param protocol: Protocol name configured on the keystone service
40 provider side
41 :type protocol: string
42
43 """
44 super(FederatedBaseAuth, self).__init__(auth_url=auth_url, **kwargs)
45 self.identity_provider = identity_provider
46 self.protocol = protocol
47
48 @classmethod
49 def get_options(cls):
50 options = super(FederatedBaseAuth, cls).get_options()
51
52 options.extend([
53 cfg.StrOpt('identity-provider',
54 help="Identity Provider's name"),
55 cfg.StrOpt('protocol', help="Name of the federated protocol used "
56 "for federated authentication. Must "
57 "match its counterpart name "
58 "configured at the keystone service "
59 "provider. Typically values would be "
60 "'saml2' or 'oidc'.")
61 ])
62
63 return options
64
65 @property
66 def federated_token_url(self):
67 """Full URL where authorization data is sent."""
68 values = {
69 'host': self.auth_url.rstrip('/'),
70 'identity_provider': self.identity_provider,
71 'protocol': self.protocol
72 }
73 url = ("%(host)s/OS-FEDERATION/identity_providers/"
74 "%(identity_provider)s/protocols/%(protocol)s/auth")
75 url = url % values
76
77 return url
78
79 def _get_scoping_data(self):
80 return {'trust_id': self.trust_id,
81 'domain_id': self.domain_id,
82 'domain_name': self.domain_name,
83 'project_id': self.project_id,
84 'project_name': self.project_name,
85 'project_domain_id': self.project_domain_id,
86 'project_domain_name': self.project_domain_name}
87
88 def get_auth_ref(self, session, **kwargs):
89 """Authenticate retrieve token information.
90
91 This is a multi-step process where a client does federated authn
92 receives an unscoped token.
93
94 If an unscoped token is successfully received and scoping information
95 is present then the token is rescoped to that target.
96
97 :param session: a session object to send out HTTP requests.
98 :type session: keystoneclient.session.Session
99
100 :returns: a token data representation
101 :rtype: :py:class:`keystoneclient.access.AccessInfo`
102
103 """
104 auth_ref = self.get_unscoped_auth_ref(session)
105 scoping = self._get_scoping_data()
106
107 if any(scoping.values()):
108 token_plugin = self.rescoping_plugin(self.auth_url,
109 token=auth_ref.auth_token,
110 **scoping)
111
112 auth_ref = token_plugin.get_auth_ref(session)
113
114 return auth_ref
115
116 @abc.abstractmethod
117 def get_unscoped_auth_ref(self, session, **kwargs):
118 """Fetch unscoped federated token."""
119 pass # pragma: no cover