Jim Fulton wrote:

Dominik Huber wrote:

Excuse me late response I was busy that weekend...

Jim Fulton wrote:

I fixed that issue within the branch 'Zope3/branches/dominik-locatableadapters'
Jim, could you take a look at that please. Thank you very much in advance!


We should *only* add the location if the adapter requires a permission other
than zope public. Key rereferences don't require a permission and should not
be location proxied. Doing so makes them unpicklable.

We're going to need to fix the trusted adapter factory to do this correctly.
I suggest we create a new kind of trusted adapter factory, perhaps
"LocatingTrustedAdapter" factory that adds the location. This should
only be used when the adapter directive specified a permission other
than zope.Public. Otherwise, the original trusted adapter factory should
be used.

May be I do not understand the problem correctly:

IMO the permission declaration within the adapter directive has nothing to do
with the permission declaration wihtin the class directive that mus be used if
trusted adapters are invoked.


Example KeyReference Adapter:


<class class=".persistent.KeyReferenceToPersistent">
<require permission="zope.Public" interface=".interfaces.IKeyReference" />

That's odd.  I didn't notice the class directive.  I don't know why the
class directive is being used here. This is one of those rare cases where
we have to make the security declaration on the adapter class. (In this
case, it's because the adapters are pickled, which is also unusual.)

It is not generally the case that you need to use separate security
declarations with trusted adapters.

I declare those additional class directive all the time if I'm using trusted adapters.
IMO this kind of registration is the common pattern

For example stephan richter uses this pattern within the wiki:

     trusted="true" />

 <class class=".wikipage.WikiPageHierarchyAdapter">
       attributes="parents path findChildren"

permission declaration of the possible adapter instances (<class ...). Therefore we can't switch the
adapter factories within the adapter directive processing..

So, during the registration of an trusted adapter factory (<adapter...) I can't do any prediction about the

No, you can't do so implicitly. You can know about the permission
used if a non-public permission was supplied. If a non-public permission
is supplied, then it is reasonable to add the location. Otherwise, you should
not try to guess.

But the permission declaration within the adapter directive defines the permission that is nessecary to invoke the adapter factory.
It's implict to asume that the instance by a certain factory desires the same permissions like the invocationg of the factory.

- How should we handle NullAdapters correctly?

All the same I implemented your sugestion. The following question appears:

What do you mean by NullAdapters?  Are you talking about factories that
return None?

Id so, then, obviously, you should not proxy None.

No, 'NullAdapter' are parameterless factories, for example x = IX()

IMO this solution is pretty implicit and I do not like it at all.

What solution?  If you are talking about my suggestion to
add a location to any adapter for whoch a non-public permission
is specified, then I consider this far less impleicit than what you
had before.  It doesn't guess. If it knows a permission is required,
it adds a location.

Yes, the current solution in the branch.

We should find a way to check the permission of the adapter instances inside a single trusted adapter factory:

class IntelligentTrustedAdapterFactory(TrustedAdapterFactoryMixin):

   def _customize(self, adapter, context):
       p = ProxyFactory(adapter)
       checker = getChecker(p)
       if checker is CheckerPublic:
           return adapter
          return assertLocation(adapter, context)


- performance
- in the key refernce example it would be an dedicated checker. how could I guess if such an checker is Public?

This is just too much magic.  It has too many rules and
is too slow.

BTW, we are not just taking about trusted adapters.  We are talking about
*any* adapter for which a non-public permission is required.

Yes, thats clear. We have two cases: 1. untrusted 2. trusted

1. if we register an untrusted adapter using the adapter directive we can make an correlation between adapter factory permission and
adapter instance: if I have no permission to invoke the factory, I should not be able to use its instances.

2. if we register a trusted adapter this correlation breaks because the adapter instance itself might have highly differented security-permission
(compare <class...)

So 1 is easy to handle in the adapter directive, but 2 not. The suggestion above tries to respect your requirments, but also allow to use.
the registration pattern <adapter... and <class.. which is failry common and explicit.

The current solution in the branch is not able to handle 2. correctly.
Stephan's zwiki example:
- The adapter directive has no permission (which is ok, because he doesn't need to protect the invocation of the adapter factory itself).
- In that case the locating trusted adapter factory is not invoked within the registration.
- Therefore the adapter instance will not have any location.
- Therefore we can't invoke the local authentication.

My suggestion:
IMO the intid and keyrefernce stuff is an exceptional case. Nobody else using the zope framework tries to memorize adapters persistently.
Everyone is aware that adapters regularly are very transient.
If somebody needs a pickable adapter he should be aware that those adapter must provide ILocation and must be trusted.

-> Derive KeyRerenceToPersistent from Location
-> if adapter are trusted, the locating trusted adapter factory is invoked all the time.


Zope3-dev mailing list
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to