[Zope3-checkins] SVN: ldapauth/trunk/ Added test LDAP adapter and
view for to test the LDAP connection
Roger Ineichen
roger at projekt01.ch
Tue Jul 20 20:26:29 EDT 2004
Log message for revision 26644:
Added test LDAP adapter and view for to test the LDAP connection
Changed:
U ldapauth/trunk/browser/checkconnection.pt
U ldapauth/trunk/browser/checkconnection.py
U ldapauth/trunk/configure.zcml
A ldapauth/trunk/connectiontest.py
U ldapauth/trunk/interfaces.py
-=-
Modified: ldapauth/trunk/browser/checkconnection.pt
===================================================================
--- ldapauth/trunk/browser/checkconnection.pt 2004-07-20 22:36:36 UTC (rev 26643)
+++ ldapauth/trunk/browser/checkconnection.pt 2004-07-21 00:26:29 UTC (rev 26644)
@@ -1,25 +1,88 @@
<html metal:use-macro="views/standard_macros/view">
<body>
<div metal:fill-slot="body">
- <div metal:define-macro="contents">
+ <div metal:define-macro="contents"
+ tal:define="hostinfo view/getHostInfo;
+ testreport view/checkConnection">
- Here should be the form for to set the test data!
+ <form name="ldapConnectionTestForm" method="POST" action="."
+ tal:attributes="action request/URL">
- <table id="sortable" class="listing" summary="Principal listing"
- i18n:attributes="summary">
- <thead>
- <tr>
- <th i18n:translate="">Test report</th>
- </tr>
- </thead>
- <tbody>
- <tr tal:repeat="entry view/checkConnection" >
- <td>
- <span tal:content="entry">login</span>
- </td>
- </tr>
- </tbody>
- </table>
+ <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="">Login attribute name</td>
+ <td><span tal:content="python:hostinfo['login_attribute']">login_attribute</span></td>
+ </tr>
+ <tr>
+ <td i18n:translate="">Base DN</td>
+ <td><span tal:content="python:hostinfo['basedn']">basedn</span></td>
+ </tr>
+ <tr>
+ <td i18n:translate="">Manager DN</td>
+ <td><span tal:content="python:hostinfo['manager_dn']">manager_dn</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="">Username (optional)</td>
+ <td><input type="text" value="" name="username"></td>
+ </tr>
+ <tr>
+ <td i18n:translate="">Password (optional)</td>
+ <td><input type="password" value="" name="password"></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>
Modified: ldapauth/trunk/browser/checkconnection.py
===================================================================
--- ldapauth/trunk/browser/checkconnection.py 2004-07-20 22:36:36 UTC (rev 26643)
+++ ldapauth/trunk/browser/checkconnection.py 2004-07-21 00:26:29 UTC (rev 26644)
@@ -25,6 +25,7 @@
from zope.app.i18n import ZopeMessageIDFactory as _
from ldapauth.interfaces import ILDAPBasedPrincipalSource
+from ldapauth.interfaces import ILDAPTestAdapter
@@ -39,14 +40,41 @@
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['login_attribute'] = self.context.login_attribute
+ infoDict['manager_dn'] = self.context.manager_dn
+ return infoDict
+
+
def checkConnection(self):
"""Check connetction to the given LDAP server."""
- report = []
+ runtest = self.request.get('runtest', None)
+ if runtest == "Run":
+ un = self.request.get('username')
+ pw = self.request.get('password')
- self._addInfo("Report traceback")
+ # test the connection to the LDAP server
+ self._addInfo("<strong>Test LDAP server connection</strong>")
+ testadapter = ILDAPTestAdapter(self.context)
+ self.report = self.report + testadapter.testConnection()
- return self.report
+ # test quering the LDAP server
+ # test query the given username
+
+ # test authenticate the given username
+
+ self._addInfo("... more test")
+
+ return self.report
+ else:
+ return ""
+
def _addInfo(self, res):
"""Add traceback info to the report list"""
self.report.append(res)
Modified: ldapauth/trunk/configure.zcml
===================================================================
--- ldapauth/trunk/configure.zcml 2004-07-20 22:36:36 UTC (rev 26643)
+++ ldapauth/trunk/configure.zcml 2004-07-21 00:26:29 UTC (rev 26644)
@@ -22,6 +22,11 @@
</content>
+ <adapter
+ factory="ldapauth.connectiontest.LDAPTestAdapter"
+ provides="ldapauth.interfaces.ILDAPTestAdapter"
+ for="*"
+ />
<!-- add browser views -->
<include package=".browser" />
Added: ldapauth/trunk/connectiontest.py
===================================================================
--- ldapauth/trunk/connectiontest.py 2004-07-20 22:36:36 UTC (rev 26643)
+++ ldapauth/trunk/connectiontest.py 2004-07-21 00:26:29 UTC (rev 26644)
@@ -0,0 +1,62 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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$
+"""
+import ldap
+from zope.security.proxy import trustedRemoveSecurityProxy
+
+from zope.interface import implements
+from interfaces import ILDAPTestAdapter
+
+
+
+class LDAPTestAdapter:
+ """A LDAP connection test adapter."""
+
+ implements(ILDAPTestAdapter)
+
+ def __init__(self, context):
+ self.context = context
+ self.report = []
+
+ def testConnection(self):
+ self.report = []
+ source = trustedRemoveSecurityProxy(self.context)
+ self.report.append("... check existing connection")
+
+ try:
+ conn = getattr(source, '_v_conn', None)
+ if conn:
+ self.report.append('... connection "%s" found' % conn)
+ else:
+ self.report.append("... no existing connection found")
+ self.report.append("... try to connect")
+
+ if not conn:
+ connectstring = 'ldap://%s:%s' % (source.host, source.port)
+ self.report.append("... ... connecting to:")
+ self.report.append("... ... %s" % connectstring)
+ connection = ldap.initialize(connectstring)
+ self.report.append("... <strong>Connection OK!</strong>")
+ return self.report
+ else:
+ self.report.append("... <strong>Connection OK!</strong>")
+ return self.report
+ except:
+ self.report.append("... <strong>Connection test faild!</strong>")
+ return self.report
+
+
Modified: ldapauth/trunk/interfaces.py
===================================================================
--- ldapauth/trunk/interfaces.py 2004-07-20 22:36:36 UTC (rev 26643)
+++ ldapauth/trunk/interfaces.py 2004-07-21 00:26:29 UTC (rev 26644)
@@ -15,6 +15,7 @@
$Id$
"""
+from zope.interface import Interface
from zope.schema import TextLine, Int, List, Password
from zope.app.i18n import ZopeMessageIDFactory as _
@@ -49,3 +50,14 @@
title = _(u'Manager password'),
description = _(u"Manager's password"))
+
+
+class ILDAPTestAdapter(Interface):
+ """A test adapter for to test the connection between Zope and LDAP."""
+
+ def testConnection():
+ """Returns a report about connecting the LDAP server.
+
+ Each step of connecting the server is reported as a string
+ in a report (list).
+ """
More information about the Zope3-Checkins
mailing list