Changeset 1103 for trunk/rp/trac
- Timestamp:
- 11/21/07 18:59:33 (14 months ago)
- Location:
- trunk/rp/trac/infocard_acct/0.11/infocard_acct
- Files:
-
- 1 added
- 4 modified
-
groups.py (modified) (4 diffs)
-
infocard/infocardlib.py (modified) (4 diffs)
-
session.py (added)
-
templates/infocard-session-detail.html (modified) (1 diff)
-
web_ui.py (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/rp/trac/infocard_acct/0.11/infocard_acct/groups.py
r1098 r1103 23 23 from trac.web.session import Session 24 24 25 class SessionGroupProvider(Component): 26 """ 27 Provides permission groups by evaluating what is stored on the session 28 Note, this doesn't change from invocation to invocation so often a cache 29 may be used. 30 """ 31 implements(IPermissionGroupProvider) 25 from session import SecTokenChangeListener 26 27 session_var_name = 'sec_groups' 28 29 class SecTokenGroups(Component): 30 """Using Policy to move items from the security token to the session as groups 31 evaluated once, then cleared from the cache on logout""" 32 33 implements(SecTokenChangeListener) 32 34 33 35 def __init__(self): … … 35 37 self.enabled = self.config.getbool('infocard_acct', 'groups', True) 36 38 if not self.enabled: 37 self.env.log.debug('Se ssionGroupProviderdisabled')39 self.env.log.debug('SecTokenGroups disabled') 38 40 return 39 41 gDefSets = self.config.getlist('infocard_acct', 'group_definitions') 40 42 for gDef in gDefSets: 41 43 gDef = gDef.strip() #remove any unsightly spaces 42 self.env.log.debug('SessionGroupProviderprocessing group definition : ' + gDef)44 # self.env.log.debug('SecTokenGroups processing group definition : ' + gDef) 43 45 groupRules = {} 44 46 groupRules['name'] = gDef … … 49 51 self.gDefs[gDef] = groupRules 50 52 53 def login(self, req, secToken): 54 """ on login set the parse the token and setup the sec_groups on the session""" 55 req.session[session_var_name] = '' 51 56 52 # IPermissionGroupProvider interface53 def get_permission_groups(self, username):54 """Return a list of names of the groups that the user with the specified55 name is a member of."""56 57 #since we don't have the session object we have to fake it58 session = {}59 60 try:61 db = self.env.get_db_cnx()62 cursor = db.cursor()63 cursor.execute("SELECT name,value FROM session_attribute "64 "WHERE sid=%s and authenticated=%s", (username, int(True)))65 for name, value in cursor:66 session[name] = value67 except Exception:68 pass69 70 # anonymous and authenticated groups are set with the default provider71 57 groups = [] 72 if not self.enabled or not self.gDefs.items() or not se ssion.items():73 return groups58 if not self.enabled or not self.gDefs.items() or not secToken: 59 return 74 60 75 61 for ruleName in self.gDefs.keys(): 76 62 rule = self.gDefs[ruleName] 77 #try:78 if self._does_rule_match(rule, session):79 values = self._evalute_rule(rule, session)80 if values:81 self.env.log.debug('SessionGroupProviderrule adds : '\82 + ','.join(values))83 groups.extend(values)84 if rule['exclusive']:85 self.env.log.debug('SessionGroupProviderexclusive rule fired: '+ ruleName)86 break87 #except Exception:88 # self.env.log.debug('SessionGroupProvidererror evaluating rule: %s' % (ruleName))63 try: 64 if self._does_rule_match(rule, session): 65 values = self._evalute_rule(rule, session) 66 if values: 67 self.env.log.debug('SecTokenGroups rule adds : '\ 68 + ','.join(values)) 69 groups.extend(values) 70 if rule['exclusive']: 71 self.env.log.debug('SecTokenGroups exclusive rule fired: '+ ruleName) 72 break 73 except Exception: 74 self.env.log.debug('SecTokenGroups error evaluating rule: %s' % (ruleName)) 89 75 90 76 if groups: 91 self.env.log.debug('Se ssionGroupProvidergroups: ' + ','.join(groups))77 self.env.log.debug('SecTokenGroups groups: ' + ','.join(groups)) 92 78 93 79 return groups 80 81 def logout(self, req): 82 """On logout we must cleanup the sec_groups variable""" 83 if req.session.has_key(session_var_name): 84 del req.session[session_var_name] 94 85 95 86 def _does_rule_match(self, rule, session): … … 115 106 return None 116 107 108 109 class SessionGroupProvider(Component): 110 """ 111 Provides permission groups by evaluating what is stored on the session 112 Note, this doesn't change from invocation to invocation so often a cache 113 may be used. 114 """ 115 implements(IPermissionGroupProvider) 116 117 # IPermissionGroupProvider interface 118 def get_permission_groups(self, username): 119 """Return a list of names of the groups that the user with the specified 120 name is a member of.""" 121 122 #since we don't have the session object we have to fake it 123 try: 124 db = self.env.get_db_cnx() 125 cursor = db.cursor() 126 cursor.execute("SELECT name,value FROM session_attribute " 127 "WHERE sid=%s and authenticated=%s and name=%s", (username, int(True), session_var_name)) 128 for name, value in cursor: 129 self.env.log.debug('SessionGroupProvider groups: ' + ','.join(value)) 130 return value.split(' ') 131 except Exception: 132 pass 133 134 return [] 135 -
trunk/rp/trac/infocard_acct/0.11/infocard_acct/infocard/infocardlib.py
r1098 r1103 359 359 try: 360 360 if nsDict[name]: 361 # self.eventLog.add_event("Ignoring multi-valued %s/%s : %s" \ 362 # % (ns, name, value), 363 # event.INFO, 'parse-assertions') 361 364 #TODO multivalued check 362 365 pass 363 else:364 nsDict[name] = value365 366 except Exception: 367 # self.eventLog.add_event("Adding %s/%s : %s" \ 368 # % (ns, name, value), 369 # event.INFO, 'parse-assertions') 366 370 nsDict[name] = value 367 371 except Exception: 372 # self.eventLog.add_event("First NS, adding %s/%s : %s" \ 373 # % (ns, name, value), 374 # event.INFO, 'parse-assertions') 368 375 self.assertions[ns] = {name:value} 369 376 … … 375 382 #is the identifier a URI or just a short name? 376 383 ns = None 377 claim = None384 claim = None 378 385 try: 379 s = identifier.rsplit('/', 1) 380 if s.items() > 1: 381 ns = s[0] 382 claim = s[-1] 386 if identifier: 387 s = identifier.rsplit('/', 1) 388 if len(s) > 1: 389 ns = s[0] 390 claim = s[-1] 383 391 except Exception: 384 392 claim = identifier … … 396 404 else: 397 405 claims[key] = nsDict[key] 398 break399 406 if claims.items(): 400 407 return claims … … 424 431 m = hashlib.md5() 425 432 signer = None 433 # ppid = self.getAssertion('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier') 426 434 ppid = self.getAssertion('privatepersonalidentifier') 427 435 if ppid: -
trunk/rp/trac/infocard_acct/0.11/infocard_acct/templates/infocard-session-detail.html
r1098 r1103 24 24 </thead> 25 25 <tbody> 26 <tr py:if="session.get('name')"> 27 <td><pre>Full Name</pre></td> 28 <td><pre>${session.get('name')}</pre></td> 29 </tr> 30 <tr py:if="session.get('email')"> 31 <td><pre>email</pre></td> 32 <td><pre>${session.get('email')}</pre></td> 33 </tr> 26 34 <div if="tok_meta is not None"> 27 35 <div py:for="key in tok_meta.rsplit(' ')"> -
trunk/rp/trac/infocard_acct/0.11/infocard_acct/web_ui.py
r1098 r1103 52 52 53 53 from association import AssociationManager 54 from session import SecTokenSessionModule 54 55 55 56 import infocard.xmlseclibs, infocard.infocardlib … … 67 68 68 69 implements(ITemplateProvider) 69 70 70 71 privateKey = '/' 71 72 privateKeyPassPhrase = '' … … 73 74 mandatoryClaims = ('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier',) 74 75 displayDebug = False 75 76 76 77 def __init__(self): 77 78 privateKey = PathOption('infocard_acct', 'private_key_path', '/') … … 82 83 privacyPolicyVer = Option('infocard_acct', 'privacy_version', '') 83 84 issuer = Option('infocard_acct', 'privacy_issuer', '') 84 85 85 86 self.privateKey = self.env.config['infocard_acct'].get('private_key_path') 86 87 self.requiredClaims = self.env.config['infocard_acct'].get('required_claims') … … 90 91 self.issuer = self.env.config['infocard_acct'].get('issuer') 91 92 self.displayDebug = self.config.getbool('infocard_acct', 'debug', False) 92 93 93 94 #append all hard coded mandatory claims to the required claims 94 95 rClaims = None … … 98 99 if not rClaims or not (claim in rClaims): 99 100 self.requiredClaims = self.requiredClaims + ' ' + claim 100 101 101 102 102 103 def authenticate(self, req): 103 104 #self.log.debug('web_ui:LoginModule:authenticate' ) … … 121 122 return True 122 123 123 if re.match(r'/iinfo/?$', req.path_info) is not None:124 return True125 126 124 return False 127 125 … … 130 128 if req.path_info.startswith('/logout'): 131 129 self._cleanup_session(req) 132 if req.path_info.startswith('/iinfo'):133 data = {134 'title': 'Infocard Session Debug',135 'session': req.session,136 'tok_claims': req.session.get('tok_claims'),137 'tok_meta': req.session.get('tok_meta')138 }139 return 'infocard-session-detail.html', data, None140 130 if req.path_info.startswith('/login'): 141 131 if req.authname == 'anonymous': … … 153 143 'submit_text': 'Login' 154 144 } 155 145 156 146 if not req.args.get('xmlToken') and not req.args.get('cardkeyhash'): 157 147 data['display_infocard'] = 'True' … … 173 163 data['events'] = secToken.eventLog.events 174 164 return 'infocard-detail.html', data, None 175 165 176 166 data['cardkeyhash'] = cardkeyhash 177 167 … … 194 184 data['events'] = secToken.eventLog.events 195 185 return 'infocard-detail.html', data, None 196 186 197 187 self.log.debug("%s", self.displayDebug) 198 188 self._setup_session(req) 199 189 return auth.LoginModule.process_request(self, req) 200 190 201 191 def _cleanup_session(self, req): 202 192 """We need to delete session attributes here 203 193 """ 204 pass194 SecTokenSessionModule(self.env).logout(req) 205 195 206 196 def _setup_session(self, req): … … 208 198 the infocard must be parsed and availible on this request 209 199 """ 210 secToken = self._get_token(req) 211 if secToken: 212 metaData = secToken.getMetaData() 213 if metaData: 214 tok_meta='' 215 for key in metaData.keys(): 216 req.session['tok_meta_'+key] = metaData[key] 217 tok_meta += ' tok_meta_'+key 218 req.session['tok_meta'] = tok_meta 219 #self.log.debug("tok_meta : %s", tok_meta) 220 claims = secToken.getAssertion() 221 if claims and claims.keys(): 222 tok_claims='' 223 for key in claims.keys(): 224 req.session['tok_claim_'+key] = claims[key] 225 tok_claims += ' tok_claim_'+key 226 req.session['tok_claims'] = tok_claims 227 #self.log.debug("tok_claims : %s", tok_claims) 200 SecTokenSessionModule(self.env).login(req, self._get_token(req)) 228 201 229 202 def _do_debug_login(self, req): … … 233 206 ignore_case = BoolOption('trac', 'ignore_auth_case', 'false', 234 207 """Whether case should be ignored for login names (''since 0.9'').""") 235 208 236 209 remote_user = req.remote_user 237 210 if self.ignore_case: … … 266 239 267 240 return processor 268 269 241 242 270 243 def _get_token(self, req): 271 244 """get the security token, cache it on the request so it isn't reparsed 272 245 """ 273 246 274 247 secToken = None 275 248 try: … … 336 309 337 310 # ITemplateProvider 338 311 339 312 def get_htdocs_dirs(self): 340 313 """Return the absolute path of a directory containing additional