Ticket #4309: sage-4309_1.patch

File sage-4309_1.patch, 4.2 KB (added by TimothyClemans, 14 years ago)
  • sage/server/notebook/avatars.py

    # HG changeset patch
    # User Timothy Clemans <timothy.clemans@gmail.com>
    # Date 1226274485 21600
    # Node ID 91b58135cec80756572727af4d606b3fb863c8fe
    # Parent  67e0603ac89003d15b4c69257b0daad0f44db95f
    4309
    
    diff -r 67e0603ac890 -r 91b58135cec8 sage/server/notebook/avatars.py
    a b  
    99
    1010import crypt
    1111import os
    12 from   random import randint
     12from   random import randint, choice
    1313
    1414import twist
     15import kerberos
    1516from twisted.cred import portal, checkers, credentials, error as credError
    1617from twisted.internet import protocol, defer
    1718from zope.interface import Interface, implements
     
    8283        self.failure_type = failure_type
    8384
    8485class PasswordChecker(object):
     86    krb_data = []
    8587    implements(checkers.ICredentialsChecker)
    8688    credentialInterfaces = (credentials.IUsernamePassword,)
    8789
     
    103105        password = credentials.password
    104106        if username == 'COOKIESDISABLED':
    105107            return defer.succeed(FailedLogin(username, failure_type = 'cookies'))
    106        
     108
     109        if self.krb_data[0] and self.krb_data[1]:
     110            try:
     111                kerberos.checkPassword(username,password,
     112                                       self.krb_data[0], self.krb_data[1])
     113            except kerberos.BasicAuthError, e:
     114                krb_auth = False
     115            else:
     116                krb_auth = True   
     117
    107118        try:
    108119            U = twist.notebook.user(username)
    109120        except KeyError:
    110             return defer.succeed(FailedLogin(username, failure_type = 'user'))
    111 
    112         if U.password_is(password):
     121            if not krb_auth:
     122                return defer.succeed(FailedLogin(username, failure_type = 'user'))
     123            else:
     124                twist.notebook.add_user(username,"".join([choice("abcdef1234567890") for i in range(30)])
     125                                        ,"", account_type='user',force=True)
     126                return defer.succeed(username)
     127                   
     128        if U.password_is(password) or krb_auth:
    113129            return defer.succeed(username)
    114130        else:
    115131            return defer.succeed(FailedLogin(username,failure_type='password'))
  • sage/server/notebook/notebook_object.py

    diff -r 67e0603ac890 -r 91b58135cec8 sage/server/notebook/notebook_object.py
    a b  
    6666                         session terminates.  0 means `never timeout'.
    6767        server_pool   -- (default: None) list; this option specifies that
    6868                         worksheet processes run as a separate user (chosen
    69                          from the list in the server_pool -- see below).
     69                         from the list in the server_pool -- see below).
     70        krb_srv       -- specifies the kerberos service if kerberos authentification is used
     71        krb_realm     -- specifies the kerberos realm if kerberos authentification is used
    7072                     
    7173    \begin{verbatim}
    7274
  • sage/server/notebook/run_notebook.py

    diff -r 67e0603ac890 -r 91b58135cec8 sage/server/notebook/run_notebook.py
    a b  
    6161             sagetex_path = "",
    6262             start_path = "",
    6363             fork = False,
    64              quiet = False):
    65              
     64
     65             quiet = False,
     66
     67             krb_srv= None,
     68             krb_realm= None):
    6669    if directory is None:
    6770        directory = '%s/sage_notebook'%DOT_SAGE
    6871    else:
     
    221224startup_checker = avatars.OneTimeTokenChecker()
    222225startup_checker.token = startup_token
    223226p.registerChecker(startup_checker)
     227avatars.PasswordChecker.krb_data=%s
    224228password_checker = avatars.PasswordChecker()
    225229p.registerChecker(password_checker)
    226230p.registerChecker(checkers.AllowAnonymousAccess())
     
    239243reactor.addSystemEventTrigger('before', 'shutdown', save_notebook)
    240244
    241245"""%(notebook_opts, sagetex_path, not require_login,
    242      os.path.abspath(directory), strport, open_page))
     246     os.path.abspath(directory), [krb_srv,krb_realm], strport, open_page))
    243247
    244248
    245249        config.close()