Exemplo n.º 1
0
    def createLocalPas(self):
        """Create PAS acl_users else login_form does not work"""
        # need Manager role to add an acl_users object
        remove_role = False
        if not getSecurityManager().checkPermission(permissions.ManagePortal, self):
            portal_membership = getToolByName(self, "portal_membership")
            current_user = portal_membership.getAuthenticatedMember()
            current_userid = current_user.getId()
            self.manage_addLocalRoles(userid=current_userid, roles=["Manager"])
            remove_role = True
        # Re-use code in PlonePAS install
        addPluggableAuthService(self)
        out = StringIO()
        try:
            challenge_chooser_setup(self)
        except TypeError:
            # BBB needed for Plone 3.3.5
            challenge_chooser_setup(self, out)
        registerPluginTypes(self.acl_users)
        try:
            setupPlugins(self)
        except TypeError:
            # BBB needed for Plone 3.3.5
            setupPlugins(self, out)

        # Recreate mutable_properties but specify fields
        uf = self.acl_users
        uf.manage_addProduct["PluggableAuthService"]
        plone_pas = uf.manage_addProduct["PlonePAS"]
        plone_pas.manage_delObjects("mutable_properties")
        plone_pas.manage_addZODBMutablePropertyProvider("mutable_properties", fullname="", key="", email_sent="")
        activatePluginInterfaces(self, "mutable_properties", out)
        if remove_role:
            self.manage_delLocalRoles(userids=[current_userid])
    def _initPAS(self, plugin_type_info=(), plugins={}):
        from OFS.Folder import Folder
        from Products.PluggableAuthService.PluggableAuthService import addPluggableAuthService

        app = Folder()
        app.getPhysicalPath = lambda: ()
        app.getPhysicalRoot = lambda: app

        addPluggableAuthService(app)
        pas = app._getOb("acl_users")

        return app, pas
        def _initPAS(self, plugin_type_info=(), plugins={}):
            from OFS.Folder import Folder
            from Products.PluggableAuthService.PluggableAuthService \
                import addPluggableAuthService

            app = Folder()
            app.getPhysicalPath = lambda: ()
            app.getPhysicalRoot = lambda: app

            addPluggableAuthService(app)
            pas = app._getOb('acl_users')

            return app, pas
Exemplo n.º 4
0
def add_PAS(app, cookie_auth=True):
    """
    Full configuration of PluggableAuthService:
    - local users plugin
    - Zope Roles plugin
    - http basic auth plugin
    - cookie auth plugin

    """
    if getattr(app, 'acl_users', False):
        del app['acl_users']
    addPluggableAuthService(app)
    pas = app['acl_users']
    addZODBUserManager(pas, 'users')
    addZODBRoleManager(pas, 'roles')
    addCookieAuthHelper(pas, 'cookie_auth')
    addHTTPBasicAuthHelper(pas, 'basic_auth')

    plugin_activation = [
        ('users', 'IAuthenticationPlugin'),
        ('users', 'IUserEnumerationPlugin'),
        ('users', 'IUserAdderPlugin'),
        ('roles', 'IRolesPlugin'),
        ('roles', 'IRoleEnumerationPlugin'),
        ('roles', 'IRoleAssignerPlugin'),
    ]
    if cookie_auth:
        plugin_activation.extend([
            ('cookie_auth', 'IExtractionPlugin'),
            ('cookie_auth', 'IChallengePlugin'),
            ('cookie_auth', 'ICredentialsUpdatePlugin'),
            ('cookie_auth', 'ICredentialsResetPlugin'),
        ])
    plugin_activation.extend([
        ('basic_auth', 'IExtractionPlugin'),
        ('basic_auth', 'IChallengePlugin'),
        ('basic_auth', 'ICredentialsResetPlugin'),
    ])

    for plugin_id, type_name in plugin_activation:
        plugin_type = getattr(plugin_interfaces, type_name)
        pas['plugins'].activatePlugin(plugin_type, plugin_id)

    return pas
Exemplo n.º 5
0
    def createLocalPas(self):
        """Create PAS acl_users else login_form does not work"""
        # need Manager role to add an acl_users object
        remove_role = False
        if not getSecurityManager().checkPermission(permissions.ManagePortal,
                                                    self):
            portal_membership = getToolByName(self, 'portal_membership')
            current_user = portal_membership.getAuthenticatedMember()
            current_userid = current_user.getId()
            self.manage_addLocalRoles(userid=current_userid,
                                      roles=[
                                          'Manager',
                                      ])
            remove_role = True
        # Re-use code in PlonePAS install
        addPluggableAuthService(self)
        out = StringIO()
        try:
            challenge_chooser_setup(self)
        except TypeError:
            # BBB needed for Plone 3.3.5
            challenge_chooser_setup(self, out)
        registerPluginTypes(self.acl_users)
        try:
            setupPlugins(self)
        except TypeError:
            # BBB needed for Plone 3.3.5
            setupPlugins(self, out)

        # Recreate mutable_properties but specify fields
        uf = self.acl_users
        uf.manage_addProduct['PluggableAuthService']
        plone_pas = uf.manage_addProduct['PlonePAS']
        plone_pas.manage_delObjects('mutable_properties')
        plone_pas.manage_addZODBMutablePropertyProvider('mutable_properties',
                                                        fullname='',
                                                        key='',
                                                        email_sent='')
        activatePluginInterfaces(self, 'mutable_properties', out)
        if remove_role:
            self.manage_delLocalRoles(userids=[
                current_userid,
            ])