"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "keystone/api/os_federation.py" between
keystone-16.0.1.tar.gz and keystone-17.0.0.tar.gz

About: OpenStack Keystone (Core Service: Identity) provides an authentication and authorization service for other OpenStack services. Provides a catalog of endpoints for all OpenStack services.
The "Ussuri" series (latest release).

os_federation.py  (keystone-16.0.1):os_federation.py  (keystone-17.0.0)
skipping to change at line 17 skipping to change at line 17
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# This file handles all flask-restful resources for /v3/OS-FEDERATION # This file handles all flask-restful resources for /v3/OS-FEDERATION
import flask import flask
import flask_restful import flask_restful
import http.client
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from six.moves import http_client
from keystone.api._shared import authentication from keystone.api._shared import authentication
from keystone.api._shared import json_home_relations from keystone.api._shared import json_home_relations
from keystone.common import provider_api from keystone.common import provider_api
from keystone.common import rbac_enforcer from keystone.common import rbac_enforcer
from keystone.common import render_token from keystone.common import render_token
from keystone.common import validation from keystone.common import validation
import keystone.conf import keystone.conf
from keystone import exception from keystone import exception
from keystone.federation import schema from keystone.federation import schema
skipping to change at line 72 skipping to change at line 72
@staticmethod @staticmethod
def _add_related_links(ref): def _add_related_links(ref):
# Do Nothing, This is in support of child class mechanisms. # Do Nothing, This is in support of child class mechanisms.
pass pass
class IdentityProvidersResource(_ResourceBase): class IdentityProvidersResource(_ResourceBase):
collection_key = 'identity_providers' collection_key = 'identity_providers'
member_key = 'identity_provider' member_key = 'identity_provider'
api_prefix = '/OS-FEDERATION' api_prefix = '/OS-FEDERATION'
_public_parameters = frozenset(['id', 'enabled', 'description', _public_parameters = frozenset(['id', 'enabled', 'description',
'remote_ids', 'links', 'domain_id' 'remote_ids', 'links', 'domain_id',
'authorization_ttl'
]) ])
_id_path_param_name_override = 'idp_id' _id_path_param_name_override = 'idp_id'
@staticmethod @staticmethod
def _add_related_links(ref): def _add_related_links(ref):
"""Add URLs for entities related with Identity Provider. """Add URLs for entities related with Identity Provider.
Add URLs pointing to: Add URLs pointing to:
- protocols tied to the Identity Provider - protocols tied to the Identity Provider
skipping to change at line 135 skipping to change at line 136
PUT /OS-FEDERATION/identity_providers/{idp_id} PUT /OS-FEDERATION/identity_providers/{idp_id}
""" """
ENFORCER.enforce_call(action='identity:create_identity_provider') ENFORCER.enforce_call(action='identity:create_identity_provider')
idp = self.request_body_json.get('identity_provider', {}) idp = self.request_body_json.get('identity_provider', {})
validation.lazy_validate(schema.identity_provider_create, validation.lazy_validate(schema.identity_provider_create,
idp) idp)
idp = self._normalize_dict(idp) idp = self._normalize_dict(idp)
idp.setdefault('enabled', False) idp.setdefault('enabled', False)
idp_ref = PROVIDERS.federation_api.create_idp( idp_ref = PROVIDERS.federation_api.create_idp(
idp_id, idp) idp_id, idp)
return self.wrap_member(idp_ref), http_client.CREATED return self.wrap_member(idp_ref), http.client.CREATED
def patch(self, idp_id): def patch(self, idp_id):
ENFORCER.enforce_call(action='identity:update_identity_provider') ENFORCER.enforce_call(action='identity:update_identity_provider')
idp = self.request_body_json.get('identity_provider', {}) idp = self.request_body_json.get('identity_provider', {})
validation.lazy_validate(schema.identity_provider_update, idp) validation.lazy_validate(schema.identity_provider_update, idp)
idp = self._normalize_dict(idp) idp = self._normalize_dict(idp)
idp_ref = PROVIDERS.federation_api.update_idp( idp_ref = PROVIDERS.federation_api.update_idp(
idp_id, idp) idp_id, idp)
return self.wrap_member(idp_ref) return self.wrap_member(idp_ref)
def delete(self, idp_id): def delete(self, idp_id):
ENFORCER.enforce_call(action='identity:delete_identity_provider') ENFORCER.enforce_call(action='identity:delete_identity_provider')
PROVIDERS.federation_api.delete_idp(idp_id) PROVIDERS.federation_api.delete_idp(idp_id)
return None, http_client.NO_CONTENT return None, http.client.NO_CONTENT
class _IdentityProvidersProtocolsResourceBase(_ResourceBase): class _IdentityProvidersProtocolsResourceBase(_ResourceBase):
collection_key = 'protocols' collection_key = 'protocols'
member_key = 'protocol' member_key = 'protocol'
_public_parameters = frozenset(['id', 'mapping_id', 'links']) _public_parameters = frozenset(['id', 'mapping_id', 'links'])
json_home_additional_parameters = { json_home_additional_parameters = {
'idp_id': IDP_ID_PARAMETER_RELATION} 'idp_id': IDP_ID_PARAMETER_RELATION}
json_home_collection_resource_name_override = 'identity_provider_protocols' json_home_collection_resource_name_override = 'identity_provider_protocols'
json_home_member_resource_name_override = 'identity_provider_protocol' json_home_member_resource_name_override = 'identity_provider_protocol'
skipping to change at line 213 skipping to change at line 214
"""Create protocol for an IDP. """Create protocol for an IDP.
PUT /OS-Federation/identity_providers/{idp_id}/protocols/{protocol_id} PUT /OS-Federation/identity_providers/{idp_id}/protocols/{protocol_id}
""" """
ENFORCER.enforce_call(action='identity:create_protocol') ENFORCER.enforce_call(action='identity:create_protocol')
protocol = self.request_body_json.get('protocol', {}) protocol = self.request_body_json.get('protocol', {})
validation.lazy_validate(schema.protocol_create, protocol) validation.lazy_validate(schema.protocol_create, protocol)
protocol = self._normalize_dict(protocol) protocol = self._normalize_dict(protocol)
ref = PROVIDERS.federation_api.create_protocol(idp_id, protocol_id, ref = PROVIDERS.federation_api.create_protocol(idp_id, protocol_id,
protocol) protocol)
return self.wrap_member(ref), http_client.CREATED return self.wrap_member(ref), http.client.CREATED
def patch(self, idp_id, protocol_id): def patch(self, idp_id, protocol_id):
"""Update protocol for an IDP. """Update protocol for an IDP.
PATCH /OS-FEDERATION/identity_providers/ PATCH /OS-FEDERATION/identity_providers/
{idp_id}/protocols/{protocol_id} {idp_id}/protocols/{protocol_id}
""" """
ENFORCER.enforce_call(action='identity:update_protocol') ENFORCER.enforce_call(action='identity:update_protocol')
protocol = self.request_body_json.get('protocol', {}) protocol = self.request_body_json.get('protocol', {})
validation.lazy_validate(schema.protocol_update, protocol) validation.lazy_validate(schema.protocol_update, protocol)
skipping to change at line 236 skipping to change at line 237
return self.wrap_member(ref) return self.wrap_member(ref)
def delete(self, idp_id, protocol_id): def delete(self, idp_id, protocol_id):
"""Delete a protocol from an IDP. """Delete a protocol from an IDP.
DELETE /OS-FEDERATION/identity_providers/ DELETE /OS-FEDERATION/identity_providers/
{idp_id}/protocols/{protocol_id} {idp_id}/protocols/{protocol_id}
""" """
ENFORCER.enforce_call(action='identity:delete_protocol') ENFORCER.enforce_call(action='identity:delete_protocol')
PROVIDERS.federation_api.delete_protocol(idp_id, protocol_id) PROVIDERS.federation_api.delete_protocol(idp_id, protocol_id)
return None, http_client.NO_CONTENT return None, http.client.NO_CONTENT
class MappingResource(_ResourceBase): class MappingResource(_ResourceBase):
collection_key = 'mappings' collection_key = 'mappings'
member_key = 'mapping' member_key = 'mapping'
api_prefix = '/OS-FEDERATION' api_prefix = '/OS-FEDERATION'
def get(self, mapping_id=None): def get(self, mapping_id=None):
if mapping_id is not None: if mapping_id is not None:
return self._get_mapping(mapping_id) return self._get_mapping(mapping_id)
return self._list_mappings() return self._list_mappings()
skipping to change at line 276 skipping to change at line 277
"""Create a mapping. """Create a mapping.
PUT /OS-FEDERATION/mappings/{mapping_id} PUT /OS-FEDERATION/mappings/{mapping_id}
""" """
ENFORCER.enforce_call(action='identity:create_mapping') ENFORCER.enforce_call(action='identity:create_mapping')
mapping = self.request_body_json.get('mapping', {}) mapping = self.request_body_json.get('mapping', {})
mapping = self._normalize_dict(mapping) mapping = self._normalize_dict(mapping)
utils.validate_mapping_structure(mapping) utils.validate_mapping_structure(mapping)
mapping_ref = PROVIDERS.federation_api.create_mapping( mapping_ref = PROVIDERS.federation_api.create_mapping(
mapping_id, mapping) mapping_id, mapping)
return self.wrap_member(mapping_ref), http_client.CREATED return self.wrap_member(mapping_ref), http.client.CREATED
def patch(self, mapping_id): def patch(self, mapping_id):
"""Update a mapping. """Update a mapping.
PATCH /OS-FEDERATION/mappings/{mapping_id} PATCH /OS-FEDERATION/mappings/{mapping_id}
""" """
ENFORCER.enforce_call(action='identity:update_mapping') ENFORCER.enforce_call(action='identity:update_mapping')
mapping = self.request_body_json.get('mapping', {}) mapping = self.request_body_json.get('mapping', {})
mapping = self._normalize_dict(mapping) mapping = self._normalize_dict(mapping)
utils.validate_mapping_structure(mapping) utils.validate_mapping_structure(mapping)
skipping to change at line 298 skipping to change at line 299
mapping_id, mapping) mapping_id, mapping)
return self.wrap_member(mapping_ref) return self.wrap_member(mapping_ref)
def delete(self, mapping_id): def delete(self, mapping_id):
"""Delete a mapping. """Delete a mapping.
DELETE /OS-FEDERATION/mappings/{mapping_id} DELETE /OS-FEDERATION/mappings/{mapping_id}
""" """
ENFORCER.enforce_call(action='identity:delete_mapping') ENFORCER.enforce_call(action='identity:delete_mapping')
PROVIDERS.federation_api.delete_mapping(mapping_id) PROVIDERS.federation_api.delete_mapping(mapping_id)
return None, http_client.NO_CONTENT return None, http.client.NO_CONTENT
class ServiceProvidersResource(_ResourceBase): class ServiceProvidersResource(_ResourceBase):
collection_key = 'service_providers' collection_key = 'service_providers'
member_key = 'service_provider' member_key = 'service_provider'
_public_parameters = frozenset(['auth_url', 'id', 'enabled', 'description', _public_parameters = frozenset(['auth_url', 'id', 'enabled', 'description',
'links', 'relay_state_prefix', 'sp_url']) 'links', 'relay_state_prefix', 'sp_url'])
_id_path_param_name_override = 'sp_id' _id_path_param_name_override = 'sp_id'
api_prefix = '/OS-FEDERATION' api_prefix = '/OS-FEDERATION'
def get(self, sp_id=None): def get(self, sp_id=None):
skipping to change at line 348 skipping to change at line 349
PUT /OS-FEDERATION/service_providers/{sp_id} PUT /OS-FEDERATION/service_providers/{sp_id}
""" """
ENFORCER.enforce_call(action='identity:create_service_provider') ENFORCER.enforce_call(action='identity:create_service_provider')
sp = self.request_body_json.get('service_provider', {}) sp = self.request_body_json.get('service_provider', {})
validation.lazy_validate(schema.service_provider_create, sp) validation.lazy_validate(schema.service_provider_create, sp)
sp = self._normalize_dict(sp) sp = self._normalize_dict(sp)
sp.setdefault('enabled', False) sp.setdefault('enabled', False)
sp.setdefault('relay_state_prefix', sp.setdefault('relay_state_prefix',
CONF.saml.relay_state_prefix) CONF.saml.relay_state_prefix)
sp_ref = PROVIDERS.federation_api.create_sp(sp_id, sp) sp_ref = PROVIDERS.federation_api.create_sp(sp_id, sp)
return self.wrap_member(sp_ref), http_client.CREATED return self.wrap_member(sp_ref), http.client.CREATED
def patch(self, sp_id): def patch(self, sp_id):
"""Update a service provider. """Update a service provider.
PATCH /OS-FEDERATION/service_providers/{sp_id} PATCH /OS-FEDERATION/service_providers/{sp_id}
""" """
ENFORCER.enforce_call(action='identity:update_service_provider') ENFORCER.enforce_call(action='identity:update_service_provider')
sp = self.request_body_json.get('service_provider', {}) sp = self.request_body_json.get('service_provider', {})
validation.lazy_validate(schema.service_provider_update, sp) validation.lazy_validate(schema.service_provider_update, sp)
sp = self._normalize_dict(sp) sp = self._normalize_dict(sp)
sp_ref = PROVIDERS.federation_api.update_sp(sp_id, sp) sp_ref = PROVIDERS.federation_api.update_sp(sp_id, sp)
return self.wrap_member(sp_ref) return self.wrap_member(sp_ref)
def delete(self, sp_id): def delete(self, sp_id):
"""Delete a service provider. """Delete a service provider.
DELETE /OS-FEDERATION/service_providers/{sp_id} DELETE /OS-FEDERATION/service_providers/{sp_id}
""" """
ENFORCER.enforce_call(action='identity:delete_service_provider') ENFORCER.enforce_call(action='identity:delete_service_provider')
PROVIDERS.federation_api.delete_sp(sp_id) PROVIDERS.federation_api.delete_sp(sp_id)
return None, http_client.NO_CONTENT return None, http.client.NO_CONTENT
class SAML2MetadataResource(flask_restful.Resource): class SAML2MetadataResource(flask_restful.Resource):
@ks_flask.unenforced_api @ks_flask.unenforced_api
def get(self): def get(self):
"""Get SAML2 metadata. """Get SAML2 metadata.
GET/HEAD /OS-FEDERATION/saml2/metadata GET/HEAD /OS-FEDERATION/saml2/metadata
""" """
metadata_path = CONF.saml.idp_metadata_path metadata_path = CONF.saml.idp_metadata_path
try: try:
with open(metadata_path, 'r') as metadata_handler: with open(metadata_path, 'r') as metadata_handler:
metadata = metadata_handler.read() metadata = metadata_handler.read()
except IOError as e: except IOError as e:
# Raise HTTP 500 in case Metadata file cannot be read. # Raise HTTP 500 in case Metadata file cannot be read.
raise exception.MetadataFileError(reason=e) raise exception.MetadataFileError(reason=e)
resp = flask.make_response(metadata, http_client.OK) resp = flask.make_response(metadata, http.client.OK)
resp.headers['Content-Type'] = 'text/xml' resp.headers['Content-Type'] = 'text/xml'
return resp return resp
class OSFederationAuthResource(flask_restful.Resource): class OSFederationAuthResource(flask_restful.Resource):
@ks_flask.unenforced_api @ks_flask.unenforced_api
def get(self, idp_id, protocol_id): def get(self, idp_id, protocol_id):
"""Authenticate from dedicated uri endpoint. """Authenticate from dedicated uri endpoint.
GET/HEAD /OS-FEDERATION/identity_providers/ GET/HEAD /OS-FEDERATION/identity_providers/
skipping to change at line 427 skipping to change at line 428
'methods': [protocol_id], 'methods': [protocol_id],
protocol_id: { protocol_id: {
'identity_provider': idp_id, 'identity_provider': idp_id,
'protocol': protocol_id 'protocol': protocol_id
}, },
} }
} }
token = authentication.authenticate_for_token(auth) token = authentication.authenticate_for_token(auth)
token_data = render_token.render_token_response_from_model(token) token_data = render_token.render_token_response_from_model(token)
resp_data = jsonutils.dumps(token_data) resp_data = jsonutils.dumps(token_data)
flask_resp = flask.make_response(resp_data, http_client.CREATED) flask_resp = flask.make_response(resp_data, http.client.CREATED)
flask_resp.headers['X-Subject-Token'] = token.id flask_resp.headers['X-Subject-Token'] = token.id
flask_resp.headers['Content-Type'] = 'application/json' flask_resp.headers['Content-Type'] = 'application/json'
return flask_resp return flask_resp
class OSFederationAPI(ks_flask.APIBase): class OSFederationAPI(ks_flask.APIBase):
_name = 'OS-FEDERATION' _name = 'OS-FEDERATION'
_import_name = __name__ _import_name = __name__
_api_url_prefix = '/OS-FEDERATION' _api_url_prefix = '/OS-FEDERATION'
resources = [] resources = []
resource_mapping = [ resource_mapping = [
 End of changes. 13 change blocks. 
12 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)