Skip to content

Commit 1d10c14

Browse files
clean dead code
1 parent cdfc33c commit 1d10c14

File tree

6 files changed

+74
-75
lines changed

6 files changed

+74
-75
lines changed

Diff for: src/main/java/com/iat/tpldapapachedirectory/configuration/GlobalProperties.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.springframework.boot.context.properties.ConfigurationProperties;
44

5-
@ConfigurationProperties(prefix="tp.ldap")
5+
@ConfigurationProperties(prefix = "tp.ldap")
66
public class GlobalProperties {
77

88
private String domain;

Diff for: src/main/java/com/iat/tpldapapachedirectory/dao/UserDao.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
@Component
1818
public class UserDao {
1919

20-
// documentation : https://directory.apache.org/api/user-guide/6.12-entry.html
20+
// documentation
21+
// https://directory.apache.org/api/user-guide/6.12-entry.html
22+
// https://www.tutorialspoint.com/java/java_mapentry_interface.htm
2123

2224
@Autowired
2325
LdapQueries ldapQueries;
@@ -32,7 +34,7 @@ public ArrayList<User> getAllAdmByIdAndName() throws IOException, LdapException,
3234
LdapNetworkConnection connection = connectionService.openConnection();
3335
ArrayList<Entry> entries = ldapQueries.findAllAdm(connection, globalProperties.getDomain());
3436
ArrayList<User> admins = new ArrayList<>();
35-
for (Entry entry: entries) {
37+
for (Entry entry : entries) {
3638
// TODO : vérifier si le design pattern utilisé ici (LdapQueries + UserDao + UserController) est efficient
3739
User user = new User();
3840
user.setCategory(entry.get("radiusTunnelPrivateGroupId").get().toString());

Diff for: src/main/java/com/iat/tpldapapachedirectory/model/User.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
import org.springframework.stereotype.Component;
55

6-
import java.util.List;
7-
86
@Component
9-
public class User {
7+
public class User {
108

119
private String name; // sn
1210
private String category; // radiusTunnelPrivateGroup

Diff for: src/main/java/com/iat/tpldapapachedirectory/service/ConnectionService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public LdapNetworkConnection openConnection() {
2525
globalProperties.getHost());
2626
try {
2727
// secure binding
28-
connection.bind("cn=admin,"+ globalProperties.getDomain(), globalProperties.getPassword());
28+
connection.bind("cn=admin," + globalProperties.getDomain(), globalProperties.getPassword());
2929
} catch (
3030
LdapException e) {
3131
e.printStackTrace();
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
package com.iat.tpldapapachedirectory.service;
22

3-
import com.iat.tpldapapachedirectory.model.User;
43
import org.apache.directory.api.ldap.model.cursor.CursorException;
54
import org.apache.directory.api.ldap.model.cursor.EntryCursor;
65
import org.apache.directory.api.ldap.model.entry.*;
76
import org.apache.directory.api.ldap.model.exception.LdapException;
87
import org.apache.directory.api.ldap.model.message.SearchScope;
98
import org.apache.directory.ldap.client.api.LdapConnection;
10-
import org.springframework.beans.factory.annotation.Autowired;
119
import org.springframework.stereotype.Component;
1210

1311
import java.io.IOException;
1412
import java.util.ArrayList;
15-
import java.util.List;
1613

1714
@Component
1815
public class LdapQueries {
1916

2017
/**
2118
* Performs search using a search of all persons in a LDAP model (SearchScope.SearchScope.SUBTREE)
19+
*
2220
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
23-
* @param domain : a LDAP model
21+
* @param domain : a LDAP model
2422
*/
2523
public void findAllPersons(LdapConnection connection, String domain) throws LdapException, CursorException, IOException {
2624

2725
// Root : Dn ; parse : all trees ans subtrees
28-
EntryCursor cursor = connection.search(domain, "(objectclass=*)", SearchScope.SUBTREE, "*" );
26+
EntryCursor cursor = connection.search(domain, "(objectclass=*)", SearchScope.SUBTREE, "*");
2927
int nbrEntries = 0;
3028

31-
while (cursor.next())
32-
33-
{
29+
while (cursor.next()) {
3430
Entry entry = cursor.get();
3531
System.out.println(entry);
36-
nbrEntries +=1;
32+
nbrEntries += 1;
3733

3834
}
3935

@@ -43,23 +39,23 @@ public void findAllPersons(LdapConnection connection, String domain) throws Ldap
4339

4440
/**
4541
* Performs search using a search of all persons in a LDAP organizational unit (SearchScope.ONELEVEL)
42+
*
4643
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
47-
* @param domain : a LDAP model
44+
* @param domain : a LDAP model
4845
*/
4946
public ArrayList<Entry> findAllAdm(LdapConnection connection, String domain) throws LdapException, CursorException, IOException {
5047

5148
ArrayList<Entry> entries = new ArrayList<>();
5249

5350
// Root : ou=adm ; parse : all adm, only adm (one level)
54-
EntryCursor cursor = connection.search( "ou=adm, "+domain+"", "(objectclass=*)", SearchScope.ONELEVEL, "*" );
51+
EntryCursor cursor = connection.search("ou=adm, " + domain + "", "(objectclass=*)", SearchScope.ONELEVEL, "*");
5552
int nbrEntries = 0;
5653

57-
while (cursor.next())
58-
{
54+
while (cursor.next()) {
5955
Entry entry = cursor.get();
6056
System.out.println(entry);
6157
entries.add(entry);
62-
nbrEntries +=1;
58+
nbrEntries += 1;
6359

6460
}
6561

@@ -72,48 +68,50 @@ public ArrayList<Entry> findAllAdm(LdapConnection connection, String domain) thr
7268

7369
/**
7470
* Add an entry (a person) to the LDAP server
71+
*
7572
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
76-
* @param domain : a LDAP model
77-
* @param cn : a LDAP common name
78-
* @param sn : a LDAP surname
73+
* @param domain : a LDAP model
74+
* @param cn : a LDAP common name
75+
* @param sn : a LDAP surname
7976
*/
8077
public void addPerson(LdapConnection connection, String domain, String cn, String sn) throws LdapException {
8178
connection.add(
8279
new DefaultEntry(
83-
"cn="+cn+", ou=adm, "+domain+"", // the dn
80+
"cn=" + cn + ", ou=adm, " + domain + "", // the dn
8481
"ObjectClass: inetOrgPerson",
8582
"ObjectClass: organizationalPerson",
8683
"ObjectClass: person",
8784
"ObjectClass: radiusprofile",
8885
"ObjectClass: top",
89-
"cn: "+cn+"",
90-
"sn: "+sn+"" ) );
86+
"cn: " + cn + "",
87+
"sn: " + sn + ""));
9188

92-
assertTrue(connection.exists("cn="+cn+", ou=adm, "+domain+""));
89+
assertTrue(connection.exists("cn=" + cn + ", ou=adm, " + domain + ""));
9390
}
9491

9592
/**
9693
* Delete the entry (a person) with the given distinguished name to the LDAP server
94+
*
9795
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
98-
* @param domain : a LDAP model
99-
* @param cn : a LDAP common name
96+
* @param domain : a LDAP model
97+
* @param cn : a LDAP common name
10098
*/
10199
public void deletePerson(LdapConnection connection, String domain, String cn) throws Exception {
102100

103-
connection.delete("cn="+cn+", ou=adm, "+domain+"");
101+
connection.delete("cn=" + cn + ", ou=adm, " + domain + "");
104102
}
105103

106104
/**
107105
* Applies all the modifications (add attributes + values = ModificationOperation.ADD_ATTRIBUTE)...
108106
* ... to the entry (a person) specified by its distinguished name
109-
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
110-
* @param domain : a LDAP model
111-
* @param cn : a LDAP common name
107+
*
108+
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
109+
* @param domain : a LDAP model
110+
* @param cn : a LDAP common name
112111
* @param attributeId1 : first attribute to add
113-
* @param value1 : first value to add
112+
* @param value1 : first value to add
114113
* @param attributeId2 : second attribute to add
115-
* @param value2 : second value to add
116-
*
114+
* @param value2 : second value to add
117115
*/
118116
public void addAttributesToPerson(LdapConnection connection, String domain, String cn, String attributeId1,
119117
String value1, String attributeId2, String value2) throws LdapException {
@@ -122,38 +120,38 @@ public void addAttributesToPerson(LdapConnection connection, String domain, Stri
122120
Modification addedInitials = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attributeId2,
123121
value2);
124122

125-
connection.modify("cn="+cn+", ou=adm, "+domain+"", addedGivenName, addedInitials); // the dn
123+
connection.modify("cn=" + cn + ", ou=adm, " + domain + "", addedGivenName, addedInitials); // the dn
126124
}
127125

128126
/**
129127
* Applies all the modifications (remove attributes = ModificationOperation.REMOVE_ATTRIBUTE)...
130128
* ... to the entry (a person) specified by its distinguished name
131-
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
132-
* @param domain : a LDAP model
133-
* @param cn : a LDAP common name
129+
*
130+
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
131+
* @param domain : a LDAP model
132+
* @param cn : a LDAP common name
134133
* @param attributeId1 : first attribute to remove
135134
* @param attributeId2 : second attribute to remove
136-
*
137135
*/
138136
public void removeAttributesToPerson(LdapConnection connection, String domain, String cn,
139137
String attributeId1, String attributeId2) throws LdapException {
140138
Modification removedGivenName = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, attributeId1);
141139
Modification removedInitials = new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, attributeId2);
142140

143-
connection.modify("cn="+cn+", ou=adm, "+domain+"", removedGivenName, removedInitials); // the dn
141+
connection.modify("cn=" + cn + ", ou=adm, " + domain + "", removedGivenName, removedInitials); // the dn
144142
}
145143

146144
/**
147145
* Applies all the modifications (replace attributes + values = ModificationOperation.REPLACE_ATTRIBUTE)...
148146
* ... to the entry (a person) specified by its distinguished name
149-
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
150-
* @param domain : a LDAP model
151-
* @param cn : a LDAP common name
147+
*
148+
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
149+
* @param domain : a LDAP model
150+
* @param cn : a LDAP common name
152151
* @param attributeId1 : first attribute to replace
153-
* @param value1 : first value to replace
152+
* @param value1 : first value to replace
154153
* @param attributeId2 : second attribute to replace
155-
* @param value2 : second value to replace
156-
*
154+
* @param value2 : second value to replace
157155
*/
158156
public void replaceAttributesToPerson(LdapConnection connection, String domain, String cn, String attributeId1,
159157
String value1, String attributeId2, String value2) throws LdapException {
@@ -162,14 +160,15 @@ public void replaceAttributesToPerson(LdapConnection connection, String domain,
162160
Modification replacedInitials = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE,
163161
attributeId2, value2);
164162

165-
connection.modify("cn="+cn+", ou=adm, "+domain+"", replacedGivenName, replacedInitials); // the dn
163+
connection.modify("cn=" + cn + ", ou=adm, " + domain + "", replacedGivenName, replacedInitials); // the dn
166164
}
167165

168166
/**
169167
* Move and rename the given entryDn. The old relative distinguished name will be deleted.
170-
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
171-
* @param oldDn : The old relative distinguished name will be deleted
172-
* @param newDn : The new relative distinguished name
168+
*
169+
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
170+
* @param oldDn : The old relative distinguished name will be deleted
171+
* @param newDn : The new relative distinguished name
173172
* @param deleteOldDn : Tells if the old relative distinguished name must be removed (true = removed)
174173
*/
175174
public void moveAndRenamePerson(LdapConnection connection, String oldDn, String newDn,
@@ -179,20 +178,19 @@ public void moveAndRenamePerson(LdapConnection connection, String oldDn, String
179178

180179
/**
181180
* Performs search using a search of all organizational unit in a LDAP model (SearchScope.SearchScope.ONELEVEL)
181+
*
182182
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
183-
* @param domain : a LDAP model
183+
* @param domain : a LDAP model
184184
*/
185185
public void findAllOu(LdapConnection connection, String domain) throws LdapException, CursorException, IOException {
186186

187-
EntryCursor cursor = connection.search(domain, "(objectclass=organizationalUnit)", SearchScope.ONELEVEL, "*" );
187+
EntryCursor cursor = connection.search(domain, "(objectclass=organizationalUnit)", SearchScope.ONELEVEL, "*");
188188
int nbrEntries = 0;
189189

190-
while (cursor.next())
191-
192-
{
190+
while (cursor.next()) {
193191
Entry entry = cursor.get();
194192
System.out.println(entry);
195-
nbrEntries +=1;
193+
nbrEntries += 1;
196194

197195
}
198196

@@ -202,45 +200,48 @@ public void findAllOu(LdapConnection connection, String domain) throws LdapExcep
202200

203201
/**
204202
* Add an entry (an organizational unit) to the LDAP server
203+
*
205204
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
206-
* @param domain : a LDAP model
207-
* @param ou : an organizational unit
205+
* @param domain : a LDAP model
206+
* @param ou : an organizational unit
208207
*/
209208
public void addOu(LdapConnection connection, String domain, String ou) throws LdapException {
210209
connection.add(
211210
new DefaultEntry(
212-
"ou="+ou+", "+domain+"", // the dn
211+
"ou=" + ou + ", " + domain + "", // the dn
213212
"ObjectClass: organizationalUnit",
214213
"ObjectClass: top",
215-
"ou: "+ou+"") );
214+
"ou: " + ou + ""));
216215

217-
assertTrue(connection.exists("ou="+ou+", "+domain+""));
216+
assertTrue(connection.exists("ou=" + ou + ", " + domain + ""));
218217
}
219218

220219
/**
221220
* Delete the entry (an organizational unit) with the given distinguished name to the LDAP server
221+
*
222222
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
223-
* @param domain : a LDAP model
223+
* @param domain : a LDAP model
224224
*/
225-
public void deleteOu(LdapConnection connection, String domain,String ou) throws Exception {
225+
public void deleteOu(LdapConnection connection, String domain, String ou) throws Exception {
226226

227-
connection.delete("ou="+ou+", "+domain+"");
227+
connection.delete("ou=" + ou + ", " + domain + "");
228228
}
229229

230230
/**
231231
* Renames the given entryDn with new relative distinguished name and deletes the old relative distinguished name
232232
* if deleteOldRdn is set to true
233-
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
234-
* @param entryDn : The old relative distinguished name will be deleted
235-
* @param newDn : The new relative distinguished name
233+
*
234+
* @param connection : an instance of LdapNetworkConnection (interface LdapConnection)
235+
* @param entryDn : The old relative distinguished name will be deleted
236+
* @param newDn : The new relative distinguished name
236237
* @param deleteOldDn : Tells if the old relative distinguished name must be removed (true = removed)
237238
*/
238239
public void renameOu(LdapConnection connection, String entryDn, String newDn,
239-
boolean deleteOldDn) throws LdapException {
240+
boolean deleteOldDn) throws LdapException {
240241
connection.moveAndRename(entryDn, newDn, deleteOldDn);
241242
}
242243

243244

244-
245-
private void assertTrue(boolean exists) { }
245+
private void assertTrue(boolean exists) {
246+
}
246247
}

Diff for: src/main/java/com/iat/tpldapapachedirectory/web/UserController.java

-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import com.iat.tpldapapachedirectory.configuration.GlobalProperties;
44
import com.iat.tpldapapachedirectory.dao.UserDao;
55
import com.iat.tpldapapachedirectory.model.User;
6-
import com.iat.tpldapapachedirectory.service.LdapQueries;
76
import com.iat.tpldapapachedirectory.service.ConnectionService;
87
import org.apache.directory.api.ldap.model.cursor.CursorException;
98
import org.apache.directory.api.ldap.model.exception.LdapException;
10-
import org.apache.directory.ldap.client.api.LdapNetworkConnection;
119
import org.springframework.beans.factory.annotation.Autowired;
1210
import org.springframework.stereotype.Controller;
1311
import org.springframework.ui.Model;

0 commit comments

Comments
 (0)