Changeset 2263

Show
Ignore:
Timestamp:
05/27/07 00:11:55 (2 years ago)
Author:
coderanger
Message:

ModAuthAcctmgrScript:

Trying to add an authz handler too.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modauthacctmgrscript/0.9/mod_auth_acctmgr/handler.py

    r1257 r2263  
    44from mod_python import apache 
    55from trac.web.main import _open_environment 
     6from trac.perm import PermissionSystem 
    67 
    78acct_mgr = None 
    89 
    9 def authenhandler(req): 
    10     global acct_mgr 
    11     pw = req.get_basic_auth_pw() 
    12     user = req.user 
    13      
     10def _get_env(req): 
     11    """Get the Environment object for a request.""" 
    1412    # Find the env_path from the Apache config 
    1513    options = req.get_options() 
    1614    if 'TracEnv' not in options: 
    1715        print 'Must specify a Trac environment' 
    18         return apache.HTTP_FORBIDDEN 
     16        return None 
    1917    env_path = options['TracEnv'] 
    2018 
    21     # Try loading the env from the global cache, addit it if needed 
    22     env = _open_environment(env_path) 
    23      
     19    # Try loading the env from the global cache, add it it if needed 
     20    return _open_environment(env_path) 
     21 
     22def authenhandler(req): 
     23    pw = req.get_basic_auth_pw() 
     24    user = req.user 
     25 
     26    env = _get_env(req) 
     27    if env is None: 
     28        return apache.HTTP_FORBIDDEN 
     29 
     30    global acct_mgr 
    2431    if acct_mgr is None: 
    2532        from acct_mgr.api import AccountManager 
     
    3138        return apache.HTTP_UNAUTHORIZED 
    3239 
     40def authzhandler(req): 
     41    user = req.user 
     42     
     43    env = _get_env(req) 
     44    if env is None: 
     45        return apache.DECLINED 
     46         
     47    options = req.get_options() 
     48    if 'TracPerm' not in options: 
     49        print 'You must specify a permission' 
     50        return apache.DECLINED 
     51    perm = options['TracPerm'] 
     52     
     53    user_perms = PermissionSystem(self.env).get_user_permissions(user) 
     54    if user_perms.get(perm): 
     55        return apache.OK 
     56    else: 
     57        return apache.DECLINED 
     58     
  • modauthacctmgrscript/0.9/mod_auth_acctmgr/__init__.py

    r1108 r2263  
     1from handler import * 
  • modauthacctmgrscript/0.9/setup.py

    r1108 r2263  
    99    packages = ['mod_auth_acctmgr'], 
    1010    #package_data={ 'mod_auth_acctmgr' : [ ] }, 
     11     
    1112    author = "Noah Kantrowitz", 
    1213    author_email = "coderanger@yahoo.com", 
     
    1718    url = "http://trac-hacks.org/wiki/ModAuthAcctmgrScript", 
    1819    zip_safe = False, 
     20     
     21    classifiers = [ 
     22        'Framework :: Trac', 
     23    ], 
     24     
     25    install_requires = ['TracAccountManager'], 
     26 
     27    entry_points = { 
     28        'trac.plugins': [ 
     29            'mod_auth_acctmgr.perms = mod_auth_acctmgr.perms', 
     30        ] 
     31    }, 
    1932)