From: matth <svn...@pl...> - 2006-03-31 16:22:00
|
Author: matth Date: Fri Mar 31 16:21:43 2006 New Revision: 21635 Added: SalesforceMultiPlugin/trunk/ SalesforceMultiPlugin/trunk/INSTALL.txt SalesforceMultiPlugin/trunk/README.txt SalesforceMultiPlugin/trunk/SalesforceMultiPlugin.py SalesforceMultiPlugin/trunk/__init__.py SalesforceMultiPlugin/trunk/refresh.txt SalesforceMultiPlugin/trunk/version.txt SalesforceMultiPlugin/trunk/www/ SalesforceMultiPlugin/trunk/www/salesforce.png (contents, props changed) SalesforceMultiPlugin/trunk/www/salesforceAdd.zpt Log: Initial import of SalesforceMultiplugin Added: SalesforceMultiPlugin/trunk/INSTALL.txt ============================================================================== --- (empty file) +++ SalesforceMultiPlugin/trunk/INSTALL.txt Fri Mar 31 16:21:43 2006 @@ -0,0 +1,17 @@ +Pre-requisites: + +1) Developer account on salesforce.com +2) Zope > 2.7 +3) PAS +4) PlonePAS +5) SalesforceTool + +It has been tested with: + +1) Plone 2.1.1 +2) PAS 1.0.4 +3) PlonePAS 0.4.0 + +But hopefully should work with Plone 2.5 + + Added: SalesforceMultiPlugin/trunk/README.txt ============================================================================== --- (empty file) +++ SalesforceMultiPlugin/trunk/README.txt Fri Mar 31 16:21:43 2006 @@ -0,0 +1,13 @@ +This is a Authentication and User Properties plugin for Salesforce and PAS. + +It allows users to be authenticated using their Salesforce.com self-service user credentials. + +It supports fetching groups from salesforce Contact records. To enable fill in the +'Salesforce Group Field' on the properties tab of the plugin. + +This Plugin was funded by Ubiquity Software, www.ubiquitysoftware.com and written by Netsight Internet Solutions + +Matt Hamilton +Netsight Internet Solutions +m...@ne... + Added: SalesforceMultiPlugin/trunk/SalesforceMultiPlugin.py ============================================================================== --- (empty file) +++ SalesforceMultiPlugin/trunk/SalesforceMultiPlugin.py Fri Mar 31 16:21:43 2006 @@ -0,0 +1,182 @@ +import sys +from time import time + +from AccessControl import ClassSecurityInfo + +from Globals import InitializeClass +from OFS.Cache import Cacheable + +from Products.CMFCore.utils import getToolByName + +from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin +from Products.PluggableAuthService.utils import classImplements, createViewName +from Products.PluggableAuthService.interfaces.plugins import IAuthenticationPlugin, IPropertiesPlugin, ICredentialsUpdatePlugin, IUpdatePlugin, IUserEnumerationPlugin, IGroupsPlugin +from Products.PlonePAS.interfaces.plugins import IUserManagement, IUserIntrospection +from Products.PlonePAS.interfaces.capabilities import IPasswordSetCapability + + +from Products.PageTemplates.PageTemplateFile import PageTemplateFile + +manage_addSalesforceMultiPluginForm = PageTemplateFile( + 'www/salesforceAdd', globals(), __name__='manage_addSalesforceMultiPluginForm' ) + +def manage_addSalesforceMultiPlugin(dispatcher, id, title=None, REQUEST=None): + """ Add a SalesforceMultiPlugin to a Pluggable Auth Service. """ + + obj = SalesforceMultiPlugin(id, title) + dispatcher._setObject(obj.getId(), obj) + + if REQUEST is not None: + REQUEST['RESPONSE'].redirect( + '%s/manage_workspace' + '?manage_tabs_message=' + 'SalesforceMultiPlugin+added.' + % dispatcher.absolute_url()) + + +class SalesforceMultiPlugin(BasePlugin, Cacheable): + + """ PAS plugin for using Salesforce contact details for login + """ + + meta_type = 'SalesforceMultiPlugin' + + security = ClassSecurityInfo() + + manage_options = BasePlugin.manage_options + Cacheable.manage_options + + _properties = BasePlugin._properties + ( + {'id':'sforce_group_field', 'type': 'string', 'mode':'w', + 'label':'SalesForce Group Field'}, + ) + + sforce_group_field = "" + + + def __init__(self, id, title=None): + self._id = self.id = id + self.title = title + + + # + # IAuthenticationPlugin implementation + # + security.declarePrivate('authenticateCredentials') + def authenticateCredentials(self, credentials): + + """ See IAuthenticationPlugin. + + o We expect the credentials to be those returned by + ILoginPasswordExtractionPlugin. + """ + login = credentials.get( 'login' ) + password = credentials.get( 'password' ) + + if login is None or password is None: + return None + + st = getToolByName(self, "portal_salesforce") + if st.authenticate_sserv(login, password): + return login, login + + return None + + # IPropertiesPlugin + def getPropertiesForUser(self, user, request=None ): + st = getToolByName(self, "portal_salesforce") + return st.getPropertiesForUser(user, request) + + # IUpdatePlugin + def updateUserInfo(self, user, set_id, set_info ): + + """ Update backing store for 'set_id' using 'set_info'. + """ + st = getToolByName(self, "portal_salesforce") + st.updateUserInfo(user, set_id, set_info) + + # IPasswordSetCapability + def allowPasswordSet(self, id): + """ can we set the password for this user """ + return True + + # IUserEnumerationPlugin + def enumerateUsers( self + , id=None + , login=None + , exact_match=False + , sort_by=None + , max_results=None + , **kw + ): + + """ -> ( user_info_1, ... user_info_N ) """ + + st = getToolByName(self, "portal_salesforce") + if id or login: + if exact_match: + spec = id or login + else: + spec = '%%%s%%' % login + else: + spec = None + + plugin_id = self.getId() + + return [ {'id': x, 'login': x, 'plugin_id': plugin_id} for x in st.listAllUsers(spec) ] + + # IUserIntrospection interfaces + def getUserIds(self): + """ + Return a list of user ids + """ + st = getToolByName(self, "portal_salesforce") + return st.listAllUsers() + + def getUserNames(self): + """ + Return a list of usernames + """ + st = getToolByName(self, "portal_salesforce") + return st.listAllUsers() + + def getUsers(self): + """ + Return a list of users + """ + uf = self.acl_users + return [uf.getUserById(x) for x in self.getUserIds()] + + + # IGroupsPlugin interfaces + def getGroupsForPrincipal(self, principal, request=None ): + + """ principal -> ( group_1, ... group_N ) + + o Return a sequence of group names to which the principal + (either a user or another group) belongs. + + o May assign groups based on values in the REQUEST object, if present + """ + props = self.getPropertiesForUser(principal) + groups = props.get(self.sforce_group_field, []) + if type(groups) not in (type([]), type(())): # (oYo) ;) + groups = [groups,] + + return map(self.addGroupPrefix, groups) + + + def addGroupPrefix(self, group): + """ add the group_ prefix to group names """ + return 'group_' + group + + +classImplements(SalesforceMultiPlugin, (IAuthenticationPlugin, + IPropertiesPlugin, + IGroupsPlugin, + IUpdatePlugin, + IUserEnumerationPlugin, + IUserIntrospection, + IPasswordSetCapability)) + +InitializeClass(SalesforceMultiPlugin) + Added: SalesforceMultiPlugin/trunk/__init__.py ============================================================================== --- (empty file) +++ SalesforceMultiPlugin/trunk/__init__.py Fri Mar 31 16:21:43 2006 @@ -0,0 +1,22 @@ +from AccessControl.Permissions import add_user_folders +from Products.PluggableAuthService.PluggableAuthService import registerMultiPlugin +from SalesforceMultiPlugin import SalesforceMultiPlugin, manage_addSalesforceMultiPlugin, manage_addSalesforceMultiPluginForm + +def initialize(context): + """ Initialize the SalesforceMultiPlugin """ + try: + registerMultiPlugin(SalesforceMultiPlugin.meta_type) + + context.registerClass( SalesforceMultiPlugin + , permission=add_user_folders + , constructors=( manage_addSalesforceMultiPluginForm + , manage_addSalesforceMultiPlugin + ) + , icon='www/salesforce.png' + , visibility=None + ) + + except ImportError: + # If we don't have libgmail installed (and installed + # correctly) then there is no point in exposing this plugin. + pass Added: SalesforceMultiPlugin/trunk/refresh.txt ============================================================================== --- (empty file) +++ SalesforceMultiPlugin/trunk/refresh.txt Fri Mar 31 16:21:43 2006 @@ -0,0 +1 @@ +# Added: SalesforceMultiPlugin/trunk/version.txt ============================================================================== --- (empty file) +++ SalesforceMultiPlugin/trunk/version.txt Fri Mar 31 16:21:43 2006 @@ -0,0 +1 @@ +0.1 Added: SalesforceMultiPlugin/trunk/www/salesforce.png ============================================================================== Binary file. No diff available. Added: SalesforceMultiPlugin/trunk/www/salesforceAdd.zpt ============================================================================== --- (empty file) +++ SalesforceMultiPlugin/trunk/www/salesforceAdd.zpt Fri Mar 31 16:21:43 2006 @@ -0,0 +1,46 @@ +<h1 tal:replace="structure here/manage_page_header">Header</h1> + +<h2 tal:define="form_title string:Add Salesforce Multi Plugin" + tal:replace="structure here/manage_form_title">Form Title</h2> + +<p class="form-help"> +The SalesforceMultiPlugin lets Plone delegate all user management +to SalesForce.com +</p> + +<form action="manage_addSalesforceMultiPlugin" method="post"> +<table cellspacing="0" cellpadding="2" border="0"> + <tr> + <td align="left" valign="top"> + <div class="form-label"> + Id + </div> + </td> + <td align="left" valign="top"> + <input type="text" name="id" size="40" /> + </td> + </tr> + <tr> + <td align="left" valign="top"> + <div class="form-optional"> + Title + </div> + </td> + <td align="left" valign="top"> + <input type="text" name="title" size="40" /> + </td> + </tr> + <tr> + <td align="left" valign="top"> + </td> + <td align="left" valign="top"> + <div class="form-element"> + <input class="form-element" type="submit" name="submit" + value=" Add " /> + </div> + </td> + </tr> +</table> +</form> + +<h1 tal:replace="structure here/manage_page_footer">Footer</h1> |