def getInternalPrincipal(principal):
    auth = IPluggableAuthentication(getUtility(IAuthentication), None)

    if auth is not None:
        id = principal.id

        if id.startswith(auth.prefix):
            id = id[len(auth.prefix):]

            for name, plugin in auth.getAuthenticatorPlugins():
                if IRPXNowUsersPlugin.providedBy(plugin):
                    if id.startswith(plugin.prefix):
                        id = id[len(plugin.prefix):]
                        return plugin[id]
예제 #2
0
    def isActive(self):
        auth = self.auth

        if IPluggableAuthentication.providedBy(auth):
            return self.name in getattr(auth, self.pluginNames)

        return False
예제 #3
0
    def _signupfolder(self):
        pau = getUtility(IAuthentication)
        if not IPluggableAuthentication.providedBy(pau):
            raise LookupError("Signup requires a PAU instance.")

        for name, plugin in pau.getAuthenticatorPlugins():
            if ISignup.providedBy(plugin):
                return plugin

        raise TypeError("Signup requires a sign-up capable athenticator "
                        "plugin.")
예제 #4
0
    def activate(self):
        plugin = self.plugin

        if plugin is None:
            return

        auth = self.auth

        if IPluggableAuthentication.providedBy(auth):
            setattr(auth, self.pluginNames,
                    tuple(set(getattr(auth, self.pluginNames) + (self.name,))))
예제 #5
0
 def getUserFolder(self):
     pau = zope.component.getUtility(IAuthentication)
     if not IPluggableAuthentication.providedBy(pau):
         return (None, False, False)
     for name, plugin in pau.getAuthenticatorPlugins():
         if not IAuthenticatorPlugin.providedBy(plugin):
             continue
         # This is a lie, but how should we know?
         writeable = IInternalPrincipalContainer.providedBy(plugin)
         searchable = IQuerySchemaSearch.providedBy(plugin)
         return (plugin, writeable, searchable)
     return (None, False, False)
예제 #6
0
    def deactivate(self):
        plugin = self.plugin

        if plugin is None:
            return

        auth = self.auth

        if IPluggableAuthentication.providedBy(auth):
            plugins = set(getattr(auth, self.pluginNames))
            if self.name in plugins:
                plugins.remove(self.name)
                setattr(auth, self.pluginNames, tuple(plugins))
예제 #7
0
    def install(self):
        auth = self.auth
        if not IPluggableAuthentication.providedBy(auth):
            raise ValueError(_("Can't create authenticator plugin."))

        plugin = self.factory()
        event.notify(ObjectCreatedEvent(plugin))

        auth = removeSecurityProxy(auth)
        if self.name in auth:
            del auth[self.name]

        auth[self.name] = plugin

        sm = getSiteManager()
        for iface, name in (self.interfaces +
                            ((self.pluginInterface, self.name),)):
            sm.registerUtility(plugin, iface, name)
예제 #8
0
def updateCredentials(request, login, password):
    auth = getUtility(IAuthentication)
    if IPluggableAuthentication.providedBy(auth):

        updated = False
        for name, creds in auth.getCredentialsPlugins():
            if ICredentialsUpdater.providedBy(creds):
                if extIPluggableAuthentication.providedBy(auth):
                    auth.logout(request)

                creds.updateCredentials(
                    request, SimpleCredentials(login, password))

                auth.authenticate(request)
                updated = True

        if updated:
            return True
    return False
예제 #9
0
    def uninstall(self):
        self.deactivate()

        auth = self.auth

        if not IPluggableAuthentication.providedBy(auth):
            return

        if self.name not in auth:
            return

        plugin = auth[self.name]

        sm = getSiteManager()
        for iface, name in (self.interfaces +
                            ((self.pluginInterface, self.name),)):
            sm.unregisterUtility(plugin, iface, name=name)

        del auth[self.name]
예제 #10
0
def evolve(context):
    root = getRootFolder(context)

    for site in findObjectsProviding(root, ISite):
        sm = site.getSiteManager()

        pau = component.queryUtility(IAuthentication, context = sm)
        if pau is not None and IPluggableAuthentication.providedBy(pau):
            if OLD_CRED_NAME in pau:
                plugins = list(pau.credentialsPlugins)
                if OLD_CRED_NAME in plugins:
                    plugins.remove(OLD_CRED_NAME)
                    pau.credentialsPlugins = tuple(plugins)

                del pau[OLD_CRED_NAME]

            setSite(site)
            factory = component.getUtility(ICredentialsPluginFactory, 'default.credentials')
            factory.install()
            factory.activate()
            setSite(None)