From 5d65089469f2afff07ca13261a85849215570fc0 Mon Sep 17 00:00:00 2001 From: Avan Thakkar Date: Thu, 26 Nov 2020 14:06:10 +0530 Subject: [PATCH] mgr/dashboard: SSO not working after REST API versioning Fixes: https://tracker.ceph.com/issues/48362 Signed-off-by: Avan Thakkar saml2: Fix versioning parameter for saml2 endpoints, including minor fix for endpoints with xml=true --- src/pybind/mgr/dashboard/controllers/__init__.py | 6 +++++- src/pybind/mgr/dashboard/controllers/saml2.py | 13 +++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/__init__.py b/src/pybind/mgr/dashboard/controllers/__init__.py index 5a7c165c658..2f3c186b952 100644 --- a/src/pybind/mgr/dashboard/controllers/__init__.py +++ b/src/pybind/mgr/dashboard/controllers/__init__.py @@ -702,7 +702,11 @@ class BaseController(object): if isinstance(ret, bytes): ret = ret.decode('utf-8') if xml: - cherrypy.response.headers['Content-Type'] = 'application/xml' + if version: + cherrypy.response.headers['Content-Type'] = \ + 'application/vnd.ceph.api.v{}+xml'.format(version) + else: + cherrypy.response.headers['Content-Type'] = 'application/xml' return ret.encode('utf8') if json_response: if version: diff --git a/src/pybind/mgr/dashboard/controllers/saml2.py b/src/pybind/mgr/dashboard/controllers/saml2.py index f53c7f0e1f6..76a7e193a9a 100644 --- a/src/pybind/mgr/dashboard/controllers/saml2.py +++ b/src/pybind/mgr/dashboard/controllers/saml2.py @@ -16,7 +16,7 @@ from .. import mgr from ..exceptions import UserDoesNotExist from ..services.auth import JwtManager from ..tools import prepare_url_prefix -from . import BaseController, Controller, Endpoint +from . import BaseController, Controller, Endpoint, allow_empty_body @Controller('/auth/saml2', secure=False) @@ -42,7 +42,8 @@ class Saml2(BaseController): except OneLogin_Saml2_Error: raise cherrypy.HTTPError(400, 'Single Sign-On is not configured.') - @Endpoint('POST', path="") + @Endpoint('POST', path="", version=None) + @allow_empty_body def auth_response(self, **kwargs): Saml2._check_python_saml() req = Saml2._build_req(self._request, kwargs) @@ -78,27 +79,27 @@ class Saml2(BaseController): 'reason': auth.get_last_error_reason() } - @Endpoint(xml=True) + @Endpoint(xml=True, version=None) def metadata(self): Saml2._check_python_saml() saml_settings = OneLogin_Saml2_Settings(mgr.SSO_DB.saml2.onelogin_settings) return saml_settings.get_sp_metadata() - @Endpoint(json_response=False) + @Endpoint(json_response=False, version=None) def login(self): Saml2._check_python_saml() req = Saml2._build_req(self._request, {}) auth = OneLogin_Saml2_Auth(req, mgr.SSO_DB.saml2.onelogin_settings) raise cherrypy.HTTPRedirect(auth.login()) - @Endpoint(json_response=False) + @Endpoint(json_response=False, version=None) def slo(self): Saml2._check_python_saml() req = Saml2._build_req(self._request, {}) auth = OneLogin_Saml2_Auth(req, mgr.SSO_DB.saml2.onelogin_settings) raise cherrypy.HTTPRedirect(auth.logout()) - @Endpoint(json_response=False) + @Endpoint(json_response=False, version=None) def logout(self, **kwargs): # pylint: disable=unused-argument Saml2._check_python_saml() -- 2.39.5