コード例 #1
0
class OpenSSOBackend:
    """
    Authenticate against OpenSSO.

    """
    def __init__(self, ):
        self.opensso = RestInterface(
            opensso_url=getattr(settings, 'LOGIN_URL', ''))

    def authenticate(self, tokenid=None):

        is_authenticated = self.opensso.isTokenValid(tokenid)

        if is_authenticated:
            username = self.opensso.attributes(attributes_names=getattr(
                settings, 'OPENSSO_USER_ID_NAME', 'uid'),
                                               subjectid=tokenid)
            return User.objects.get(username=username)

        return None

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None
コード例 #2
0
 def wrapper(request, *args, **kwargs):
     if request.user.is_authenticated():
         return f(request, *args, **kwargs)
     else:
         ri = RestInterface(opensso_url=login_url)
         cookie_name = ri.getCookieNameForToken()
         if cookie_name in request.COOKIES:
             user = authenticate(tokenid=request.COOKIES[cookie_name])
             if user is not None:
                 if user.is_active:
                     login(request, user)
                     return f(request, *args, **kwargs)
                 else:
                     # return disabled account page
                     pass
             else:
                 # Return an 'invalid login' error message.
                 pass
     path = urlquote(''.join(('http://', request.get_host(), request.get_full_path())))
     tup = getattr(settings, 'LOGIN_URL_EXTERNAL', ''), redirect_field_name, path
     return redirect('%s?%s=%s' % tup)
コード例 #3
0
 def wrapper(request, *args, **kwargs):
     if request.user.is_authenticated():
         return f(request, *args, **kwargs)
     else:
         ri = RestInterface(opensso_url=login_url)
         cookie_name = ri.getCookieNameForToken()
         if cookie_name in request.COOKIES:
             user = authenticate(tokenid=request.COOKIES[cookie_name])
             if user is not None:
                 if user.is_active:
                     login(request, user)
                     return f(request, *args, **kwargs)
                 else:
                     # return disabled account page
                     pass
             else:
                 # Return an 'invalid login' error message.
                 pass
     path = urlquote(''.join(
         ('http://', request.get_host(), request.get_full_path())))
     tup = getattr(settings, 'LOGIN_URL_EXTERNAL',
                   ''), redirect_field_name, path
     return redirect('%s?%s=%s' % tup)
コード例 #4
0
class OpenSSOBackend:
    """
    Authenticate against OpenSSO.

    """

    def __init__(self, ):
        self.opensso = RestInterface(opensso_url=getattr(settings, 'LOGIN_URL', ''))

    def authenticate(self, tokenid=None):

        is_authenticated = self.opensso.isTokenValid(tokenid)

        if is_authenticated:
            username = self.opensso.attributes(attributes_names=getattr(settings, 'OPENSSO_USER_ID_NAME', 'uid'), subjectid=tokenid)
            return User.objects.get(username=username)

        return None

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None
コード例 #5
0
 def __init__(self, ):
     self.opensso = RestInterface(opensso_url=getattr(settings, 'LOGIN_URL', ''))
コード例 #6
0
 def __init__(self, ):
     self.opensso = RestInterface(
         opensso_url=getattr(settings, 'LOGIN_URL', ''))