<p>Thankyou for pointing that out Uli, I knew root[&#39;myapp&#39;].getSiteManager()... must have been a bit hackish even if outside the webapp context.</p>
<p>I will change my offline code to use the setSite method.</p>
<div class="gmail_quote">On Jan 30, 2012 9:43 AM, &quot;Uli Fouquet&quot; &lt;<a href="mailto:uli@gnufix.de">uli@gnufix.de</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Matt,<br>
<br>
Am Montag, den 30.01.2012, 00:25 +0000 schrieb Matt Rutherford:<br>
&gt; I implemented (with a few edits for latest Grok version) my own PAU as<br>
&gt; a LocalUtility according to the end of Chapter 7 in the Grok web dev<br>
&gt; book. I&#39;d like to base my app model around the user Account object<br>
&gt; detailed here, which is stored in the UserFolder container object that<br>
&gt; itself is an attribute of my authenticator plugin LocalUtility. But<br>
&gt; looking for these objects in the ZODB I cannot find it under my<br>
&gt; toplevel App object. I can see the<br>
&gt; &#39;grokcore.site.directive.local_utility&#39; attribute and from this can<br>
&gt; get a grokcore.site.directive.LocalUtilityInfo object which gives some<br>
&gt; properties of the authenticator plugin that I want to access but not<br>
&gt; the underlying model.<br>
<br>
These grokcore.site... attributes are normally only helpers for grok to<br>
setup local utils when you add a grok.Application (aka<br>
grokcore.site.Site) instance to your ZODB. You shouldn&#39;t have to fiddle<br>
around with them under normal circumstances.<br>
<br>
During a request (i.e. from inside a view/viewlet/etc.) you can then do<br>
something like this (I will start with looking up a PAU as this is often<br>
asked)::<br>
<br>
  from zope.component import getUtility<br>
  from zope.authentication.interfaces import IAuthentication<br>
  mypau = getUtility(IAuthentication)<br>
<br>
This works, because during a request the Zope publisher sets the &#39;site&#39;<br>
according to the requested object.<br>
<br>
Sample: when requesting &#39;<a href="http://localhost:8080/myapp/item/@@index" target="_blank">http://localhost:8080/myapp/item/@@index</a>&#39;, for<br>
this request &#39;myapp&#39; will be set as site if it is a grok.Application or<br>
grokcore.site.Site instance.<br>
<br>
If you then ask for a utility, the machinery will first lookup &#39;local&#39;<br>
ones (i.e. ones registered with your site or application) and only<br>
proceed to the global registry if it cannot find the requested<br>
utility/adapter in the site.<br>
<br>
&gt; How should I access my authenticator plugin and it&#39;s UserFolder<br>
&gt; attribute from my bin/python-console prompt?<br>
<br>
If you&#39;re not &#39;in a site&#39; (for instance in the console or in a test),<br>
you can also set the site manually and then proceed in the usual way::<br>
<br>
  from zope.component import getUtility<br>
  from zope.component.hooks import setSite<br>
  from zope.authentication.interfaces import IAuthentication<br>
  setSite(myapp)<br>
  mypau = getUtility(IAuthentication)<br>
<br>
where &#39;myapp&#39; of course has to be a grok.Application or Site instance<br>
_already stored in the ZODB_. In the console something like::<br>
<br>
  myapp = root[&#39;myapp&#39;]<br>
<br>
will give you that (if you created some application called &#39;myapp&#39;<br>
before).<br>
<br>
In tests you can normally do the same except that here you normally have<br>
to create the Application instance first and store it in the ZODB::<br>
<br>
  myapp = MyApp()<br>
  getRootFolder()[&#39;myapp&#39;] = MyApp()<br>
  myapp = getRootFolder()[&#39;myapp&#39;]<br>
  setSite(myapp)<br>
  mypau = getUtility(IAuthentication)<br>
<br>
All that was about PluggableAuthenticationUtilities (PAUs). But you can<br>
retrieve all locally registered authenticators and the like accordingly.<br>
Just change the interface and additionally ask for a name::<br>
<br>
  from zope.component import getUtility<br>
  from zope.component.hooks import setSite<br>
  from zope.pluggableauth.interfaces import IAuthenticatorPlugin<br>
  setSite(myapp)<br>
  myauthplugin = getUtility(IAuthenticatorPlugin, name=&#39;users&#39;)<br>
<br>
This should give you the local authenticator, given it was registered<br>
locally (not globally) under the name ``users`` (see the <a href="http://grok.name" target="_blank">grok.name</a>()<br>
directive in your authenticator definition).<br>
<br>
The other samples above should work with authenticators and similar as<br>
well when passing the correct interface and name. The trick, overall, is<br>
to set the site correctly before doing the utility lookup.<br>
<br>
Hope that helps,<br>
<br>
--<br>
Uli<br>
<br>
<br>
</blockquote></div>