Auth flask conversion cleanup
* Superfluous call to setup token authentication has been removed from keystone.server.flask.core * Base SAML assertion function has been extracted from keystone.api.auth and moved to keystone.api._shared.saml Change-Id: Idfa62bf1aea81ef5b4c6f564397e6a0d3ae60417 Partial-Bug: #1776504
This commit is contained in:
parent
d97832e8e8
commit
54b6227c1f
|
@ -0,0 +1,54 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from keystone.common import provider_api
|
||||
import keystone.conf
|
||||
from keystone import exception
|
||||
from keystone.federation import idp as keystone_idp
|
||||
from keystone.federation import utils as federation_utils
|
||||
from keystone.i18n import _
|
||||
|
||||
|
||||
CONF = keystone.conf.CONF
|
||||
PROVIDERS = provider_api.ProviderAPIs
|
||||
|
||||
|
||||
def create_base_saml_assertion(auth):
|
||||
issuer = CONF.saml.idp_entity_id
|
||||
sp_id = auth['scope']['service_provider']['id']
|
||||
service_provider = PROVIDERS.federation_api.get_sp(sp_id)
|
||||
federation_utils.assert_enabled_service_provider_object(service_provider)
|
||||
sp_url = service_provider['sp_url']
|
||||
|
||||
token_id = auth['identity']['token']['id']
|
||||
token = PROVIDERS.token_provider_api.validate_token(token_id)
|
||||
|
||||
if not token.project_scoped:
|
||||
action = _('Use a project scoped token when attempting to create '
|
||||
'a SAML assertion')
|
||||
raise exception.ForbiddenAction(action=action)
|
||||
|
||||
subject = token.user['name']
|
||||
role_names = []
|
||||
for role in token.roles:
|
||||
role_names.append(role['name'])
|
||||
project = token.project['name']
|
||||
# NOTE(rodrigods): the domain name is necessary in order to distinguish
|
||||
# between projects and users with the same name in different domains.
|
||||
project_domain_name = token.project_domain['name']
|
||||
subject_domain_name = token.user_domain['name']
|
||||
|
||||
generator = keystone_idp.SAMLGenerator()
|
||||
response = generator.samlize_token(
|
||||
issuer, sp_url, subject, subject_domain_name,
|
||||
role_names, project, project_domain_name)
|
||||
return response, service_provider
|
|
@ -24,6 +24,7 @@ import werkzeug.exceptions
|
|||
|
||||
from keystone.api._shared import authentication
|
||||
from keystone.api._shared import json_home_relations
|
||||
from keystone.api._shared import saml
|
||||
from keystone.auth import schema as auth_schema
|
||||
from keystone.common import authorization
|
||||
from keystone.common import provider_api
|
||||
|
@ -55,38 +56,6 @@ def _combine_lists_uniquely(a, b):
|
|||
return a or b
|
||||
|
||||
|
||||
def _create_base_saml_assertion(auth):
|
||||
issuer = CONF.saml.idp_entity_id
|
||||
sp_id = auth['scope']['service_provider']['id']
|
||||
service_provider = PROVIDERS.federation_api.get_sp(sp_id)
|
||||
federation_utils.assert_enabled_service_provider_object(service_provider)
|
||||
sp_url = service_provider['sp_url']
|
||||
|
||||
token_id = auth['identity']['token']['id']
|
||||
token = PROVIDERS.token_provider_api.validate_token(token_id)
|
||||
|
||||
if not token.project_scoped:
|
||||
action = _('Use a project scoped token when attempting to create '
|
||||
'a SAML assertion')
|
||||
raise exception.ForbiddenAction(action=action)
|
||||
|
||||
subject = token.user['name']
|
||||
role_names = []
|
||||
for role in token.roles:
|
||||
role_names.append(role['name'])
|
||||
project = token.project['name']
|
||||
# NOTE(rodrigods): the domain name is necessary in order to distinguish
|
||||
# between projects and users with the same name in different domains.
|
||||
project_domain_name = token.project_domain['name']
|
||||
subject_domain_name = token.user_domain['name']
|
||||
|
||||
generator = keystone_idp.SAMLGenerator()
|
||||
response = generator.samlize_token(
|
||||
issuer, sp_url, subject, subject_domain_name,
|
||||
role_names, project, project_domain_name)
|
||||
return response, service_provider
|
||||
|
||||
|
||||
def _build_response_headers(service_provider):
|
||||
# URLs in header are encoded into bytes
|
||||
return [('Content-Type', 'text/xml'),
|
||||
|
@ -424,7 +393,7 @@ class AuthFederationSaml2Resource(_AuthFederationWebSSOBase):
|
|||
"""
|
||||
auth = self.request_body_json.get('auth')
|
||||
validation.lazy_validate(federation_schema.saml_create, auth)
|
||||
response, service_provider = _create_base_saml_assertion(auth)
|
||||
response, service_provider = saml.create_base_saml_assertion(auth)
|
||||
headers = _build_response_headers(service_provider)
|
||||
response = flask.make_response(response.to_string(), http_client.OK)
|
||||
for header, value in headers:
|
||||
|
@ -444,7 +413,8 @@ class AuthFederationSaml2ECPResource(_AuthFederationWebSSOBase):
|
|||
"""
|
||||
auth = self.request_body_json.get('auth')
|
||||
validation.lazy_validate(federation_schema.saml_create, auth)
|
||||
saml_assertion, service_provider = _create_base_saml_assertion(auth)
|
||||
saml_assertion, service_provider = saml.create_base_saml_assertion(
|
||||
auth)
|
||||
relay_state_prefix = service_provider['relay_state_prefix']
|
||||
|
||||
generator = keystone_idp.ECPGenerator()
|
||||
|
|
|
@ -84,6 +84,13 @@ class RBACEnforcer(object):
|
|||
# it to the a token response or dictionary before passing it to
|
||||
# oslo.policy for enforcement. This is because oslo.policy shouldn't
|
||||
# know how to deal with an internal object only used within keystone.
|
||||
#
|
||||
# TODO(morgan): Rework this to not need an explicit token render as
|
||||
# this is a generally poorly designed behavior. The enforcer should not
|
||||
# rely on a contract of the token's rendered JSON form. This likely
|
||||
# needs reworking of how we handle the context in oslo.policy. Until
|
||||
# this is reworked, it is not possible to merge the token render
|
||||
# function into keystone.api
|
||||
if 'token' in credentials:
|
||||
token_ref = render_token.render_token_response_from_model(
|
||||
credentials['token']
|
||||
|
|
|
@ -146,8 +146,6 @@ def initialize_application(name, post_log_configured_function=lambda: None,
|
|||
config_files = [dev_conf]
|
||||
|
||||
keystone.server.configure(config_files=config_files)
|
||||
# explicitly load auth configuration
|
||||
keystone.conf.auth.setup_authentication()
|
||||
|
||||
# Log the options used when starting if we're in debug mode...
|
||||
if CONF.debug:
|
||||
|
|
Loading…
Reference in New Issue