Commit 341ef37b authored by mouadh's avatar mouadh

authentication exception

parent c53c45b9
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
from spyne import ComplexModel, Integer, String, Unicode, XmlAttribute from spyne import ComplexModel, Integer, Unicode, XmlAttribute
from spyne.model.fault import Fault
class Tuple(object): class Tuple(object):
...@@ -104,3 +104,9 @@ class DiscoverRequest(ComplexModel): ...@@ -104,3 +104,9 @@ class DiscoverRequest(ComplexModel):
RequestType = Unicode RequestType = Unicode
Restrictions = Restrictionlist Restrictions = Restrictionlist
Properties = Propertielist Properties = Propertielist
class AuthenticationError(Fault):
__namespace__ = 'spyne.examples.authentication'
faultcode='Client.AuthenticationError',
faultstring='Invalid authentication request'
...@@ -8,11 +8,12 @@ from os.path import expanduser ...@@ -8,11 +8,12 @@ from os.path import expanduser
from lxml import etree from lxml import etree
from spyne import AnyXml, Application, ServiceBase, rpc from spyne import AnyXml, Application, ServiceBase, rpc
from spyne.error import InvalidCredentialsError
from spyne.protocol.soap import Soap11 from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication from spyne.server.wsgi import WsgiApplication
from ..mdx.tools.config_file_parser import ConfigParser from ..mdx.tools.config_file_parser import ConfigParser
from ..services.models import DiscoverRequest, ExecuteRequest, Session from ..services.models import DiscoverRequest, ExecuteRequest, Session, AuthenticationError
from .xmla_discover_tools import XmlaDiscoverTools from .xmla_discover_tools import XmlaDiscoverTools
from .xmla_execute_tools import XmlaExecuteTools from .xmla_execute_tools import XmlaExecuteTools
from .xmla_execute_xsds import execute_xsd from .xmla_execute_xsds import execute_xsd
...@@ -36,10 +37,15 @@ class XmlaProviderService(ServiceBase): ...@@ -36,10 +37,15 @@ class XmlaProviderService(ServiceBase):
discover_tools = XmlaDiscoverTools() discover_tools = XmlaDiscoverTools()
SessionId = discover_tools.SessionId SessionId = discover_tools.SessionId
@rpc(DiscoverRequest, @rpc(DiscoverRequest,
_returns=AnyXml, _returns=AnyXml,
_body_style="bare", _body_style="bare",
_out_header=Session) _out_header=Session,
_throws=InvalidCredentialsError
# _throws=AuthenticationError
)
def Discover(ctx, request): def Discover(ctx, request):
""" """
the first principle function of xmla protocol the first principle function of xmla protocol
...@@ -60,15 +66,12 @@ class XmlaProviderService(ServiceBase): ...@@ -60,15 +66,12 @@ class XmlaProviderService(ServiceBase):
if config_parser.xmla_authentication(): if config_parser.xmla_authentication():
# TODO call labster login or create login with token (according to labster db) # TODO call labster login or create login with token (according to labster db)
if ctx.transport.req_env['QUERY_STRING'] != 'admin': if ctx.transport.req_env['QUERY_STRING'] != 'mouadh':
# TODO try to 'monkey-patch' spyne and change response function name so we can authentication error to user
return etree.fromstring(""" raise InvalidCredentialsError(fault_string='You do not have permission to access this resource',
<soap11env:Fault> fault_object=None)
<faultcode>soap11env:Server</faultcode>
<faultstring>Authentication failed</faultstring> # raise AuthenticationError()
<faultactor></faultactor>
</soap11env:Fault>
""")
if request.RequestType == "DISCOVER_DATASOURCES": if request.RequestType == "DISCOVER_DATASOURCES":
return discover_tools.discover_datasources_response() return discover_tools.discover_datasources_response()
...@@ -198,7 +201,7 @@ class XmlaProviderService(ServiceBase): ...@@ -198,7 +201,7 @@ class XmlaProviderService(ServiceBase):
xmla_tools.generate_slicer_axis(df), xmla_tools.generate_slicer_axis(df),
xmla_tools.generate_cell_data(df), xmla_tools.generate_cell_data(df),
datetime.now().strftime('%Y-%m-%dT%H:%M:%S')).replace( datetime.now().strftime('%Y-%m-%dT%H:%M:%S')).replace(
'&', '&amp;')) '&', '&amp;'))
# Problem: # Problem:
# An XML parser returns the error “xmlParseEntityRef: noname” # An XML parser returns the error “xmlParseEntityRef: noname”
...@@ -250,8 +253,8 @@ def start_server(write_on_file=False): ...@@ -250,8 +253,8 @@ def start_server(write_on_file=False):
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG) logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
logging.info("listening to http://127.0.0.1:8000/xmla") logging.info("listening to http://127.0.0.1:8000/xmla")
logging.info("wsdl is at: http://localhost:8000/xmla?wsdl") logging.info("wsdl is at: http://localhost:8000/xmla?wsdl")
# server = make_server('127.0.0.1', 8000, wsgi_application) server = make_server('127.0.0.1', 8000, wsgi_application)
server = make_server('192.168.101.139', 8000, wsgi_application) # server = make_server('192.168.101.139', 8000, wsgi_application)
server.serve_forever() server.serve_forever()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment