Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #ifndef EXTENSIONS_CONFIG_LDAP_LDAPACCESS_HXX_
21 : : #define EXTENSIONS_CONFIG_LDAP_LDAPACCESS_HXX_
22 : :
23 : : #include "sal/config.h"
24 : :
25 : : #include <map>
26 : :
27 : : #ifdef WNT
28 : : #include <windows.h>
29 : : #include <winldap.h>
30 : : #else // !defined WNT
31 : : #include <ldap.h>
32 : : #endif // WNT
33 : :
34 : : #include <com/sun/star/ldap/LdapGenericException.hpp>
35 : :
36 : : #include <com/sun/star/ldap/LdapConnectionException.hpp>
37 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
38 : : #include <osl/module.h>
39 : :
40 : : namespace extensions { namespace config { namespace ldap {
41 : :
42 : : namespace css = com::sun::star ;
43 : : namespace uno = css::uno ;
44 : : namespace lang = css::lang ;
45 : : namespace ldap = css::ldap ;
46 : : //------------------------------------------------------------------------------
47 : : struct LdapUserProfile;
48 : :
49 : : //------------------------------------------------------------------------------
50 : : /** Struct containing the information on LDAP connection */
51 : 0 : struct LdapDefinition
52 : : {
53 : : /** LDAP server name */
54 : : rtl::OUString mServer ;
55 : : /** LDAP server port number */
56 : : sal_Int32 mPort ;
57 : : /** Repository base DN */
58 : : rtl::OUString mBaseDN ;
59 : : /** DN to use for "anonymous" connection */
60 : : rtl::OUString mAnonUser ;
61 : : /** Credentials to use for "anonymous" connection */
62 : : rtl::OUString mAnonCredentials ;
63 : : /** User Entity Object Class */
64 : : rtl::OUString mUserObjectClass;
65 : : /** User Entity Unique Attribute */
66 : : rtl::OUString mUserUniqueAttr;
67 : : } ;
68 : :
69 : : typedef std::map< rtl::OUString, rtl::OUString > LdapData; // key/value pairs
70 : :
71 : : /** Class encapulating all LDAP functionality */
72 : : class LdapConnection
73 : : {
74 : : friend struct LdapMessageHolder;
75 : : public:
76 : :
77 : : /** Default constructor */
78 : 0 : LdapConnection(void) : mConnection(NULL),mLdapDefinition() {}
79 : : /** Destructor, releases the connection */
80 : : ~LdapConnection(void) ;
81 : : /** Make connection to LDAP server */
82 : : void connectSimple(const LdapDefinition& aDefinition)
83 : : throw (ldap::LdapConnectionException,
84 : : ldap::LdapGenericException);
85 : :
86 : : /**
87 : : Gets LdapUserProfile from LDAP repository for specified user
88 : : @param aUser name of logged on user
89 : : @param aUserProfileMap Map containing LDAP->00o mapping
90 : : @param aUserProfile struct for holding OOo values
91 : :
92 : : @throws com::sun::star::ldap::LdapGenericException
93 : : if an LDAP error occurs.
94 : : */
95 : : void getUserProfile(const rtl::OUString& aUser, LdapData * data)
96 : : throw (lang::IllegalArgumentException,
97 : : ldap::LdapConnectionException,
98 : : ldap::LdapGenericException);
99 : :
100 : : /** finds DN of user
101 : : @return DN of User
102 : : */
103 : : rtl::OUString findUserDn(const rtl::OUString& aUser)
104 : : throw (lang::IllegalArgumentException,
105 : : ldap::LdapConnectionException,
106 : : ldap::LdapGenericException);
107 : :
108 : : private:
109 : :
110 : : void initConnection()
111 : : throw (ldap::LdapConnectionException);
112 : : void disconnect();
113 : : /**
114 : : Indicates whether the connection is in a valid state.
115 : : @return sal_True if connection is valid, sal_False otherwise
116 : : */
117 : 0 : bool isValid(void) const { return mConnection != NULL ; }
118 : :
119 : : void connectSimple()
120 : : throw (ldap::LdapConnectionException,
121 : : ldap::LdapGenericException);
122 : :
123 : : /** LDAP connection object */
124 : : LDAP* mConnection ;
125 : : LdapDefinition mLdapDefinition;
126 : : } ;
127 : :
128 : : //------------------------------------------------------------------------------
129 : : }} }
130 : :
131 : : #endif // EXTENSIONS_CONFIG_LDAP_LDAPUSERPROFILE_HXX_
132 : :
133 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|