Hi, <div><br></div><div>I can not receive some mails from this mail list, though I can read them in the digest mail.</div><div>but it&#39;s really inconvenient to reply those ones.</div><div><br></div><div>Thanks</div><div>
--Shrek<br><br><div class="gmail_quote">On Thu, Nov 4, 2010 at 4:14 PM,  <span dir="ltr">&lt;<a href="mailto:grok-dev-request@zope.org">grok-dev-request@zope.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Send Grok-dev mailing list submissions to<br>
        <a href="mailto:grok-dev@zope.org">grok-dev@zope.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://mail.zope.org/mailman/listinfo/grok-dev" target="_blank">https://mail.zope.org/mailman/listinfo/grok-dev</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:grok-dev-request@zope.org">grok-dev-request@zope.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:grok-dev-owner@zope.org">grok-dev-owner@zope.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of Grok-dev digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
   1. Re: grok 1.2 and session based auth. (Shrek Zhou)<br>
   2. Re: grok 1.2 and session based auth. (Jan-Wijbrand Kolman)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Thu, 4 Nov 2010 09:49:12 +0800<br>
From: Shrek Zhou &lt;<a href="mailto:zgwmike@gmail.com">zgwmike@gmail.com</a>&gt;<br>
Subject: Re: [Grok-dev] grok 1.2 and session based auth.<br>
To: <a href="mailto:grok-dev@zope.org">grok-dev@zope.org</a><br>
Cc: <a href="mailto:cklinger@novareto.de">cklinger@novareto.de</a><br>
Message-ID:<br>
        &lt;<a href="mailto:AANLkTin66%2BCYTfkhVRGMVaVObFhzQKRQ6ggMoOV-p0p3@mail.gmail.com">AANLkTin66+CYTfkhVRGMVaVObFhzQKRQ6ggMoOV-p0p3@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;windows-1252&quot;<br>
