summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2004-08-03 13:38:06 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2004-08-03 13:38:06 +0000
commit4c58df1dd5e8de3fc0cee92955ca5d3877641fa9 (patch)
tree2a80af52689f124d9da26b24e23440e5f4726805 /extensions
parent7800a1f8a30f7b0807f919b9ff55cbe61b35781a (diff)
INTEGRATION: CWS scmtoapoc (1.1.2); FILE ADDED
2004/04/22 09:10:37 ssmith 1.1.2.1: #115692# ldap user profile backend
Diffstat (limited to 'extensions')
-rw-r--r--extensions/source/config/ldap/ldapaccess.cxx293
-rw-r--r--extensions/source/config/ldap/ldapaccess.hxx176
-rw-r--r--extensions/source/config/ldap/ldapbe2.uno.xml45
3 files changed, 514 insertions, 0 deletions
diff --git a/extensions/source/config/ldap/ldapaccess.cxx b/extensions/source/config/ldap/ldapaccess.cxx
new file mode 100644
index 000000000000..18277c6aaa3f
--- /dev/null
+++ b/extensions/source/config/ldap/ldapaccess.cxx
@@ -0,0 +1,293 @@
+/*************************************************************************
+ *
+ * $RCSfile: ldapaccess.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: hr $ $Date: 2004-08-03 14:37:45 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef EXTENSIONS_CONFIG_LDAP_LDAPACCESS_HXX_
+#include "ldapaccess.hxx"
+#endif // EXTENSIONS_CONFIG_LDAP_LDAPACCESS_HXX_
+
+#ifndef _RTL_USTRBUF_HXX_
+#include <rtl/ustrbuf.hxx>
+#endif // _RTL_USTRBUF_HXX_
+
+
+namespace extensions { namespace config { namespace ldap {
+
+
+//------------------------------------------------------------------------------
+
+LdapConnection::~LdapConnection(void)
+{
+ if (mConnection != NULL) { ldap_unbind_s(mConnection) ; }
+}
+//------------------------------------------------------------------------------
+
+static void checkLdapReturnCode(const sal_Char *aOperation,
+ sal_Int32 aRetCode,
+ LDAP * aConnection)
+{
+ if (aRetCode == LDAP_SUCCESS) { return ; }
+ static const sal_Char *kNoSpecificMessage = "No additional information" ;
+ rtl::OUStringBuffer message ;
+
+ if (aOperation != NULL)
+ {
+ message.appendAscii(aOperation).appendAscii(": ") ;
+ }
+ message.appendAscii(ldap_err2string(aRetCode)).appendAscii(" (") ;
+ sal_Char *stub = NULL ;
+
+ ldap_get_lderrno(aConnection, NULL, &stub) ;
+ if (stub != NULL)
+ {
+ message.appendAscii(stub) ;
+ // It would seem the message returned is actually
+ // not a copy of a string but rather some static
+ // string itself. At any rate freeing it seems to
+ // cause some undue problems at least on Windows.
+ // This call is thus disabled for the moment.
+ //ldap_memfree(stub) ;
+ }
+ else { message.appendAscii(kNoSpecificMessage) ; }
+ message.appendAscii(")") ;
+ throw ldap::LdapGenericException(message.makeStringAndClear(),
+ NULL, aRetCode) ;
+}
+//------------------------------------------------------------------------------
+void LdapConnection::connectSimple(const LdapDefinition& aDefinition)
+ throw (ldap::LdapGenericException)
+{
+ mLdapDefinition = aDefinition;
+ connectSimple();
+}
+//------------------------------------------------------------------------------
+void LdapConnection::connectSimple()
+ throw (ldap::LdapGenericException)
+{
+ if (!isValid())
+ {
+ // Connect to the server
+ initConnection() ;
+ // Set Protocol V3
+ sal_Int32 version = LDAP_VERSION3;
+ ldap_set_option(mConnection,
+ LDAP_OPT_PROTOCOL_VERSION,
+ &version);
+ /* timeout is specified in milliseconds -> 4 seconds*/
+ int timeout = 4000;
+ ldap_set_option( mConnection,
+ LDAP_X_OPT_CONNECT_TIMEOUT,
+ &timeout );
+
+ // Do the bind
+ sal_Int32 retCode = ldap_simple_bind_s(mConnection,
+ mLdapDefinition.mAnonUser ,
+ mLdapDefinition.mAnonCredentials) ;
+
+ checkLdapReturnCode("SimpleBind", retCode, mConnection) ;
+ }
+}
+//------------------------------------------------------------------------------
+void LdapConnection::initConnection()
+ throw (backend::BackendSetupException)
+{
+ mConnection = ldap_init(mLdapDefinition.mServer,
+ mLdapDefinition.mPort) ;
+ if (mConnection == NULL)
+ {
+ rtl::OUStringBuffer message ;
+
+ message.appendAscii("Cannot initialise connection to server ") ;
+ message.appendAscii(mLdapDefinition.mServer) ;
+ message.appendAscii(":") ;
+ message.append(mLdapDefinition.mPort) ;
+ throw backend::BackendSetupException(message.makeStringAndClear(),
+ NULL, uno::Any()) ;
+ }
+}
+//------------------------------------------------------------------------------
+ void LdapConnection::getUserProfile(const rtl::OUString& aUser,
+ const LdapUserProfileMap& aUserProfileMap,
+ LdapUserProfile& aUserProfile)
+ throw (ldap::LdapGenericException)
+ {
+ if (!isValid())
+ {
+ connectSimple();
+ }
+ rtl::OString aUserDn =findUserDn(
+ rtl::OUStringToOString(aUser, RTL_TEXTENCODING_ASCII_US));
+ LDAPMessage *result = NULL ;
+ sal_Int32 retCode = ldap_search_s(mConnection,
+ aUserDn,
+ LDAP_SCOPE_BASE,
+ "(objectclass=*)",
+ const_cast<sal_Char **>(aUserProfileMap.getLdapAttributes()),
+ 0, // Attributes + values
+ &result) ;
+
+ checkLdapReturnCode("getUserProfile", retCode,mConnection) ;
+
+
+ aUserProfileMap.ldapToUserProfile(mConnection,
+ result,
+ aUserProfile) ;
+ ldap_msgfree(result) ;
+
+ }
+//------------------------------------------------------------------------------
+ rtl::OString LdapConnection::findUserDn(const rtl::OString& aUser)
+ throw (ldap::LdapGenericException)
+{
+
+ if (!isValid())
+ {
+ connectSimple();
+ }
+ if (aUser.equals(""))
+ {
+ throw backend::BackendSetupException(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
+ ("LdapConnection::findUserDn -User id is empty")),
+ NULL, uno::Any()) ;
+ }
+
+
+
+ rtl::OString filter = "(&(objectclass=" ;
+
+ filter += mLdapDefinition.mUserObjectClass+ ")(" ;
+ filter += mLdapDefinition.mUserUniqueAttr+ "="+ aUser + "))" ;
+ LDAPMessage *result = NULL ;
+ sal_Char * attributes [2];
+ attributes[0]= LDAP_NO_ATTRS;
+ attributes[1]= NULL;
+ sal_Int32 retCode = ldap_search_s(mConnection,
+ mLdapDefinition.mBaseDN,
+ LDAP_SCOPE_SUBTREE,
+ filter, attributes, 0, &result) ;
+
+ checkLdapReturnCode("FindUserDn", retCode,mConnection) ;
+ rtl::OString userDn ;
+ LDAPMessage *entry = ldap_first_entry(mConnection, result) ;
+
+ if (entry != NULL)
+ {
+ sal_Char *charsDn = ldap_get_dn(mConnection, entry) ;
+
+ userDn = charsDn ;
+ ldap_memfree(charsDn) ;
+ }
+ else
+ {
+ OSL_ENSURE( false, "LdapConnection::findUserDn-could not get DN for User ");
+ }
+ ldap_msgfree(result) ;
+ return userDn ;
+}
+//------------------------------------------------------------------------------
+rtl::OString LdapConnection::getSingleAttribute(
+ const rtl::OString& aDn,
+ const rtl::OString& aAttribute)
+ throw (ldap::LdapGenericException)
+{
+ if (!isValid())
+ {
+ connectSimple();
+ }
+ const sal_Char *attributes [2] ;
+ rtl::OString value ;
+
+ attributes [0] = aAttribute ;
+ attributes [1] = 0 ;
+ LDAPMessage *result = NULL ;
+ sal_Int32 retCode = ldap_search_s(mConnection,
+ aDn,
+ LDAP_SCOPE_BASE,
+ "(objectclass=*)",
+ const_cast<sal_Char **>(attributes),
+ 0, // Attributes + values
+ &result) ;
+
+ if (retCode == LDAP_NO_SUCH_OBJECT)
+ {
+ return value ;
+ }
+ checkLdapReturnCode("GetSingleAttribute", retCode, mConnection) ;
+ LDAPMessage *entry = ldap_first_entry(mConnection, result) ;
+
+ if (entry != NULL)
+ {
+ sal_Char **values = ldap_get_values(mConnection, entry,
+ aAttribute) ;
+
+ if (values != NULL)
+ {
+ if (*values != NULL) { value = *values ; }
+ ldap_value_free(values) ;
+ }
+ }
+ ldap_msgfree(result) ;
+ return value ;
+}
+
+//------------------------------------------------------------------------------
+} } } // extensions.config.ldap
+
diff --git a/extensions/source/config/ldap/ldapaccess.hxx b/extensions/source/config/ldap/ldapaccess.hxx
new file mode 100644
index 000000000000..e3e9a15be0d0
--- /dev/null
+++ b/extensions/source/config/ldap/ldapaccess.hxx
@@ -0,0 +1,176 @@
+/*************************************************************************
+ *
+ * $RCSfile: ldapaccess.hxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: hr $ $Date: 2004-08-03 14:37:56 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards OOurce License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free OOftware; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free OOftware Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free OOftware
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards OOurce License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * OOurce License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * OOftware provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE OOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the OOftware.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef EXTENSIONS_CONFIG__LDAP_LDAPACCESS_HXX_
+#define EXTENSIONS_CONFIG_LDAP_LDAPACCESS_HXX_
+
+#ifndef EXTENSIONS_CONFIG_LDAP_LDAPUSERPROF_HXX_
+#include "ldapuserprof.hxx"
+#endif // EXTENSIONS_CONFIG_LDAP_LDAPUSERPROF_HXX_
+
+#ifndef LDAP_INCLUDED
+#define LDAP_INCLUDED
+#include <mozilla/ldap/ldap.h>
+#endif // LDAP_INCLUDED
+
+#ifndef _COM_SUN_STAR_LDAP_LDAPGENERICEXCEPTION_HPP_
+#include <com/sun/star/ldap/LdapGenericException.hpp>
+#endif // _COM_SUN_STAR_LDAP_LDAPGENERICEXCEPTION_HPP_
+#ifndef _COM_SUN_STAR_CONFIGURATION_BACKEND_BACKENDSETUPEXCEPTION_HPP_
+#include <com/sun/star/configuration/backend/BackendSetupException.hpp>
+#endif // _COM_SUN_STAR_CONFIGURATION_BACKEND_BACKENDSETUPEXCEPTION_HPP_
+
+namespace extensions { namespace config { namespace ldap {
+
+namespace css = com::sun::star ;
+namespace uno = css::uno ;
+namespace backend = css::configuration::backend ;
+namespace ldap = css::ldap ;
+//------------------------------------------------------------------------------
+/** Struct containing the information on LDAP connection */
+struct LdapDefinitionStruct
+{
+ /** LDAP server name */
+ rtl::OString mServer ;
+ /** LDAP server port number */
+ sal_Int32 mPort ;
+ /** Repository base DN */
+ rtl::OString mBaseDN ;
+ /** DN to use for "anonymous" connection */
+ rtl::OString mAnonUser ;
+ /** Credentials to use for "anonymous" connection */
+ rtl::OString mAnonCredentials ;
+ /** User Entity Object Class */
+ rtl::OString mUserObjectClass;
+ /** User Entity Unique Attribute */
+ rtl::OString mUserUniqueAttr;
+ /** Mapping File */
+ rtl::OString mMapping;
+ } ;
+typedef LdapDefinitionStruct LdapDefinition;
+
+/** Class encapulating all LDAP functionality */
+class LdapConnection
+{
+public:
+
+ /** Default constructor */
+ LdapConnection(void) : mConnection(NULL),mLdapDefinition() {}
+ /** Destructor, releases the connection */
+ ~LdapConnection(void) ;
+ /** Make connection to LDAP server */
+ void connectSimple(const LdapDefinition& aDefinition)
+ throw (ldap::LdapGenericException);
+
+ /**
+ Gets LdapUserProfile from LDAP repository for specified user
+ @param aUser name of logged on user
+ @param aUserProfileMap Map containing LDAP->00o mapping
+ @param aUserProfile struct for holding OOo values
+
+ @throws com::sun::star::ldap::LdapGenericException
+ if an LDAP error occurs.
+ */
+ void getUserProfile(const rtl::OUString& aUser,
+ const LdapUserProfileMap& aUserProfileMap,
+ LdapUserProfile& aUserProfile)
+ throw (ldap::LdapGenericException);
+ /**
+ Retrieves a single attribute from a single entry.
+ @param aDn entry DN
+ @param aAttribute attribute name
+
+ @throws com::sun::star::ldap::LdapGenericException
+ if an LDAP error occurs.
+ */
+ rtl::OString getSingleAttribute(const rtl::OString& aDn,
+ const rtl::OString& aAttribute)
+ throw (ldap::LdapGenericException);
+
+
+
+
+ /** finds DN of user
+ @return DN of User
+ */
+ rtl::OString findUserDn(const rtl::OString& aUser)
+ throw (ldap::LdapGenericException);
+private:
+
+ void initConnection()
+ throw (backend::BackendSetupException);
+ /**
+ Indicates whether the connection is in a valid state.
+ @return sal_True if connection is valid, sal_False otherwise
+ */
+ bool isValid(void) const { return mConnection != NULL ; }
+
+ void connectSimple()
+ throw (ldap::LdapGenericException);
+
+ /** LDAP connection object */
+ LDAP* mConnection ;
+ LdapDefinition mLdapDefinition;
+} ;
+//------------------------------------------------------------------------------
+}} }
+
+#endif // EXTENSIONS_CONFIG_LDAP_LDAPUSERPROFILE_HXX_
diff --git a/extensions/source/config/ldap/ldapbe2.uno.xml b/extensions/source/config/ldap/ldapbe2.uno.xml
new file mode 100644
index 000000000000..e365e20f48aa
--- /dev/null
+++ b/extensions/source/config/ldap/ldapbe2.uno.xml
@@ -0,0 +1,45 @@
+c<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE module-description PUBLIC "-//StarOffice/DTD ComponentDescription 1.0//EN" "module-description.dtd">
+<module-description xmlns:xlink="http://www.w3.org/1999/xlink">
+ <module-name>ldapbe2.uno</module-name>
+ <component-description>
+ <author>Sarah Smith</author>
+ <name>com.sun.star.comp.configuration.backend.LdapUserProfileBe</name>
+ <description>The LdapUserProfileBe accesses User Profile settings form a configured LDAP repository</description>
+ <loader-name>com.sun.star.loader.SharedLibrary</loader-name>
+ <language>C++</language>
+ <status value="final"/>
+ <supported-service>com.sun.star.configuration.backend.LdapUserProfileBe</supported-service>
+ <supported-service>com.sun.star.configuration.backend.PlatformBackend</supported-service>
+ <supported-service>com.sun.star.configuration.backend.SingleLayerStratum</supported-service>
+ <service-dependency>com.sun.star.configuration.backend.LayerDescriber</service-dependency>
+ <type>com.sun.star.configuration.CannotLoadConfigurationException</type>
+ <type>com.sun.star.configuration.backend.BackendAccessException</type>
+ <type>com.sun.star.configuration.backend.XLayer</type>
+ <type>com.sun.star.configuration.backend.XUpdateHandler</type>
+ <type>com.sun.star.configuration.backend.XSingleLayerStratum</type>
+ <type>com.sun.star.uno.XComponentContext</type>
+ <type>com.sun.star.lang.IllegalArgumentException</type>
+ <type>com.sun.star.lang.XInitialization</type>
+ <type>com.sun.star.lang.XMultiServiceFactory</type>
+ <type>com.sun.star.lang.XServiceInfo</type>
+ <type>com.sun.star.lang.XSingleServiceFactory</type>
+ <type>com.sun.star.lang.XSingleComponentFactory</type>
+ <type>com.sun.star.lang.XTypeProvider</type>
+ <type>com.sun.star.registry.XRegistryKey</type>
+ <type>com.sun.star.uno.Any</type>
+ <type>com.sun.star.uno.Sequence</type>
+ </component-description>
+ <project-build-dependency> comphelper </project-build-dependency>
+ <project-build-dependency> vos </project-build-dependency>
+ <project-build-dependency> cppuhelper </project-build-dependency>
+ <project-build-dependency> salhelper </project-build-dependency>
+ <project-build-dependency> cppu </project-build-dependency>
+ <project-build-dependency> sal </project-build-dependency>
+ <runtime-module-dependency> comphelp2$(COM) </runtime-module-dependency>
+ <runtime-module-dependency> vos2$(COM) </runtime-module-dependency>
+ <runtime-module-dependency> cppuhelper3$(COM) </runtime-module-dependency>
+ <runtime-module-dependency> salhelper3$(COM) </runtime-module-dependency>
+ <runtime-module-dependency> cppu3 </runtime-module-dependency>
+ <runtime-module-dependency> sal3 </runtime-module-dependency>
+</module-description>