--- a/ztfy/utils/security.py Tue Mar 02 23:34:55 2010 +0100
+++ b/ztfy/utils/security.py Tue Mar 02 23:35:23 2010 +0100
@@ -18,11 +18,14 @@
from persistent.dict import PersistentDict
# import Zope3 interfaces
+from zope.app.authentication.interfaces import IPrincipalInfo
# import local interfaces
# import Zope3 packages
from zc.set import Set
+from zope.app import zapi
+from zope.interface import implements
from zope.security.proxy import removeSecurityProxy
# import local packages
@@ -45,3 +48,27 @@
else:
result = removeSecurityProxy(value)
return result
+
+
+class MissingPrincipal(object):
+
+ implements(IPrincipalInfo)
+
+ def __init__(self, id):
+ self.id = id
+
+ @property
+ def title(self):
+ return _("< missing principal %s>") % self.id
+
+ @property
+ def description(self):
+ return _("This principal can't be found in any authentication utility...")
+
+
+def getPrincipal(uid):
+ principals = zapi.principals()
+ try:
+ return principals.getPrincipal(uid)
+ except:
+ return MissingPrincipal(uid)