<br>
To Christian,<br>
<br>
I can not found groupfolder.zcml in that folder under *<br>
.buildout/eggs/zope.pluggableauth-1.0.3-py2.6.egg/zope/pluggableauth/plugins/<br>
*<br>
<br>
i think you have to include zope.pluggableauth and this zcml-snippet:<br>
<br>
&lt;include package=&quot;zope.pluggableauth.plugins&quot; file=&quot;groupfolder.zcml&quot; /&gt;<br>
<br>
Maybe you can report if it works for you.<br>
Christian<br>
<br>
<br>
On Thu, Nov 4, 2010 at 9:30 AM, Shrek Zhou &lt;<a href="mailto:zgwmike@gmail.com">zgwmike@gmail.com</a>&gt; wrote:<br>
<br>
&gt; Hi, Jerrfey,<br>
&gt; I did that before I sent the mail. and I noticed that,<br>
&gt; in .buildout/eggs/zope.app.publication-3.12.0-py2.6.egg/zope/app/publication/zopepublication.py(89),<br>
&gt; the following func is called, which just get IAuthentication Utility from<br>
&gt; global site manager.<br>
&gt;<br>
&gt; def beforeTraversal(self, request):<br>
&gt;         notify(StartRequestEvent(request))<br>
&gt;         # Try to authenticate against the root authentication utility.<br>
&gt;         auth = zope.component.getGlobalSiteManager().getUtility(<br>
&gt;             zope.authentication.interfaces.IAuthentication)<br>
&gt;         principal = auth.authenticate(request)<br>
&gt;         if principal is None:<br>
&gt;             principal = auth.unauthenticatedPrincipal()<br>
&gt;             if principal is None:<br>
&gt;                 # Get the fallback unauthenticated principal<br>
&gt;                 principal = zope.component.getUtility(<br>
&gt;                     IFallbackUnauthenticatedPrincipal)<br>
&gt;<br>
&gt;         request.setPrincipal(principal)<br>
&gt;         newInteraction(request)<br>
&gt;         transaction.begin()<br>
&gt; ps:<br>
&gt;<br>
&gt; *And code snippet of app.py*<br>
&gt; class Bada(grok.Application, grok.Container):<br>
&gt;     grok.implements(IBada)<br>
&gt;     grok.local_utility(auth.UserAuthenticatorPlugin,<br>
&gt;                        provides=IAuthenticatorPlugin,<br>
&gt;                        name=&#39;users&#39;)<br>
&gt;     grok.local_utility(PluggableAuthentication,provides=IAuthentication,<br>
&gt;                        setup=auth.setup_authentication,<br>
&gt;                        )<br>
&gt; *And code snippet of auth.py*<br>
&gt; def setup_authentication(pau):<br>
&gt;     pau.credentialsPlugins=[&#39;credentials&#39;]<br>
&gt;     pau.authenticatorPlugins=[&#39;users&#39;]<br>
&gt;<br>
&gt; class Account(grok.Model):<br>
&gt;     def __init__(self,name,password,real_name,role):<br>
&gt;         <a href="http://self.name" target="_blank">self.name</a>=name<br>
&gt;         self.real_name=real_name<br>
&gt;         self.role=role<br>
&gt;         self.setPassword(password)<br>
&gt;     def setPassword(self,password):<br>
&gt;         passwordManager=getUtility(IPasswordManager,&#39;SHA1&#39;)<br>
&gt;         self.password=passwordManager.encodePassword(password)<br>
&gt;     def checkPassword(self,password):<br>
&gt;         passwordManager=getUtility(IPasswordManager,&#39;SHA1&#39;)<br>
&gt;         return passwordManager.checkPassword(self.password,password)<br>
&gt; class UserFolder(grok.Container):<br>
&gt;     pass<br>
&gt; class<br>
&gt; MySessionCredentialsPlugin(grok.GlobalUtility,SessionCredentialsPlugin):<br>
&gt;     grok.provides(ICredentialsPlugin)<br>
&gt;     <a href="http://grok.name" target="_blank">grok.name</a>(&quot;credentials&quot;)<br>
&gt;<br>
&gt;     loginpagename=&quot;login&quot;<br>
&gt;     loginfield=&#39;login&#39;<br>
&gt;     passwordfield=&#39;password&#39;<br>
&gt;<br>
&gt; class PrincipalInfo(object):<br>
&gt;     grok.implements(IPrincipalInfo)<br>
&gt;     def __init__(self,id,title,description):<br>
&gt;         <a href="http://self.id" target="_blank">self.id</a>=id<br>
&gt;         self.title=title<br>
&gt;         self.description=description<br>
&gt;         self.credentialsPlugin=None<br>
&gt;         self.authenticatorPlugin=None<br>
&gt; class UserAuthenticatorPlugin(grok.LocalUtility):<br>
&gt;     grok.implements(IAuthenticatorPlugin)<br>
&gt;     <a href="http://grok.name" target="_blank">grok.name</a>(&#39;users&#39;)<br>
&gt;<br>
&gt;     def __init__(self):<br>
&gt;         self.user_folder=UserFolder()<br>
&gt;     def authenticateCredentials(self,credentials):<br>
&gt;         if not isinstance(credentials,dict):<br>
&gt;             return None<br>
&gt;         if not (&#39;login&#39; in credentials and &#39;password&#39; in credentials):<br>
&gt;             return None<br>
&gt;         account=self.getAccount(credentials[&#39;login&#39;])<br>
&gt;         if account is None:<br>
&gt;             return None<br>
&gt;         if not account.checkPassword(credentials[&#39;password&#39;]):<br>
&gt;             return None<br>
&gt;         return PrincipalInfo(id=<a href="http://account.name" target="_blank">account.name</a>,<br>
&gt;                              title=account.real_name,<br>
&gt;                              description=account.real_name<br>
&gt;                              )<br>
&gt;     def principalInfo(self,id):<br>
&gt;         account=self.getAccount(id)<br>
&gt;         if account is None:<br>
&gt;             return None<br>
&gt;         return PrincialInfo(id=<a href="http://account.name" target="_blank">account.name</a>,<br>
&gt;                             title=account.real_name,<br>
&gt;                             description=account.real_name<br>
&gt;                             )<br>
&gt;     def getAccount(self,login):<br>
&gt;         return login in self.user_folder and self.user_folder[login] or<br>
&gt; None<br>
&gt;     def addUser(self,username,password,real_name,role,**kwargw):<br>
&gt;         import pdb;pdb.set_trace()<br>
&gt;         if username not in self.user_folder:<br>
&gt;             user=Account(username,password,real_name,role)<br>
&gt;             self.user_folder[username]=user<br>
&gt;             role_manager=IPrincipalRoleManager(grok.getSite())<br>
&gt;             permission_manager=IPrincipalPermissionManager(grok.getSite())<br>
&gt;             #TODO: do role or permission assigning here.<br>
&gt;             permission_manager.grantPermissionToPrincipal(&#39;zope.View&#39;,<br>
&gt; <a href="http://user.name" target="_blank">user.name</a>)<br>
&gt;<br>
&gt; class ILoginForm(Interface):<br>
&gt;     login=schema.BytesLine(title=_(u&#39;Username&#39;),required=True)<br>
&gt;     camefrom=schema.BytesLine(title=u&#39;&#39;,required=False)<br>
&gt;     password=schema.Password(title=_(u&#39;Password&#39;),required=True)<br>
&gt;<br>
&gt; class Login(megrok.layout.Form):<br>
&gt;     grok.context(Interface)<br>
&gt;     grok.require(&#39;zope.Public&#39;)<br>
&gt;     label=&#39;Login&#39;<br>
&gt;     prefix=&#39;&#39;<br>
&gt;     form_fields=grok.Fields(ILoginForm)<br>
&gt;<br>
&gt;     def setUpWidgets(self,ignore_request=False):<br>
&gt;         super(Login,self).setUpWidgets(ignore_request)<br>
&gt;         self.widgets[&#39;camefrom&#39;].type=&#39;hidden&#39;<br>
&gt;         self.widgets[&#39;login&#39;].cssClass=&#39;title&#39;<br>
&gt;         self.widgets[&#39;password&#39;].cssClass=&#39;title&#39;<br>
&gt;<br>
&gt;     @grok.action(&#39;Login&#39;)<br>
&gt;     def handle_login(self,**data):<br>
&gt;         import pdb;pdb.set_trace()<br>
&gt;<br>
&gt;  self.redirect(self.request.form.get(&#39;camefrom&#39;,self.url(grok.getSite())))<br>
&gt;<br>
&gt; class IAddUserForm(Interface):<br>
&gt;     login=schema.BytesLine(title=_(u&quot;Username&quot;),required=True)<br>
&gt;     password=schema.Password(title=_(u&#39;Password&#39;),required=True)<br>
&gt;     confirm_password=schema.Password(title=_(u&quot;Confirm password&quot;),<br>
&gt;                                      required=True)<br>
&gt;     real_name=schema.TextLine(title=_(u&#39;Real name&#39;),required=True)<br>
&gt;     role=schema.Choice(title=_(u&#39;User role&#39;),<br>
&gt;                        values=[_(u&#39;Bada Member&#39;),_(u&#39;Bada Master<br>
&gt; Account&#39;)],<br>
&gt;                        required=True)<br>
&gt;<br>
&gt; class AddUserForm(megrok.layout.Form):<br>
&gt;     grok.context(Interface)<br>
&gt;     grok.require(&#39;zope.Public&#39;)<br>
&gt;     label=_(&#39;Register&#39;)<br>
&gt;     form_fields=grok.Fields(IAddUserForm)<br>
&gt;     @grok.action(_(u&#39;Register&#39;))<br>
&gt;     def handle_add(self,**data):<br>
&gt;         users=getUtility(IAuthenticatorPlugin,&#39;users&#39;)<br>
&gt;<br>
&gt;  users.addUser(data[&#39;login&#39;],data[&#39;password&#39;],data[&#39;real_name&#39;],data[&#39;role&#39;])<br>
&gt;         self.redirect(self.url(grok.getSite()))<br>
&gt;<br>
&gt; On Thu, Nov 4, 2010 at 1:49 AM, Jeffrey D Peterson &lt;<a href="mailto:bgpete@gmail.com">bgpete@gmail.com</a>&gt;wrote:<br>
&gt;<br>
&gt;&gt;  There is a bug, it?s been documented.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; You need to include zope.pluggableauth in your setup.py in<br>
&gt;&gt; install_requires and rerun buildout.  This will work around the bug.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Hopefully that?s the issue, otherwise, we?ll have to look closer.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt;<br>
&gt;&gt; Jeffrey Peterson<br>
&gt;&gt;<br>
&gt;&gt; <a href="mailto:bgpete3@gmail.com">bgpete3@gmail.com</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; *From:* <a href="mailto:grok-dev-bounces@zope.org">grok-dev-bounces@zope.org</a> [mailto:<a href="mailto:grok-dev-bounces@zope.org">grok-dev-bounces@zope.org</a>] *On<br>
&gt;&gt; Behalf Of *Shrek Zhou<br>
&gt;&gt; *Sent:* Wednesday, November 03, 2010 12:01 PM<br>
&gt;&gt; *To:* <a href="mailto:grok-dev@zope.org">grok-dev@zope.org</a><br>
&gt;&gt; *Subject:* [Grok-dev] grok 1.2 and session based auth.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; hi, grokkers,<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; *My problem:*<br>
&gt;&gt;<br>
&gt;&gt; I can not use PluggableAuthenticationPlugin from zope.pluggableauth to do<br>
&gt;&gt; a session based auth.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; *Steps I took:*<br>
&gt;&gt;<br>
&gt;&gt; 1. added the following lines to my gork.Application:<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;     grok.local_utility(auth.UserAuthenticatorPlugin,<br>
&gt;&gt;<br>
&gt;&gt;                        provides=IAuthenticatorPlugin,<br>
&gt;&gt;<br>
&gt;&gt;                        name=&#39;users&#39;)<br>
&gt;&gt;<br>
&gt;&gt;     grok.local_utility(PluggableAuthentication,provides=IAuthentication,<br>
&gt;&gt;<br>
&gt;&gt;                        setup=auth.setup_authentication,<br>
&gt;&gt;<br>
&gt;&gt;                        )<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; 2. created corresponding authenticatorPlugin and credentialsPlugin, and<br>
&gt;&gt; add them to pau through setup_authentication.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; *Results*:<br>
&gt;&gt;<br>
&gt;&gt; The authentication utility is not called at all. only<br>
&gt;&gt; princialRegistry(from zope.principalregistry which is a globalsite utility<br>
&gt;&gt; that implements IAuthentication.) works.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Expected:<br>
&gt;&gt;<br>
&gt;&gt; The local authentication utility should work and substitute the global<br>
&gt;&gt; one.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; *How can I fix the above problem??*<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://mail.zope.org/pipermail/grok-dev/attachments/20101104/b33f1dfc/attachment-0001.html" target="_blank">http://mail.zope.org/pipermail/grok-dev/attachments/20101104/b33f1dfc/attachment-0001.html</a><br>

<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Thu, 04 Nov 2010 09:14:44 +0100<br>
From: Jan-Wijbrand Kolman &lt;<a href="mailto:janwijbrand@gmail.com">janwijbrand@gmail.com</a>&gt;<br>
Subject: Re: [Grok-dev] grok 1.2 and session based auth.<br>
To: <a href="mailto:grok-dev@zope.org">grok-dev@zope.org</a><br>
Message-ID: &lt;iatq1j$7jo$<a href="mailto:1@dough.gmane.org">1@dough.gmane.org</a>&gt;<br>
Content-Type: text/plain; charset=windows-1252; format=flowed<br>
<br>
On 11/4/10 2:49 AM, Shrek Zhou wrote:<br>
&gt; To Christian,<br>
&gt;<br>
&gt; I can not found groupfolder.zcml in that folder under<br>
&gt; *.buildout/eggs/zope.pluggableauth-1.0.3-py2.6.egg/zope/pluggableauth/plugins/<br>
<br>
Grok-1.2 still uses zope.pluggableauth-1.0.3 indeed. I&#39;m not sure of the<br>
chronology of the Grok 1.2 release and the zope.pluggableauth 1.1<br>
anymore, but, if you were to say in your project&#39;s buildout.cfg:<br>
<br>
[versions]<br>
...<br>
zope.pluggableauth = 1.1<br>
...<br>
<br>
and then re-run ./bin/buildout, you should get the latest<br>
zope.pluggableauth *with* the aforementioned plugins.<br>
<br>
As Christian said, the subject of zope.pluggablauth and related have<br>
soke glitches concerning the correct configuration. I *think* this is<br>
being worked on as we speak during the Grok Forest Sprint.<br>
<br>
Thanks for keeping up with this and helping identifying the issues.<br>
<br>
Kind regards, jw<br>
<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Grok-dev mailing list<br>
<a href="mailto:Grok-dev@zope.org">Grok-dev@zope.org</a><br>
<a href="https://mail.zope.org/mailman/listinfo/grok-dev" target="_blank">https://mail.zope.org/mailman/listinfo/grok-dev</a><br>
<br>
<br>
End of Grok-dev Digest, Vol 50, Issue 5<br>
***************************************<br>
</blockquote></div><br></div>