1
- package com .iat .tpldapapachedirectory ;
1
+ package com .iat .tpldapapachedirectory . service ;
2
2
3
+ import com .iat .tpldapapachedirectory .model .User ;
3
4
import org .apache .directory .api .ldap .model .cursor .CursorException ;
4
5
import org .apache .directory .api .ldap .model .cursor .EntryCursor ;
5
6
import org .apache .directory .api .ldap .model .entry .*;
6
7
import org .apache .directory .api .ldap .model .exception .LdapException ;
7
8
import org .apache .directory .api .ldap .model .message .SearchScope ;
8
9
import org .apache .directory .ldap .client .api .LdapConnection ;
10
+ import org .springframework .beans .factory .annotation .Autowired ;
9
11
import org .springframework .stereotype .Component ;
10
12
11
13
import java .io .IOException ;
14
+ import java .util .ArrayList ;
15
+ import java .util .List ;
12
16
13
17
@ Component
14
18
public class LdapQueries {
15
19
16
20
/**
17
- * Performs search using a search of all persons in a LDAP domain (SearchScope.SearchScope.SUBTREE)
21
+ * Performs search using a search of all persons in a LDAP model (SearchScope.SearchScope.SUBTREE)
18
22
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
19
- * @param domain : a LDAP domain
23
+ * @param domain : a LDAP model
20
24
*/
21
25
public void findAllPersons (LdapConnection connection , String domain ) throws LdapException , CursorException , IOException {
22
26
@@ -40,9 +44,11 @@ public void findAllPersons(LdapConnection connection, String domain) throws Ldap
40
44
/**
41
45
* Performs search using a search of all persons in a LDAP organizational unit (SearchScope.ONELEVEL)
42
46
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
43
- * @param domain : a LDAP domain
47
+ * @param domain : a LDAP model
44
48
*/
45
- public void findAllAdm (LdapConnection connection , String domain ) throws LdapException , CursorException , IOException {
49
+ public ArrayList <Entry > findAllAdm (LdapConnection connection , String domain ) throws LdapException , CursorException , IOException {
50
+
51
+ ArrayList <Entry > entries = new ArrayList <>();
46
52
47
53
// Root : ou=adm ; parse : all adm, only adm (one level)
48
54
EntryCursor cursor = connection .search ( "ou=adm, " +domain +"" , "(objectclass=*)" , SearchScope .ONELEVEL , "*" );
@@ -52,18 +58,22 @@ public void findAllAdm(LdapConnection connection, String domain) throws LdapExce
52
58
{
53
59
Entry entry = cursor .get ();
54
60
System .out .println (entry );
61
+ entries .add (entry );
55
62
nbrEntries +=1 ;
56
63
57
64
}
58
65
59
66
System .out .println ("NOMBRE TOTAL D'ENTREES : " + nbrEntries );
67
+
60
68
cursor .close ();
69
+
70
+ return entries ;
61
71
}
62
72
63
73
/**
64
74
* Add an entry (a person) to the LDAP server
65
75
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
66
- * @param domain : a LDAP domain
76
+ * @param domain : a LDAP model
67
77
* @param cn : a LDAP common name
68
78
* @param sn : a LDAP surname
69
79
*/
@@ -85,7 +95,7 @@ public void addPerson(LdapConnection connection, String domain, String cn, Strin
85
95
/**
86
96
* Delete the entry (a person) with the given distinguished name to the LDAP server
87
97
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
88
- * @param domain : a LDAP domain
98
+ * @param domain : a LDAP model
89
99
* @param cn : a LDAP common name
90
100
*/
91
101
public void deletePerson (LdapConnection connection , String domain , String cn ) throws Exception {
@@ -97,7 +107,7 @@ public void deletePerson(LdapConnection connection, String domain, String cn) th
97
107
* Applies all the modifications (add attributes + values = ModificationOperation.ADD_ATTRIBUTE)...
98
108
* ... to the entry (a person) specified by its distinguished name
99
109
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
100
- * @param domain : a LDAP domain
110
+ * @param domain : a LDAP model
101
111
* @param cn : a LDAP common name
102
112
* @param attributeId1 : first attribute to add
103
113
* @param value1 : first value to add
@@ -119,7 +129,7 @@ public void addAttributesToPerson(LdapConnection connection, String domain, Stri
119
129
* Applies all the modifications (remove attributes = ModificationOperation.REMOVE_ATTRIBUTE)...
120
130
* ... to the entry (a person) specified by its distinguished name
121
131
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
122
- * @param domain : a LDAP domain
132
+ * @param domain : a LDAP model
123
133
* @param cn : a LDAP common name
124
134
* @param attributeId1 : first attribute to remove
125
135
* @param attributeId2 : second attribute to remove
@@ -137,7 +147,7 @@ public void removeAttributesToPerson(LdapConnection connection, String domain, S
137
147
* Applies all the modifications (replace attributes + values = ModificationOperation.REPLACE_ATTRIBUTE)...
138
148
* ... to the entry (a person) specified by its distinguished name
139
149
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
140
- * @param domain : a LDAP domain
150
+ * @param domain : a LDAP model
141
151
* @param cn : a LDAP common name
142
152
* @param attributeId1 : first attribute to replace
143
153
* @param value1 : first value to replace
@@ -168,9 +178,9 @@ public void moveAndRenamePerson(LdapConnection connection, String oldDn, String
168
178
}
169
179
170
180
/**
171
- * Performs search using a search of all organizational unit in a LDAP domain (SearchScope.SearchScope.ONELEVEL)
181
+ * Performs search using a search of all organizational unit in a LDAP model (SearchScope.SearchScope.ONELEVEL)
172
182
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
173
- * @param domain : a LDAP domain
183
+ * @param domain : a LDAP model
174
184
*/
175
185
public void findAllOu (LdapConnection connection , String domain ) throws LdapException , CursorException , IOException {
176
186
@@ -193,7 +203,7 @@ public void findAllOu(LdapConnection connection, String domain) throws LdapExcep
193
203
/**
194
204
* Add an entry (an organizational unit) to the LDAP server
195
205
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
196
- * @param domain : a LDAP domain
206
+ * @param domain : a LDAP model
197
207
* @param ou : an organizational unit
198
208
*/
199
209
public void addOu (LdapConnection connection , String domain , String ou ) throws LdapException {
@@ -210,7 +220,7 @@ public void addOu(LdapConnection connection, String domain, String ou) throws Ld
210
220
/**
211
221
* Delete the entry (an organizational unit) with the given distinguished name to the LDAP server
212
222
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
213
- * @param domain : a LDAP domain
223
+ * @param domain : a LDAP model
214
224
*/
215
225
public void deleteOu (LdapConnection connection , String domain ,String ou ) throws Exception {
216
226
0 commit comments