Adapting authenticator to better support of SSOs

This commit is contained in:
Adolfo Gómez 2012-07-23 13:34:09 +00:00
parent 713614a784
commit 503d03431c
4 changed files with 61 additions and 2 deletions

View File

@ -200,11 +200,18 @@ class Authenticator(Module):
Helper method to return callback url for self (authenticator).
This method will allow us to know where to do redirection in case
we need to use callback
we need to use callback for authentication
'''
from auth import authCallbackUrl
return authCallbackUrl(self.dbAuthenticator())
def infoUrl(self):
'''
Helper method to return info url for this authenticator
'''
from auth import authInfoUrl
return authInfoUrl(self.dbAuthenticator())
def searchUsers(self, pattern):
'''
If you provide this method, the user will be allowed to search users,
@ -364,6 +371,16 @@ class Authenticator(Module):
at login, but at future (from admin interface, at user editing for example)
'''
return None
def getInfo(self, parameters):
'''
This method is invoked whenever the authinfo url is invoked, with the name of the authenticator
If this is implemented, information returned by this will be shown via web.
:note: You can return here a single element or a list (or tuple), where first element will be content itself,
and second will be the content type (i.e. "text/plain").
'''
return None
def getRealName(self, username):
'''

View File

@ -169,6 +169,18 @@ def authCallbackUrl(authenticator):
from django.core.urlresolvers import reverse
return reverse('uds.web.views.authCallback', kwargs={'idAuth': authenticator.id})
def authInfoUrl(authenticator):
'''
Helper method, so we can get the info url for an authenticator
'''
from django.core.urlresolvers import reverse
if type(authenticator) is str:
name = authenticator
else:
name = authenticator.name
return reverse('uds.web.views.authInfo', kwargs={'authName': name})
def webLogin(request, response, user, password):
'''
Helper function to, once the user is authenticated, store the information at the user session.

View File

@ -58,6 +58,7 @@ urlpatterns = patterns('uds',
# Custom authentication callback
(r'^auth/(?P<idAuth>.+)', 'web.views.authCallback'),
(r'^authJava/(?P<idAuth>.+)/(?P<hasJava>.*)$', 'web.views.authJava'),
(r'^authinfo/?P<authName>.+)', 'web.views.authInfo'),
)

View File

@ -296,6 +296,35 @@ def authCallback(request, idAuth):
except Exception as e:
return errors.exceptionView(request, e)
def authInfo(request, authName):
'''
This url is provided so authenticators can provide info (such as SAML metadata)
This will invoke getInfo on requested authName. The search of the authenticator is done
by name, so it's easier to access from external sources
'''
from uds.core import auths
try:
authenticator = Authenticator.objects.get(name=authName)
authInstance = authenticator.getInstance()
if authInstance.getInfo == auths.Authenticator.getInfo:
raise Exception() # This authenticator do not provides info
params = request.GET.copy()
info = authInstance.getInfo(params)
if info is None:
raise Exception() # This auth do not provides info
if type(info) is list or type(info) is tuple:
return HttpResponse(info[0], content_type = info[1])
return HttpResponse(info)
except Exception:
return HttpResponse(_('Authenticator do not provides information'))
@webLoginRequired
@transformId