26#include <rtl/instance.hxx>
27#include <com/sun/star/beans/NamedValue.hpp>
28#include <com/sun/star/beans/Optional.hpp>
29#include <com/sun/star/configuration/theDefaultProvider.hpp>
32#include <osl/security.hxx>
41 OUString loggedOnUser;
43 bool bHaveLdapConfiguration =
true;
49 static osl::Mutex aInitMutex;
50 osl::MutexGuard aInitGuard(aInitMutex);
52 static bool bReentrantCall;
53 OSL_ENSURE(!bReentrantCall,
"configuration: Ldap Backend constructor called reentrantly - probably a registration error.");
57 bReentrantCall = true ;
65 xContext, &aDefinition, &loggedOnUser);
66 if (!bHaveLdapConfiguration)
67 SAL_WARN(
"extensions.config",
"LdapUserProfileBackend: LDAP not configured");
71 if (bHaveLdapConfiguration)
85 css::uno::Reference< css::uno::XComponentContext >
const & context,
88 OSL_ASSERT(context.is() && definition !=
nullptr && loggedOnUser !=
nullptr);
90 uno::Reference< XInterface > xIface;
93 uno::Reference< lang::XMultiServiceFactory > xCfgProvider(
94 css::configuration::theDefaultProvider::get(context));
96 css::beans::NamedValue aPath(
"nodepath",
uno::Any(OUString(
"org.openoffice.LDAP/UserDirectory")) );
98 uno::Sequence< uno::Any > aArgs{
uno::Any(aPath) };
100 xIface = xCfgProvider->createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationAccess", aArgs);
102 uno::Reference<container::XNameAccess > xAccess(xIface, uno::UNO_QUERY_THROW);
103 xAccess->getByName(
"ServerDefinition") >>= xIface;
105 uno::Reference<container::XNameAccess > xChildAccess(xIface, uno::UNO_QUERY_THROW);
113 xChildAccess->getByName(
"Port") >>= definition->
mPort ;
114 if (definition->
mPort == 0)
125 catch (
const uno::Exception&)
127 TOOLS_WARN_EXCEPTION(
"extensions.config",
"LdapUserProfileBackend: access to configuration data failed");
131 osl::Security aSecurityContext;
132 if (!aSecurityContext.getUserName(*loggedOnUser))
133 SAL_WARN(
"extensions.config",
"LdapUserProfileBackend - could not get Logged on user from system");
135 sal_Int32
nIndex = loggedOnUser->indexOf(
'/');
137 *loggedOnUser = loggedOnUser->copy(
nIndex+1);
144 uno::Reference<container::XNameAccess>
const & xAccess,
145 const OUString& aLdapSetting,
146 OUString& aServerParameter)
148 xAccess->getByName(aLdapSetting) >>= aServerParameter;
150 return !aServerParameter.isEmpty();
154 OUString
const &, css::uno::Any
const &)
156 throw css::lang::IllegalArgumentException(
157 "setPropertyValue not supported",
162 OUString
const & PropertyName)
164 for (sal_Int32
i = 0;;) {
165 sal_Int32 j = PropertyName.indexOf(
',',
i);
167 j = PropertyName.getLength();
170 throw css::beans::UnknownPropertyException(
173 LdapData::iterator k(
data_.find(PropertyName.copy(
i, j -
i)));
174 if (k !=
data_.end()) {
175 return css::uno::Any(
176 css::beans::Optional< css::uno::Any >(
177 true, css::uno::Any(k->second)));
179 if (j == PropertyName.getLength()) {
184 return css::uno::Any(css::beans::Optional< css::uno::Any >());
190 return "com.sun.star.comp.configuration.backend.LdapUserProfileBe";
198uno::Sequence<OUString>
201 return {
"com.sun.star.configuration.backend.LdapUserProfileBe" };
206extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
208 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
Class encapsulating all LDAP functionality.
void connectSimple(const LdapDefinition &aDefinition)
Make connection to LDAP server.
void getUserProfile(const OUString &aUser, LdapData *data)
Gets LdapUserProfile from LDAP repository for specified user.
Implements the PlatformBackend service, a specialization of the XPropertySet service for retrieving L...
LdapUserProfileBe(const uno::Reference< uno::XComponentContext > &xContext)
virtual OUString SAL_CALL getImplementationName() override
static bool getLdapStringParam(uno::Reference< container::XNameAccess > const &xAccess, const OUString &aLdapSetting, OUString &aServerParameter)
virtual sal_Bool SAL_CALL supportsService(const OUString &aServiceName) override
virtual void SAL_CALL setPropertyValue(OUString const &, css::uno::Any const &) override
virtual ~LdapUserProfileBe() override
virtual css::uno::Any SAL_CALL getPropertyValue(OUString const &PropertyName) override
virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
static bool readLdapConfiguration(uno::Reference< uno::XComponentContext > const &context, LdapDefinition *definition, OUString *loggedOnUser)
Check if LDAP is configured.
#define TOOLS_WARN_EXCEPTION(area, stream)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_ldp_LdapUserProfileBe_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define SAL_WARN(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
cppu::WeakComponentImplHelper< css::beans::XPropertySet, lang::XServiceInfo > BackendBase
Struct containing the information on LDAP connection.
OUString mAnonUser
DN to use for "anonymous" connection.
OUString mServer
LDAP server name.
OUString mUserObjectClass
User Entity Object Class.
OUString mUserUniqueAttr
User Entity Unique Attribute.
OUString mAnonCredentials
Credentials to use for "anonymous" connection.
OUString mBaseDN
Repository base DN.
sal_Int32 mPort
LDAP server port number.