|
@@ -1,7 +1,8 @@
|
|
|
package org.example.lc.service;
|
|
|
|
|
|
-import org.example.lc.request.AddUserReq;
|
|
|
-import org.example.lc.response.ResponseBean;
|
|
|
+import org.example.lc.pojo.request.AddUserReq;
|
|
|
+import org.example.lc.pojo.request.DelUserReq;
|
|
|
+import org.example.lc.pojo.response.ResponseBean;
|
|
|
import org.ldaptive.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -23,15 +24,15 @@ public class LdapService {
|
|
|
SearchOperation search = new SearchOperation(conn);
|
|
|
SearchResult result = search.execute(
|
|
|
new SearchRequest(
|
|
|
- baseDn, "(cn=*)")).getResult();
|
|
|
+ baseDn, filter)).getResult();
|
|
|
|
|
|
for (LdapEntry entry : result.getEntries()) {
|
|
|
// do something useful with the entry
|
|
|
System.out.println(entry.getDn());
|
|
|
- entry.getAttributes();
|
|
|
-
|
|
|
+ for(LdapAttribute attribute : entry.getAttributes()){
|
|
|
+ System.out.println(attribute.getName() + "------" + attribute.getStringValue());
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
} finally {
|
|
|
conn.close();
|
|
|
}
|
|
@@ -40,10 +41,12 @@ public class LdapService {
|
|
|
|
|
|
public ResponseBean<Boolean> addUser(AddUserReq req) throws LdapException {
|
|
|
LdapEntry entry = new LdapEntry(
|
|
|
- "cn=" + req.getUserName() + ",cn=readers,ou=users,dc=northking,dc=net",
|
|
|
- new LdapAttribute("userName", req.getUserName()),
|
|
|
- new LdapAttribute("pwd", req.getPwd()),
|
|
|
- new LdapAttribute("email", req.getEmail()));
|
|
|
+ "cn=" + req.getUserName() + ",ou=users,dc=northking,dc=net",
|
|
|
+ new LdapAttribute("objectClass", "inetOrgPerson"),
|
|
|
+ new LdapAttribute("cn", req.getUserName()),
|
|
|
+ new LdapAttribute("sn", req.getUserName()),
|
|
|
+ new LdapAttribute("userPassword", req.getPwd()),
|
|
|
+ new LdapAttribute("mail", req.getEmail()));
|
|
|
|
|
|
Connection conn = connectionFactory.getConnection();
|
|
|
try {
|
|
@@ -55,4 +58,16 @@ public class LdapService {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ public ResponseBean<Boolean> del(DelUserReq req) throws LdapException {
|
|
|
+ Connection conn = connectionFactory.getConnection();
|
|
|
+ try {
|
|
|
+ conn.open();
|
|
|
+ DeleteOperation delete = new DeleteOperation(conn);
|
|
|
+ delete.execute(new DeleteRequest("cn=" + req.getUserName() + ",ou=users,dc=northking,dc=net"));
|
|
|
+ } finally {
|
|
|
+ conn.close();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|