Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / config / ldap / ldapaccess.hxx
blob45ac6b0e91a27a6e07d4992c8bc85971a3a6cbe7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_EXTENSIONS_SOURCE_CONFIG_LDAP_LDAPACCESS_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_CONFIG_LDAP_LDAPACCESS_HXX
23 #include <sal/config.h>
25 #include <map>
27 #ifdef _WIN32
28 #if !defined WIN32_LEAN_AND_MEAN
29 # define WIN32_LEAN_AND_MEAN
30 #endif
31 #include <windows.h>
32 #include <winldap.h>
33 #else // !defined WNT
34 #include <ldap.h>
35 #endif // WNT
37 #include <com/sun/star/ldap/LdapGenericException.hpp>
39 #include <com/sun/star/ldap/LdapConnectionException.hpp>
40 #include <com/sun/star/lang/IllegalArgumentException.hpp>
41 #include <osl/module.h>
43 namespace extensions { namespace config { namespace ldap {
45 namespace uno = css::uno ;
46 namespace lang = css::lang ;
47 namespace ldap = css::ldap ;
49 struct LdapUserProfile;
52 /** Struct containing the information on LDAP connection */
53 struct LdapDefinition
55 /** LDAP server name */
56 OUString mServer ;
57 /** LDAP server port number */
58 sal_Int32 mPort ;
59 /** Repository base DN */
60 OUString mBaseDN ;
61 /** DN to use for "anonymous" connection */
62 OUString mAnonUser ;
63 /** Credentials to use for "anonymous" connection */
64 OUString mAnonCredentials ;
65 /** User Entity Object Class */
66 OUString mUserObjectClass;
67 /** User Entity Unique Attribute */
68 OUString mUserUniqueAttr;
70 LdapDefinition()
71 : mPort(0)
76 typedef std::map< OUString, OUString > LdapData; // key/value pairs
78 /** Class encapsulating all LDAP functionality */
79 class LdapConnection
81 friend struct LdapMessageHolder;
82 public:
84 /** Default constructor */
85 LdapConnection() : mConnection(nullptr),mLdapDefinition() {}
86 /** Destructor, releases the connection */
87 ~LdapConnection() ;
88 /** Make connection to LDAP server
89 @throws ldap::LdapConnectionException
90 @throws ldap::LdapGenericException
92 void connectSimple(const LdapDefinition& aDefinition);
94 /**
95 Gets LdapUserProfile from LDAP repository for specified user
96 @param aUser name of logged on user
97 @param aUserProfileMap Map containing LDAP->00o mapping
98 @param aUserProfile struct for holding OOo values
100 @throws css::ldap::LdapGenericException
101 if an LDAP error occurs.
103 void getUserProfile(const OUString& aUser, LdapData * data);
105 /** finds DN of user
106 @return DN of User
107 @throws lang::IllegalArgumentException
108 @throws ldap::LdapConnectionException
109 @throws ldap::LdapGenericException
111 OUString findUserDn(const OUString& aUser);
113 private:
114 /// @throws ldap::LdapConnectionException
115 void initConnection();
116 void disconnect();
118 Indicates whether the connection is in a valid state.
119 @return sal_True if connection is valid, sal_False otherwise
121 bool isValid() const { return mConnection != nullptr ; }
123 /// @throws ldap::LdapConnectionException
124 /// @throws ldap::LdapGenericException
125 void connectSimple();
127 /** LDAP connection object */
128 LDAP* mConnection ;
129 LdapDefinition mLdapDefinition;
133 }} }
135 #endif // EXTENSIONS_CONFIG_LDAP_LDAPUSERPROFILE_HXX_
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */