Skip to content

Commit

Permalink
fix(setup): Existing broken Zope root cookie
Browse files Browse the repository at this point in the history
[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
rpatterson committed Feb 25, 2022
1 parent 13c1766 commit 1e9cd05
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Products/PlonePAS/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<depends name="memberdata-properties" />
<depends name="rolemap" />
</genericsetup:importStep>
<genericsetup:upgradeStep
title="Fix existing broken Zope root `/acl_users` plugins"
profile="Products.PlonePAS:PlonePAS"
source="4"
destination="5"
handler=".upgrades.from4to5_fix_zope_root" />

<genericsetup:registerProfile
name="root-cookie"
Expand Down
2 changes: 1 addition & 1 deletion src/Products/PlonePAS/profiles/default/metadata.xml
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>
59 changes: 59 additions & 0 deletions src/Products/PlonePAS/upgrades.py
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"],
)

0 comments on commit 1e9cd05

Please sign in to comment.