-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(setup): Existing broken Zope root cookie
[A previous PR fixed the broken Zope root cookie plugin for new installs](17deb97) but didn't include an upgrade step for existing Zope instances/ZODBs. The issue is only revealed when `IChallengePlugin` is activated for the broken plugins, such as when the `Products.PlonePAS:root-cookie` profile is installed, and [a `Manager` tries to login to](#66 (comment)) the [Zope root ZMI](http://localhost:8080/manage_main). Add an upgrade step that fixes the issue for existing instances/ZODBs.
- Loading branch information
1 parent
13c1766
commit 1e9cd05
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<metadata> | ||
<version>4</version> | ||
<version>5</version> | ||
</metadata> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
Upgrade steps specific to Plone's use of PAS. | ||
""" | ||
|
||
from Products.PlonePAS.plugins import cookie_handler | ||
from Products.PluggableAuthService.plugins import CookieAuthHelper | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def from4to5_fix_zope_root(context): | ||
""" | ||
Fix broken Zope root `/acl_users/` plugins. | ||
""" | ||
root = context.getPhysicalRoot() | ||
pas = root.acl_users.manage_addProduct['PluggableAuthService'] | ||
# Identify which interfaces should be considered PAS plugin interfaces | ||
plugin_ifaces = [ | ||
plugin_type_info["interface"] | ||
for plugin_type_info in root.acl_users.plugins.listPluginTypeInfo() | ||
] | ||
broken_meta_type = cookie_handler.ExtendedCookieAuthHelper.meta_type | ||
broken_plugins = root.acl_users.objectValues(broken_meta_type) | ||
for broken_plugin in broken_plugins: | ||
# Collect properties from old/broken plugin | ||
kwargs = dict( | ||
id=broken_plugin.id, | ||
title=broken_plugin.title, | ||
cookie_name=broken_plugin.cookie_name, | ||
) | ||
# Which PAS plugin interfaces has this plugin been activated for | ||
active_ifaces = [ | ||
plugin_iface | ||
for plugin_iface in plugin_ifaces | ||
if plugin_iface.providedBy(broken_plugin) | ||
and broken_plugin.id in root.acl_users.plugins.listPluginIds(plugin_iface) | ||
] | ||
# Delete the old/broken plugin | ||
logger.info( | ||
"Deleting broken %r plugin: %r", | ||
broken_meta_type, | ||
"/".join(broken_plugin.getPhysicalPath()), | ||
) | ||
root.acl_users.manage_delObjects([broken_plugin.id]) | ||
# Add the correct plugin | ||
logger.info( | ||
"Adding working %r plugin: %r", | ||
CookieAuthHelper.CookieAuthHelper.meta_type, | ||
"/".join(broken_plugin.getPhysicalPath()), | ||
) | ||
pas.addCookieAuthHelper(**kwargs) | ||
# Restore activated plugin interfaces | ||
for plugin_iface in active_ifaces: | ||
root.acl_users.plugins.activatePlugin( | ||
plugin_iface, | ||
kwargs["id"], | ||
) |