[Zope-CVS] SVN: ldapadapter/trunk/ Added test adapter fro testing
Roger Ineichen
roger at projekt01.ch
Sun Oct 10 09:01:20 EDT 2004
Log message for revision 27896:
Added test adapter fro testing
Added test view for testing adapter/connection
Changed:
A ldapadapter/trunk/browser/check.pt
A ldapadapter/trunk/browser/check.py
U ldapadapter/trunk/browser/configure.zcml
A ldapadapter/trunk/check.py
U ldapadapter/trunk/configure.zcml
-=-
Added: ldapadapter/trunk/browser/check.pt
===================================================================
--- ldapadapter/trunk/browser/check.pt 2004-10-10 13:01:09 UTC (rev 27895)
+++ ldapadapter/trunk/browser/check.pt 2004-10-10 13:01:20 UTC (rev 27896)
@@ -0,0 +1,89 @@
+<html metal:use-macro="views/standard_macros/view">
+<body>
+<div metal:fill-slot="body">
+ <div metal:define-macro="contents"
+ tal:define="hostinfo view/getHostInfo;
+ testreport view/checkConnection">
+
+ <form name="ldapConnectionTestForm" method="POST" action="."
+ tal:attributes="action request/URL">
+
+ <table id="sortable" class="listing" summary="LDAP Configuration listing"
+ i18n:attributes="summary">
+ <thead>
+ <tr>
+ <th i18n:translate="">Desription</th>
+ <th i18n:translate="">Data</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td i18n:translate="">Hostname</td>
+ <td><span tal:content="python:hostinfo['host']">host</span></td>
+ </tr>
+ <tr>
+ <td i18n:translate="">Port</td>
+ <td><span tal:content="python:hostinfo['port']">port</span></td>
+ </tr>
+ <tr>
+ <td i18n:translate="">Bind DN</td>
+ <td><span tal:content="python:hostinfo['baseDN']">baseDN</span></td>
+ </tr>
+ <tr>
+ <td i18n:translate="">Base DN</td>
+ <td><span tal:content="python:hostinfo['bindDN']">bindDN</span></td>
+ </tr>
+ <tr>
+ <td i18n:translate="">Bind password</td>
+ <td><span tal:content="python:hostinfo['bindPassword']">bindPassword</span></td>
+ </tr>
+ </tbody>
+ </table>
+
+ <span i18n:translate="">
+ For to test the authentication, you can set a username and password.<br />
+ This usename and password has to be falid on the LDAP server.
+ </span>
+
+ <table id="sortable" class="listing" summary="LDAP Connection Test Data"
+ i18n:attributes="summary">
+ <thead>
+ <tr>
+ <th i18n:translate="">Description</th>
+ <th i18n:translate="">Data</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td i18n:translate="">Bind DN</td>
+ <td><input type="text" value="" name="bindDN"></td>
+ </tr>
+ <tr>
+ <td i18n:translate="">Bind password</td>
+ <td><input type="password" value="" name="bindPassword"></td>
+ </tr>
+ </tbody>
+ </table>
+ <input type="hidden" value="Run" name="runtest">
+ <input type="submit" value="Test" name="submit">
+
+ <table id="sortable" class="listing" summary="LDAP Connection Report listing"
+ i18n:attributes="summary"
+ tal:condition="testreport">
+ <thead>
+ <tr>
+ <th i18n:translate="">Test report</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr tal:repeat="line testreport" >
+ <td><span tal:content="structure line">report entry</span> </td>
+ </tr>
+ </tbody>
+ </table>
+
+ </form>
+ </div>
+</div>
+</body>
+</html>
Property changes on: ldapadapter/trunk/browser/check.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: ldapadapter/trunk/browser/check.py
===================================================================
--- ldapadapter/trunk/browser/check.py 2004-10-10 13:01:09 UTC (rev 27895)
+++ ldapadapter/trunk/browser/check.py 2004-10-10 13:01:20 UTC (rev 27896)
@@ -0,0 +1,78 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""View Class for the Container's Contents view.
+
+$Id: check.py 26680 2004-07-22 16:31:38Z nicoe $
+"""
+
+from zope.exceptions import NotFoundError
+
+from zope.app import zapi
+from zope.app.size.interfaces import ISized
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zope.app.publisher.browser import BrowserView
+from zope.app.i18n import ZopeMessageIDFactory as _
+
+from ldapadapter.interfaces import IManageableLDAPAdapter
+from ldapadapter.interfaces import ICheckLDAPAdapter
+
+
+
+class CheckLDAPAdapterView(BrowserView):
+
+ __used_for__ = IManageableLDAPAdapter
+
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+ self.__parent__ = context
+ self.report = []
+
+ def getHostInfo(self):
+ """Returns a dict with host information."""
+ infoDict = {}
+ infoDict['host'] = self.context.host
+ infoDict['port'] = self.context.port
+ infoDict['baseDN'] = self.context.baseDN
+ infoDict['bindDN'] = self.context.bindDN
+ infoDict['bindPassword'] = self.context.bindPassword
+ return infoDict
+
+
+ def checkConnection(self):
+ """Check connetction to the given LDAP server."""
+ runtest = self.request.get('runtest', None)
+ if runtest == "Run":
+ dn = self.request.get('bindDN')
+ pw = self.request.get('bindPassword')
+
+ # get the ldapauth source
+ testadapter = ICheckLDAPAdapter(self.context)
+
+ # test the connection to the LDAP server
+ self._addInfo("<strong>Test python connection and LDAP server binding</strong>")
+ self.report = self.report + testadapter.testConnection(dn, pw)
+ self._addInfo("<strong>Tests done</strong>")
+ self._addInfo(" ")
+
+ return self.report
+ else:
+ return ""
+
+ def _addInfo(self, res):
+ """Add traceback info to the report list"""
+ self.report.append(res)
+
+ check = ViewPageTemplateFile('check.pt')
Property changes on: ldapadapter/trunk/browser/check.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: ldapadapter/trunk/browser/configure.zcml
===================================================================
--- ldapadapter/trunk/browser/configure.zcml 2004-10-10 13:01:09 UTC (rev 27895)
+++ ldapadapter/trunk/browser/configure.zcml 2004-10-10 13:01:20 UTC (rev 27896)
@@ -39,4 +39,14 @@
permission="zope.ManageContent"
/>
+ <!-- LDAPAdapter connetion test view -->
+ <page
+ for="ldapadapter.interfaces.IManageableLDAPAdapter"
+ name="checkLDAPAdapter.html"
+ attribute="check"
+ class=".check.CheckLDAPAdapterView"
+ menu="zmi_views" title="Test LDAP Adapter"
+ permission="zope.ManageServices"
+ />
+
</configure>
Added: ldapadapter/trunk/check.py
===================================================================
--- ldapadapter/trunk/check.py 2004-10-10 13:01:09 UTC (rev 27895)
+++ ldapadapter/trunk/check.py 2004-10-10 13:01:20 UTC (rev 27896)
@@ -0,0 +1,54 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""A plugable authentication module for LDAP.
+
+$Id: check.py 27204 2004-08-21 01:46:57Z nicoe $
+"""
+
+from zope.security.proxy import removeSecurityProxy
+from zope.interface import implements
+
+from interfaces import ICheckLDAPAdapter
+
+class CheckLDAPAdapter:
+ """A LDAP connection test adapter."""
+
+ implements(ICheckLDAPAdapter)
+
+ def __init__(self, context):
+ self.context = context
+ self.report = []
+
+ def testConnection(self, bindDN, bindPassword):
+ self.report = []
+ adapter = removeSecurityProxy(self.context)
+ self.report.append("Start check connection")
+
+ try:
+ self.report.append("... try connect with:")
+ self.report.append("... bindDN = %s" % bindDN)
+ self.report.append("... bindPassword = %s" % bindPassword)
+
+ connection = adapter.connect(bindDN, bindPassword)
+
+ if connection != None:
+ self.report.append("... <strong>Connecting failed!</strong>")
+ else:
+ self.report.append("... <strong>OK!</strong>")
+
+ return report
+
+ except:
+ self.report.append("... <strong>Test failed!</strong>")
+ return self.report
Property changes on: ldapadapter/trunk/check.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: ldapadapter/trunk/configure.zcml
===================================================================
--- ldapadapter/trunk/configure.zcml 2004-10-10 13:01:09 UTC (rev 27895)
+++ ldapadapter/trunk/configure.zcml 2004-10-10 13:01:20 UTC (rev 27896)
@@ -26,6 +26,13 @@
</content>
+ <!-- LDAP connection test adapter -->
+ <adapter
+ factory="ldapadapter.check.CheckLDAPAdapter"
+ provides="ldapadapter.interfaces.ICheckLDAPAdapter"
+ for="ldapadapter.interfaces.IManageableLDAPAdapter"
+ />
+
<include package=".browser" />
<!-- add onlinehelp text -->
More information about the Zope-CVS
mailing list