Package pulp :: Package server :: Package auth :: Module auth
[hide private]
[frames] | no frames]

Source Code for Module pulp.server.auth.auth

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  # 
 4  # Copyright © 2010 Red Hat, Inc. 
 5  # 
 6  # This software is licensed to you under the GNU General Public License, 
 7  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 8  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 9  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
10  # along with this software; if not, see 
11  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
12  # 
13  # Red Hat trademarks are not licensed under GPLv2. No permission is 
14  # granted to use or replicate Red Hat trademarks that are incorporated 
15  # in this software or its documentation. 
16   
17  import threading 
18   
19  from pulp.server.util import Singleton 
20   
21  # default system principal ---------------------------------------------------- 
22   
23 -class SystemPrincipal(object):
24 """ 25 Class representing the default "system" principal. 26 """ 27 __metaclass__ = Singleton 28
29 - def __unicode__(self):
30 return u'SYSTEM'
31 32 # thread-local storage for holding the current principal ---------------------- 33 34 _storage = threading.local() 35 36 # principal api --------------------------------------------------------------- 37
38 -def set_principal(principal):
39 """ 40 Set the current principal (user) of the system. 41 @param principal: current system user 42 """ 43 _storage.principal = principal
44 45
46 -def get_principal():
47 """ 48 Get the current principal (user) of the system. 49 50 @return: current principal 51 @rtype: pulp.server.db.model.User instance if one was specified in set_principal; 52 pulp.server.auth.auth.SystemPrincipal otherwise 53 """ 54 if not hasattr(_storage, 'principal'): 55 _storage.principal = SystemPrincipal() 56 return _storage.principal
57 58
59 -def clear_principal():
60 """ 61 Clear the current principal (user) of the system. 62 This resets the principal to a "system" default. 63 """ 64 _storage.principal = SystemPrincipal()
65