bean类

package com.cn.ccc.ggg.ldap.model;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date; /**
* 目录服务连接信息
* dq
*/
@Entity
@Table(name = "bo_ldap_info")//用户表
public class LDAPConectionInfo extends IdEntity{ private static final long serialVersionUID = 7300555212960602097L; public static final Integer ENABLE_STATUS = 1;//1:表示启用状态 public static final Integer DISABLE_STATUS = 0;// 0:表示停用状态 public static final Integer LDAP_VERSION_3 = 3;// 3:表示ldap协议版本为3.0 public static final Integer LDAP_VERSION_2 = 2;// 2:表示ldap协议版本为2.0 public static final Integer LDAP_PORT_389 = 389; //389:默认端口 private Integer userId; //用户的ID private String serverName; //服务名称 private String ip; //ip private Integer port = LDAP_PORT_389; //端口 private Integer version = LDAP_VERSION_3; //协议版本 private String baseDN; //根节点 private Integer isAnonymousBind = DISABLE_STATUS; //是否匿名访问 private String userDN; //用户DN private Integer isAppendBaseDN = DISABLE_STATUS; //是否追加根节点 private String password; //密码 private Date optTime = new Date();//操作时间 @Override
public String toString() {
return "LDAPConectionInfo{" +
"userId=" + userId +
", serverName='" + serverName + '\'' +
", ip='" + ip + '\'' +
", port=" + port +
", version=" + version +
", baseDN='" + baseDN + '\'' +
", isAnonymousBind=" + isAnonymousBind +
", userDN='" + userDN + '\'' +
", isAppendBaseDN=" + isAppendBaseDN +
", password='" + password + '\'' +
", optTime=" + optTime +
'}';
} public Integer getUserId() {
return userId;
} public void setUserId(Integer userId) {
this.userId = userId;
} public String getServerName() {
return serverName;
} public void setServerName(String serverName) {
this.serverName = serverName;
} public String getIp() {
return ip;
} public void setIp(String ip) {
this.ip = ip;
} public Integer getPort() {
return port;
} public void setPort(Integer port) {
this.port = port;
} public Integer getVersion() {
return version;
} public void setVersion(Integer version) {
this.version = version;
} public String getBaseDN() {
return baseDN;
} public void setBaseDN(String baseDN) {
this.baseDN = baseDN;
} public Integer getIsAnonymousBind() {
return isAnonymousBind;
} public void setIsAnonymousBind(Integer isAnonymousBind) {
this.isAnonymousBind = isAnonymousBind;
} public String getUserDN() {
return userDN;
} public void setUserDN(String userDN) {
this.userDN = userDN;
} public Integer getIsAppendBaseDN() {
return isAppendBaseDN;
} public void setIsAppendBaseDN(Integer isAppendBaseDN) {
this.isAppendBaseDN = isAppendBaseDN;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public Date getOptTime() {
return optTime;
} public void setOptTime(Date optTime) {
this.optTime = optTime;
} public LDAPConectionInfo(Integer userId, String serverName, String ip, Integer port, Integer version, String baseDN, Integer isAnonymousBind, String userDN, Integer isAppendBaseDN, String password, Date optTime) {
this.userId = userId;
this.serverName = serverName;
this.ip = ip;
this.port = port;
this.version = version;
this.baseDN = baseDN;
this.isAnonymousBind = isAnonymousBind;
this.userDN = userDN;
this.isAppendBaseDN = isAppendBaseDN;
this.password = password;
this.optTime = optTime;
} public LDAPConectionInfo() {
}
}

Service类

package com.cn.ccc.ggg.ldap.service;

import com.cn.ccc.ggg.encrypt.core.dao.HibernateEntityDao;
import com.cn.ccc.ggg.encrypt.core.dao.support.Page;
import com.cn.ccc.ggg.ldap.bean.entryInfo.PersonEntry;
import com.cn.ccc.ggg.ldap.core.common.LDIFReader;
import com.cn.ccc.ggg.ldap.core.novell.LDAPExport;
import com.cn.ccc.ggg.ldap.exception.LDAPException;
import com.cn.ccc.ggg.ldap.model.CertList;
import com.cn.ccc.ggg.ldap.model.LDAPConectionInfo; import com.novell.ldap.*;
import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service; import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import java.io.*;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.*; /**
* 目录服务连接信息管理
*/
@Service("ldapConectionInfoService")
public class LDAPConectionInfoService extends HibernateEntityDao<LDAPConectionInfo> { public static int DEFAULT_PAGE_SIZE = 500; private int pageSize = DEFAULT_PAGE_SIZE; // 每页的记录数 private String msg = new String(); private Integer d = new Integer(0); /**
* @description:查询目录服务列表
* @param: [condition, pageNo, pageSize]
* @return: com.cn.ccc.ggg.encrypt.core.dao.support.Page
* @exception:
* @author: dq
* @date: 13:39 2018/1/26
*/
public Page findserverList(Map<String, Object> condition, int pageNo, int pageSize) throws LDAPException {
ArrayList<Criterion> criteria = new ArrayList<Criterion>();
if (condition.get("userId") != null) {
Integer id = (Integer) condition.get("userId");
criteria.add(Restrictions.eq("userId", id));
}
return pagedQuery(LDAPConectionInfo.class, pageNo, pageSize, "optTime", false, criteria.toArray(new Criterion[]{}));
} public LDAPConectionInfo findServerInfoByUserIdAndServerName(int id, String serverName) {
List<LDAPConectionInfo> list = createCriteria(LDAPConectionInfo.class, Restrictions.and(Restrictions.eq("userId", id), Restrictions.eq("serverName", serverName))).list();
if (list.size() > 0)
return list.get(0);
else
return null;
} /**
* @description:连接并绑定目录服务系统,支持匿名访问,简单认证。不支持ssl连接。自动追加数据库名称
* @param: [currinfo] 连接信息
* @return: com.novell.ldap.LDAPConnection
* @exception:
* @author: dq
* @date: 13:39 2018/1/26
*/
public LDAPConnection connectionLDAP(LDAPConectionInfo currinfo) {
LDAPConnection lc = new LDAPConnection();
try {
//连接目录服务
lc.connect(currinfo.getIp(), currinfo.getPort());
//绑定服务
if (currinfo.getIsAnonymousBind() == 1) { //匿名访问
lc.bind(null, null);
} else { //简单认证
String loginDN = currinfo.getUserDN();
if (currinfo.getIsAppendBaseDN().equals(LDAPConectionInfo.ENABLE_STATUS)) //检查是否追加数据库名称
loginDN = currinfo.getUserDN() + "," + currinfo.getBaseDN();
lc.bind(currinfo.getVersion(), loginDN, currinfo.getPassword().getBytes("UTF8"));
}
} catch (com.novell.ldap.LDAPException e) {
d = 1;
getErrorMsg(e);
//连接失败
return null;
} catch (UnsupportedEncodingException e) {
//转码异常
msg = "编码异常";
}
return lc;
} public Map<String,Object> getNumberOfEntries(LDAPConectionInfo info,String searchDN){
HashMap<String, Object> hashMap = new HashMap<String, Object>();
String searfiler = "(objectclass=*)";
LDAPConnection lc = connectionLDAP(info);
long total = 0L;
d = 0;
try {
String attrs[] = {LDAPConnection.NO_ATTRS};
LDAPSearchResults s = lc.search(searchDN, LDAPConnection.SCOPE_SUB,searfiler,attrs,true);
while (s.hasMore()) {
s.next();
total++;
//TODO 异常处理
} } catch (com.novell.ldap.LDAPException e) {
d = 1;
getErrorMsg(e);
}
hashMap.put("status",d);
hashMap.put("msg",msg);
hashMap.put("total",total);
return hashMap;
} /**
* @description:根据ip、port获取ldap的根节点
* @param: [ip, port]
* @return: java.util.List<java.util.Map < java.lang.String , java.lang.Object>>
* @exception:
* @author: dq
* @date: 9:54 2018/2/26
*/
public List<Map<String,Object>> getSuffix(String ip,int port) {
d = 0;msg = "";
LDAPConnection lc = new LDAPConnection();
List<Map<String, Object>> arrayList = new ArrayList<Map<String, Object>>();
HashMap<String, Object> map = new HashMap<String, Object>();
try {
lc.connect(ip,port);
} catch (com.novell.ldap.LDAPException e) {
d = 1;
msg = "获取数据库名称失败,请检查ip和端口是否正确以及服务是否开启";
logger.error(msg);
return null;
}
String [] context = {"namingContexts"};
try {
LDAPSearchResults search = lc.search("", 0, "objectclass=*", context, false);
while (search.hasMore()){
LDAPEntry ldapEntry = search.next();
LDAPAttributeSet attributeSet = ldapEntry.getAttributeSet();
Iterator iterator = attributeSet.iterator();
while (iterator.hasNext()){
LDAPAttribute next = (LDAPAttribute)iterator.next();
String nextName = next.getName();
if(nextName.equals("namingContexts")){
Enumeration stringValues = next.getStringValues();
while (stringValues.hasMoreElements()){
HashMap<String, Object> hashMap = new HashMap<String, Object>();
String dn = (String)stringValues.nextElement();
hashMap.put("DN",dn);
arrayList.add(hashMap);
}
}
}
}
} catch (com.novell.ldap.LDAPException e) {
e.printStackTrace();
d = 1;
msg = "获取数据库名称失败";
return null;
}
return arrayList; } public Map<String,Object> importLDIF(LDAPConectionInfo info, File ldifFile){
Integer errorSign = 0;
Integer successSign = 0;
LDIFReader reader = null;
LDAPEntry entry;
LDAPMessage msg, retMsg;
LDAPConnection lc = new LDAPConnection();
Map<String, Object> hashMap = new HashMap<String, Object>();
try {
FileInputStream fis = new FileInputStream(ldifFile);
reader = new LDIFReader(fis, 1);
} catch (Exception e) {
logger.error("读取 " + ldifFile +"文件失败"+e.getMessage());
}
try {
lc.connect( info.getIp(), info.getPort() );
String loginDN = info.getUserDN();
if(info.getIsAppendBaseDN().equals(LDAPConectionInfo.ENABLE_STATUS)) //检查是否追加数据库名称
loginDN = info.getUserDN()+","+info.getBaseDN();
lc.bind( info.getVersion(), loginDN, info.getPassword().getBytes("UTF8") );
if (!reader.isRequest()) {
while ( (msg = reader.readMessage()) != null) {
entry = ((LDAPSearchResult)msg).getEntry();
}
} else {
while ( (msg = reader.readMessage()) != null) {
LDAPMessageQueue queue = lc.sendRequest(msg, null, null);
if ((retMsg = queue.getResponse()) != null) {
LDAPResponse response = (LDAPResponse)retMsg;
int status = response.getResultCode();
if ( status == com.novell.ldap.LDAPException.SUCCESS )
successSign++;
else {
if(status == com.novell.ldap.LDAPException.ENTRY_ALREADY_EXISTS){
successSign++;
} else{
errorSign++;
if(response.getErrorMessage().length() != 0){
logger.error("错误代码为:"+ status +response.getErrorMessage());
} } }
}
}
}
} catch( UnsupportedEncodingException e ) {
logger.error( "错误信息为:UnsupportedEncodingException");
} catch ( IOException ioe ) {
logger.error("错误信息为:IOException");
} catch ( com.novell.ldap.LDAPException le ) {
logger.error("错误信息为:LDAPException :"+le.getMessage());
}
hashMap.put("errorSign", errorSign);
hashMap.put("successSign", successSign);
return hashMap;
} /**
* @description:LDIF文件导出
* @param: [info, baseDN, filePath] 连接信息;导出的根节点;导出的路径
* @return: void
* @exception:
* @author: dq
* @date: 13:37 2018/1/26
*/
public void exportLDIF(LDAPConectionInfo info,String baseDN,String filePath){
String loginDN = info.getUserDN();
if(info.getIsAppendBaseDN().equals(LDAPConectionInfo.ENABLE_STATUS)) //检查是否追加数据库名称
loginDN = info.getUserDN()+","+info.getBaseDN();
String [] args = {info.getIp(),loginDN,info.getPassword(),baseDN,"objectClass=*",filePath};
LDAPExport export = new LDAPExport();
export.export(args); } /**
* @description:重命名属性名称,若该属性不是子节点则失败
* @param: [info, oldDN, newDN, parentDN]
* @return: java.util.Map<java.lang.String , java.lang.Object>
* @exception:
* @author: dq
* @date: 13:32 2018/1/26
*/
public Map<String,Object> renameRDN(LDAPConectionInfo info,String oldDN,String newDN,String parentDN){
d= 0;msg = "";
Map<String, Object> map = new HashMap<String, Object>();
LDAPConnection lc = connectionLDAP(info);
if(null == lc){
map.put("status",d);
map.put("msg",msg);
return map;
}
try {
lc.rename(oldDN,newDN,parentDN,true);
lc.disconnect();
} catch (com.novell.ldap.LDAPException e) {
d = 1; }
map.put("status",d);
map.put("msg",msg);
return map;
}
/**
* @description:修改指定条目的属性
* @param: [info, searchDN, attrsVal]
* @return: java.util.Map<java.lang.String , java.lang.Object>
* @exception:
* @author: dq
* @date: 13:50 2018/1/26
*/
public Map<String,Object> modifyAttrs(LDAPConectionInfo info,String searchDN,List<Map<String,Object>> attrsVal){
d= 0;msg = "";
HashMap<String, Object> map = new HashMap<String, Object>();
LDAPConnection lc = connectionLDAP(info); if(null == lc){
map.put("status",d);
map.put("msg",msg);
return map;
}
String searchFilter = "(objectclass=*)";
try {
LDAPSearchResults search = lc.search(searchDN, LDAPConnection.SCOPE_BASE, searchFilter, null, false);
while (search.hasMore()){
LDAPEntry next = search.next();
LDAPAttributeSet attributeSet = next.getAttributeSet();
Iterator iterator = attributeSet.iterator();
while (iterator.hasNext()){
LDAPAttribute attribute = (LDAPAttribute) iterator.next();
String attributeName = attribute.getName();
for (Map m: attrsVal){ //新的属性值
//动态修改条目属性值
if(m.containsKey(attributeName)) //检查key是否存在
lc.modify(searchDN,new LDAPModification(LDAPModification.ADD,new LDAPAttribute( attributeName, (String) m.get(attributeName))));
}
}
} } catch (com.novell.ldap.LDAPException e) {
d =1;
getErrorMsg(e);
}
map.put("status",d);
map.put("msg",msg);
return map;
} /**
* @description:添加条目(只支持用户和组织)
* @param: [info, person, searchDN]
* @return: java.util.Map<java.lang.String , java.lang.Object>
* @exception:
* @author: dq
* @date: 13:49 2018/1/26
*/
public Map<String,Object> addEntry(LDAPConectionInfo info, PersonEntry person,String searchDN) {
d= 0;msg = "";
Map<String, Object> map = new HashMap<String,Object>();
LDAPConnection lc = connectionLDAP(info);
if(null == lc){
map.put("status",d);
map.put("msg",msg);
return map;
}
LDAPAttributeSet attributeSet = new LDAPAttributeSet();
String [] att = {"top",person.getObjectclass()};
attributeSet.add(new LDAPAttribute("objectclass",att));
if(person.getSn().length() > 0)
attributeSet.add(new LDAPAttribute("sn",person.getSn()));
if(person.getUserPassword().length() > 0 )
attributeSet.add(new LDAPAttribute("userpassword",person.getUserPassword()));
if( person.getTelephoneNumber().length() > 0)
attributeSet.add(new LDAPAttribute("telephoneNumber",person.getTelephoneNumber()));
if( person.getDescription().length() > 0)
attributeSet.add(new LDAPAttribute("description",person.getDescription()));
if( person.getSeeAlso().length() > 0 )
attributeSet.add(new LDAPAttribute("seeAlso",person.getSeeAlso())); String dn = person.getDn() + "," + searchDN;
LDAPEntry newEntry = new LDAPEntry(dn, attributeSet);
try {
lc.add(newEntry);
lc.disconnect();
} catch (com.novell.ldap.LDAPException e) {
d= 1;
getErrorMsg(e);
}
map.put("status",d);
map.put("msg",msg);
return map; } /**
* @description:删除指定的节点,若该节点存在子节点将一并删除
* @param: [info, base, baseDN]
* @return: java.util.Map<java.lang.String , java.lang.Object>
* @exception:
* @author: dq
* @date: 13:47 2018/1/26
*/
public Map<String, Object> delete(LDAPConectionInfo info,int base, String baseDN){
d= 0;msg = "";
Map<String, Object> map = new HashMap<String, Object>();
LDAPConnection lc = connectionLDAP(info);
if(null == lc){
map.put("status",d);
map.put("msg",msg);
return map;
}
String searchFilter = "(objectclass=*)";
try {
LDAPSearchResults search = lc.search(baseDN, base, searchFilter, null, false);
while (search.hasMore()){
String dn = search.next().getDN();
delete(info,LDAPConnection.SCOPE_ONE,dn);
lc.delete(dn);
}
} catch (com.novell.ldap.LDAPException e) {
d = 1;
getErrorMsg(e);
}
map.put("msg",msg);
map.put("status",d); return map;
} /**
* @description:返回子节点的条目。
* @param: [currInfo, searchBase, searchFilter, scope, currentPageNo]
* @return: java.util.List<java.util.Map < java.lang.String , java.lang.Object>>
* @exception:
* @author: dq
* @date: 13:46 2018/1/26
*/
public List<Map<String, Object>> search(LDAPConectionInfo currInfo, String searchBase, String searchFilter, int scope,int currentPageNo) {
d= 0;msg = "";
StringBuffer str = new StringBuffer();
List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
LDAPConnection lc = connectionLDAP(currInfo);
if(null == lc){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("status",d);
map.put("msg",msg);
mapList.add(map);
return mapList;
}
long l = 0L; try {
String attrs[] = {LDAPConnection.NO_ATTRS};
LDAPSearchResults searchResults = lc.search(searchBase,
scope, // 搜索的类型,遍历、子节点、 LDAPConnection.SCOPE_BASE base 0:自身,one 1:子节点,sub 2:所有
searchFilter,
attrs, // “1.1”只返回条目名称
true);// 不返回属性和属性值
long totalCount = (long)currentPageNo * pageSize ;
long current = (long)( currentPageNo - 1 ) * pageSize + 1;
while (searchResults.hasMore()) { //遍历所有条目
Map<String, Object> map = new HashMap<String, Object>();
LDAPEntry nextEntry = null;
try {
nextEntry = searchResults.next();
} catch (com.novell.ldap.LDAPException e) {
d = 1;
HashMap<String, Object> m = new HashMap<String, Object>();
getErrorMsg(e);
m.put("status",d);
m.put("msg",msg);
mapList.add(m); // 抛出异常,进入下一个条目
if (e.getResultCode() == com.novell.ldap.LDAPException.LDAP_TIMEOUT || e.getResultCode() == com.novell.ldap.LDAPException.CONNECT_ERROR)
break;
else
continue;
}
l++;
if(l >= current && l <= totalCount){ //查询需要的条目数是介于current条至totalCount条
map.put("isParent", true);
int a = currentPageNo != 1 ? currentPageNo : 1;
map.put("pageNo",a);
String dn = nextEntry.getDN();
map.put("baseDN", dn); //保存DN
long total = getTotal(searchFilter, lc, dn);
map.put("totalRecord",total);
if (scope != 0) dn = dn.substring(0, dn.indexOf(","));
map.put("text", dn); //去除父节点名称,用于前端显示
mapList.add(map);
}
}
lc.disconnect();
} catch (com.novell.ldap.LDAPException e) {
//getErrorMsg(e);
}
return mapList;
} /**
* @description:获取节点自身的属性和属性值
* @param: [currInfo, searchBase, searchFilter]
* @return: java.util.List<java.util.Map < java.lang.String , java.lang.Object>>
* @exception:
* @author: dq
* @date: 13:45 2018/1/26
*/
public List<Map<String, Object>> attAndValue(LDAPConectionInfo currInfo, String searchBase, String searchFilter) {
d= 0;msg = "";
StringBuffer str = new StringBuffer();
LDAPConnection lc = connectionLDAP(currInfo);
List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
if(null == lc){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("status",d);
map.put("msg",msg);
mapList.add(map);
return mapList;
} try {
LDAPSearchResults searchResults = lc.search(searchBase,
LDAPConnection.SCOPE_BASE, // 搜索的类型,遍历、子节点、 LDAPConnection.SCOPE_BASE base 0:自身,one 1:子节点,sub 2:所有
searchFilter,
null, // return all attributes
false);// return attrs and values while (searchResults.hasMore()) { //遍历所有条目
Map<String, Object> map = new HashMap<String, Object>();
LDAPEntry nextEntry = null;
try {
nextEntry = searchResults.next();
} catch (com.novell.ldap.LDAPException e) {
System.out.println("Error: " + e.toString());
// Exception is thrown, go for next entry
if (e.getResultCode() == com.novell.ldap.LDAPException.LDAP_TIMEOUT || e.getResultCode() == com.novell.ldap.LDAPException.CONNECT_ERROR)
break;
else
continue;
}
map.put("baseDN", nextEntry.getDN()); //保存DN
LDAPAttributeSet attributeSet = nextEntry.getAttributeSet();
Iterator allAttributes = attributeSet.iterator();
HashMap<String, Object> hashMap = new HashMap<String, Object>(); while (allAttributes.hasNext()) { //遍历所有属性
LDAPAttribute attribute = (LDAPAttribute) allAttributes.next();
String attributeName = attribute.getName();
byte[] byteValue = attribute.getByteValue();
String s = new String(byteValue);
Enumeration byteValues = attribute.getByteValues();
if(byteValues != null){
while (byteValues.hasMoreElements()){
Object oneVal = byteValues.nextElement();
if(attributeName .endsWith("binary")){
try {
StringBuffer buffer = readCer(attributeName, oneVal);
hashMap.put(attributeName,buffer.toString());
} catch (CertificateException e) {
System.out.println(e.getMessage());
}
}else if(oneVal instanceof String ){
hashMap.put(attributeName ,(String) oneVal);
} else if(oneVal instanceof byte []){
try {
hashMap.put(attributeName ,new String ((byte[] )oneVal,"UTF-8"));
} catch (UnsupportedEncodingException e) {
//TODO
}
}
}
}
}
map.put("attributes",hashMap);
mapList.add(map);
}
lc.disconnect();
} catch (com.novell.ldap.LDAPException e) {
e.printStackTrace();
}
return mapList;
} /**
* @description:统计该节点下的所有数据量
* @param: [searchFilter, lc, nextEntry]
* @return: long
* @exception:
* @author: dq
* @date: 13:44 2018/1/26
*/
public long getTotal(String searchFilter, LDAPConnection lc, String dn) throws com.novell.ldap.LDAPException {
String attrs[] = {LDAPConnection.NO_ATTRS};
LDAPSearchResults s = lc.search(dn, LDAPConnection.SCOPE_ONE,searchFilter,attrs,true);
long total = 0L;
while (s.hasMore()) {
s.next();
total++;
//TODO 异常处理
}
return total;
} /**
* @description:解析证书
* @param: [attributeName, oneVal]
* @return: java.lang.StringBuffer 返回StringBuffer类型的字符串
* @exception:
* @author: dq
* @date: 13:43 2018/1/26
*/
public StringBuffer readCer( String attributeName, Object oneVal) throws CertificateException{
byte[] byteCert = (byte[]) oneVal;
//转换成二进制流
ByteArrayInputStream bain = new ByteArrayInputStream(byteCert);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate oCert = null;
StringBuffer buffer = new StringBuffer();
try {
oCert = (X509Certificate) cf.generateCertificate(bain);
if (null != oCert) {
String serianNum = oCert.getSerialNumber().toString(); //序列号
String issuerDn = oCert.getIssuerDN().getName(); //发布方标识名
String subDN = oCert.getSubjectDN().getName(); //主体标识
String sigAlgOID = oCert.getSigAlgOID(); //证书算法OID字符串
String noAfter = oCert.getNotAfter().toGMTString(); //证书有效期
String sigAlg = oCert.getSigAlgName().toString(); //签名算法
int version = oCert.getVersion(); //版本号
String publicKey = oCert.getPublicKey().getFormat(); //公钥 buffer.append("版本号: " + version);
buffer.append("; 序列号: " + serianNum);
buffer.append("; 签名算法: " + sigAlg);
buffer.append("; 签发者: " + issuerDn);
buffer.append("; 有效期: " + noAfter);
buffer.append("; 使用者: " + subDN);
buffer.append("; 算法OID: " + sigAlgOID);
buffer.append("; 公钥: " + publicKey);
} else {
organizeCer(buffer);
}
} catch (Exception e) {
//无法解析或者解析失败
if(attributeName.equals("userCertificate;binary")){
organizeCer(buffer);
}else{
buffer.append("binary");
}
}
return buffer;
} /**
* @description:若解析证书失败则显示N/A
* @param: [buffer]
* @return: void
* @exception:
* @author: dq
* @date: 13:42 2018/1/26
*/
public void organizeCer(StringBuffer buffer) {
buffer.append("版本号: N/A");
buffer.append("; 序列号: N/A");
buffer.append("; 签名算法: N/A");
buffer.append("; 签发者: N/A");
buffer.append("; 有效期: N/A");
buffer.append("; 使用者: N/A");
buffer.append("; 算法OID: N/A");
buffer.append("; 公钥: N/A");
} /**
* @description:将List<Map<K,V>>对象转为String类型
* @param: [search]
* @return: java.lang.String
* @exception:
* @author: dq
* @date: 13:41 2018/1/26
*/
public static String getJsonByListMap(List<Map<String, Object>> search) {
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
JSONArray json = JSONArray.fromObject(search, jsonConfig);
return json.toString();
}
/**
* @description:将Map对象转为String类型
* @param: [search]
* @return: java.lang.String
* @exception:
* @author: dq
* @date: 13:40 2018/1/26
*/
public static String getJsonByMap(Map<String, Object> search) {
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
JSONArray json = JSONArray.fromObject(search, jsonConfig);
return json.toString();
} private void getErrorMsg(com.novell.ldap.LDAPException e) {
if(e.getResultCode() == com.novell.ldap.LDAPException.OPERATIONS_ERROR) {//
msg = "操作错误";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.PROTOCOL_ERROR){//
msg = "服务器收到来自客户端的无效或格式错误的请求";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.TIME_LIMIT_EXCEEDED){//
msg = "已超出客户端或服务器指定的操作时间限制";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.SIZE_LIMIT_EXCEEDED){//
msg = "超出了客户端或服务器指定的大小限制";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.AUTH_METHOD_NOT_SUPPORTED){//
msg = "绑定操作期间,客户端请求LDAP服务器时,采用了不支持的身份验证方法";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.STRONG_AUTH_REQUIRED){//
msg = "客户端请求了需要强认证的操作,如删除操作";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.LDAP_PARTIAL_RESULTS){//
msg = "LDAP部分结果";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.REFERRAL){//
msg = "REFERRAL";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.ADMIN_LIMIT_EXCEEDED){//
msg = "已超出由管理权限设置的LDAP服务器限制";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.UNAVAILABLE_CRITICAL_EXTENSION){//
msg = "服务器不支持该控件或该控件不适合该操作类型";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.CONFIDENTIALITY_REQUIRED){//
msg = "会话不受诸如传输层安全性(TLS)之类的提供会话机密性的协议的保护";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.SASL_BIND_IN_PROGRESS){//
msg = "需要SASL绑定";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.NO_SUCH_ATTRIBUTE){//
msg = "指定的属性在条目中不存在";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.UNDEFINED_ATTRIBUTE_TYPE){//
msg = "指定的属性在LDAP服务器的模式中不存在";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.INAPPROPRIATE_MATCHING){//
msg = "搜索过滤器中指定的匹配规则与为该属性的语法定义的规则不匹配";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.CONSTRAINT_VIOLATION){//
msg = "指定的属性值违反了放置在属性上的约束。约束可以是大小或内容之一(例如,仅字符串,不是二进制数据)";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.ATTRIBUTE_OR_VALUE_EXISTS){//
msg = "指定的属性值已经作为该属性的值存在";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.INVALID_ATTRIBUTE_SYNTAX){//
msg = "无效的属性语法";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.NO_SUCH_OBJECT){//
msg = "无法找到目标对象";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.ALIAS_PROBLEM){//
msg = "取消别名时发生错误";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.INVALID_DN_SYNTAX){//
msg = "DN的语法不正确";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.ALIAS_DEREFERENCING_PROBLEM){//
msg = "无权读取别名对象的名称,或者不允许取消引用";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.INAPPROPRIATE_AUTHENTICATION){//
msg = "无法正确使用的身份验证方法";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.INVALID_CREDENTIALS){//
msg = "无效的凭证,请检查用户和密码是否正确";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.INSUFFICIENT_ACCESS_RIGHTS){//
msg = "访问权限不够";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.BUSY){//
msg = "无法处理客户端请求,但重新提交请求,服务器可能会处理该请求";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.UNAVAILABLE){//
msg = "正在关闭中,无法处理绑定请求";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.UNWILLING_TO_PERFORM){//
msg = "请求违反了服务器的结构规则,定义的限制,无法处理该请求";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.LOOP_DETECT){//
msg = "发现别名或引用循环,因此无法完成此请求";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.NAMING_VIOLATION){//
msg = "违反了模式的结构规则";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.OBJECT_CLASS_VIOLATION){//
msg = "违反条目的对象类规则";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.NOT_ALLOWED_ON_NONLEAF){//
msg = "不允许在非叶结点执行此操作";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.NOT_ALLOWED_ON_RDN){//
msg = "不允许对RDN执行此操作";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.ENTRY_ALREADY_EXISTS){//
msg = "条目已存在";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.OBJECT_CLASS_MODS_PROHIBITED){//
msg = "禁止更改对象类的结构规则";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.OTHER){//
msg = "未知的错误情况";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.LOCAL_ERROR){//
msg = "本地错误";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.ENCODING_ERROR){//
msg = "编码错误";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.DECODING_ERROR){//
msg = "解码错误";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.LDAP_TIMEOUT){//
msg = "等待结果时超出LDAP客户端的时间限制";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.AUTH_UNKNOWN){//
msg = "未知的身份验证方法调用绑定方法";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.FILTER_ERROR){//
msg = "使用无效的搜索过滤器调用搜索方法";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.USER_CANCELLED){//
msg = "用户取消了LDAP操作";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.NO_MEMORY){//
msg = "调用LDAP方法时动态内存分配方法失败";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.CONNECT_ERROR){//
msg = "连接失败,请检查配置信息是否正确以及服务是否开启";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.LDAP_NOT_SUPPORTED){//
msg = "请求的功能不支持";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.CONTROL_NOT_FOUND){//
msg = "控制未发现";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.NO_RESULTS_RETURNED){//
msg = "没有返回结果";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.MORE_RESULTS_TO_RETURN){//
msg = "更多的结果返回";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.CLIENT_LOOP){//
msg = "客户端循环";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.REFERRAL_LIMIT_EXCEEDED){//
msg = "超过限制";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.INVALID_RESPONSE){//
msg = "无效的响应";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.AMBIGUOUS_RESPONSE){//
msg = "请求的响应不明确";
}else if(e.getResultCode() == com.novell.ldap.LDAPException.TLS_NOT_SUPPORTED){//
msg = "不支持TLS";
} else {
msg = "操作失败,错误代码:"+e.getResultCode()+" "+e.getMessage();
} } }

action类

package com.cn.ccc.ggg.ldap.web.action.clientManager;

import com.cn.ccc.ggg.ldap.LDAPConstants;
import com.cn.ccc.ggg.ldap.bean.entryInfo.PersonEntry;
import com.cn.ccc.ggg.ldap.common.ISysLog;
import com.cn.ccc.ggg.ldap.exception.LDAPException;
import com.cn.ccc.ggg.ldap.model.LDAPConectionInfo;
import com.cn.ccc.ggg.ldap.model.ManagerLog;
import com.cn.ccc.ggg.ldap.service.LDAPConectionInfoService;
import com.cn.ccc.ggg.ldap.util.GGGLDAPUtils;
import com.cn.ccc.ggg.ldap.util.LDAPContextUtils;
import com.cn.ccc.ggg.ldap.web.action.BasePageAction;
import com.opensymphony.xwork2.Preparable;
import net.sf.json.JSONArray;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired; import java.io.*;
import java.util.List;
import java.util.Map; /**
* 对目录服务数据进行相应操作
*/
@Namespace("/ldapData")
public class LDAPDataOperaAction extends BasePageAction implements Preparable,ISysLog { @Autowired
private LDAPConectionInfoService ldapConectionInfoService; public LDAPConectionInfo ldapConectionInfo; private PersonEntry personEntry = new PersonEntry(); private String searchDN; private long totalRecord; private String jsonByMap; //操作成功或失败标识 0:成功,1:失败 private InputStream inputStream;// 输入字节流 private String downName;//下载文件名称 private File ldifFile;// ldif 文件 private ManagerLog log = new ManagerLog(); public void prepare() throws Exception {
log.setOptObj(LDAPContextUtils.getClassMap().get(this.getClass().getSimpleName()));
} public void setLog(ManagerLog log) {
this.log = log;
} public ManagerLog getLog() {
return log;
} public File getLdifFile() {
return ldifFile;
} public void setLdifFile(File ldifFile) {
this.ldifFile = ldifFile;
} public String getDownName() {
return downName;
} public void setDownName(String downName) {
this.downName = downName;
} public InputStream getInputStream() {
return inputStream;
} public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
} public PersonEntry getPersonEntry() {
return personEntry;
} public void setPersonEntry(PersonEntry personEntry) {
this.personEntry = personEntry;
} public String getStatus() {
return jsonByMap;
} public void setStatus(String jsonByMap) {
this.jsonByMap = jsonByMap;
} public long getTotalRecord() {
return totalRecord;
} public void setTotalRecord(long totalRecord) {
this.totalRecord = totalRecord;
} public String getSearchDN() {
return searchDN;
} public void setSearchDN(String searchDN) {
this.searchDN = searchDN;
} public LDAPConectionInfo getLdapConectionInfo() {
return ldapConectionInfo;
} public void setLdapConectionInfo(LDAPConectionInfo ldapConectionInfo) {
this.ldapConectionInfo = ldapConectionInfo;
} /**
* @description:到数据列表界面
* @param: []
* @return: java.lang.String
* @exception:
* @author: dq
* @date: 14:10 2018/1/26
*/
@Action(value = "dataList", results = {@Result(name = "success", location = "/WEB-INF/pages/clientManager/dataList.jsp")})
public String dataList() throws LDAPException {
ldapConectionInfo = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
return SUCCESS;
} /**
* @description:到新增节点界面
* @param: []
* @return: java.lang.String
* @exception:
* @author: dq
* @date: 14:09 2018/1/26
*/
@Action(value = "addDN", results = {@Result(name = "success", location = "/WEB-INF/pages/clientManager/addDN.jsp")})
public String addDN() throws LDAPException, UnsupportedEncodingException {
ldapConectionInfo = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
searchDN = new String(ServletActionContext.getRequest().getParameter("searchDN").getBytes("iso-8859-1"),"UTF-8");
//System.out.println(searchDN+ServletActionContext.getRequest().getParameter("searchDN"));
return SUCCESS;
} /**
* @description:到修改属性值界面
* @param: []
* @return: java.lang.String
* @exception:
* @author: dq
* @date: 14:09 2018/1/26
*/
@Action(value = "toModifyAttrs", results = {@Result(name = "success", location = "/WEB-INF/pages/clientManager/modifyAttrs.jsp")})
public String toModifyAttrs() throws LDAPException {
ldapConectionInfo = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
searchDN = ServletActionContext.getRequest().getParameter("baseDN");
return SUCCESS;
} /**
* @description:初始化树形结构,获取根节点
* @param: []
* @return: void
* @exception:
* @author: dq
* @date: 14:08 2018/1/26
*/
@Action(value = "initBaseDN")
public void initBaseDN() throws LDAPException {
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
List<Map<String, Object>> search = ldapConectionInfoService.search(info, info.getBaseDN(), "(objectclass=*)", 0, 1);
String json = LDAPConectionInfoService.getJsonByListMap(search);
GGGLDAPUtils.sendMsgHttp(json.toString());
} /**
* @description:搜索指定节点下的子节点,不包括属性和属性值
* @param: []
* @return: void
* @exception:
* @author: dq
* @date: 14:06 2018/1/26
*/
@Action(value = "search")
public void search() throws LDAPException {
searchDN = ServletActionContext.getRequest().getParameter("baseDN");
String currentPageNo = ServletActionContext.getRequest().getParameter("pageNo");
Integer page = Integer.valueOf(currentPageNo);
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
List<Map<String, Object>> search = ldapConectionInfoService.search(info, searchDN, "(objectclass=*)", 1, page);
String json = LDAPConectionInfoService.getJsonByListMap(search);
GGGLDAPUtils.sendMsgHttp(json.toString());
} /**
* @description:获取指定节点的属性和属性值
* @param: []
* @return: void
* @exception:
* @author: dq
* @date: 14:03 2018/1/26
*/
@Action(value = "attAndVal")
public void attAndVal() throws LDAPException {
searchDN = ServletActionContext.getRequest().getParameter("baseDN");
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
List<Map<String, Object>> search = ldapConectionInfoService.attAndValue(info, searchDN, "(objectclass=*)");
String json = LDAPConectionInfoService.getJsonByListMap(search);
GGGLDAPUtils.sendMsgHttp(json.toString());
} /**
* @description:删除节点,包括子节点
* @param: []
* @return: void
* @exception:
* @author: dq
* @date: 14:03 2018/1/26
*/
@Action(value = "deleteDN")
public void deleteDN() throws LDAPException {
searchDN = ServletActionContext.getRequest().getParameter("baseDN");
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
Map<String, Object> delete = ldapConectionInfoService.delete(info, 0, searchDN);
Object status1 = delete.get("status");
int status = Integer.parseInt(status1.toString());
if(status == 0){
StringBuffer inf = new StringBuffer("");
inf.append("删除的DN:'").append(searchDN).append("'; ");
inf.append("服务别名:'").append(info.getServerName()).append("'; ");
inf.append("IP地址:'").append(info.getIp()).append("'; ");
inf.append("端口:'").append(info.getPort()).append("'; ");
inf.append("数据库:'").append(info.getBaseDN()).append("'; ");
log.setOptEvent("删除LDAP数据");
log.setOperation(info.toString());
log.setOptType("waring");
}
String json = LDAPConectionInfoService.getJsonByMap(delete); GGGLDAPUtils.sendMsgHttp(json.toString());
} /**
* @description:添加节点
* @param: []
* @return: void
* @exception:
* @author: dq
* @date: 14:02 2018/1/26
*/
@Action(value = "addDNInfo")
public void addDNInfo() throws LDAPException, UnsupportedEncodingException {
//System.out.println("dddddd"+searchDN);
//searchDN = new String(ServletActionContext.getRequest().getParameter("searchDN").getBytes("iso-8859-1"),"UTF-8");
System.out.println(searchDN);
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
Map<String, Object> stringObjectMap = ldapConectionInfoService.addEntry(info, personEntry, searchDN);
jsonByMap = LDAPConectionInfoService.getJsonByMap(stringObjectMap);
Object status1 = stringObjectMap.get("status");
int status = Integer.parseInt(status1.toString());
if(status == 0){
StringBuffer inf = new StringBuffer("");
inf.append("添加的父条目:'").append(searchDN).append("'; ");
inf.append("服务别名:'").append(info.getServerName()).append("'; ");
inf.append("IP地址:'").append(info.getIp()).append("'; ");
inf.append("端口:'").append(info.getPort()).append("'; ");
inf.append("数据库:'").append(info.getBaseDN()).append("'; ");
log.setOptEvent("新增LDAP数据");
log.setOperation(info.toString());
log.setOptType("waring");
} GGGLDAPUtils.sendMsgHttp(jsonByMap.toString());
} /**
* @description:搜索指定节点的属性和属性值
* @param: []
* @return: void
* @exception:
* @author: dq
* @date: 13:57 2018/1/26
*/
@Action(value = "searchAttrs")
public void searchAttrs() throws LDAPException {
searchDN = ServletActionContext.getRequest().getParameter("baseDN");
System.out.println(searchDN);
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
List<Map<String, Object>> maps = ldapConectionInfoService.attAndValue(info, searchDN, "(objectclass=*)");
jsonByMap = LDAPConectionInfoService.getJsonByListMap(maps);
System.out.println(jsonByMap.toString());
GGGLDAPUtils.sendMsgHttp(jsonByMap.toString());
} /**
* @description:修改指定节点的属性值
* @param: []
* @return: void
* @exception:
* @author: dq
* @date: 13:57 2018/1/26
*/
@Action(value = "modifyAttrs")
public void modifyAttrs() throws LDAPException {
searchDN = ServletActionContext.getRequest().getParameter("baseDN");
System.out.println(searchDN);
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
String json = ServletActionContext.getRequest().getParameter("newAttrVal");
JSONArray jsonArray = JSONArray.fromObject(json);
List<Map<String,Object>> mapListJson = (List)jsonArray;
Map<String, Object> objectMap = ldapConectionInfoService.modifyAttrs(info, searchDN, mapListJson);
String jsonByMap = LDAPConectionInfoService.getJsonByMap(objectMap);
Object status1 = objectMap.get("status");
int status = Integer.parseInt(status1.toString());
if(status == 0){
StringBuffer inf = new StringBuffer("");
inf.append("修改的条目:'").append(searchDN).append("'; ");
inf.append("服务别名:'").append(info.getServerName()).append("'; ");
inf.append("IP地址:'").append(info.getIp()).append("'; ");
inf.append("端口:'").append(info.getPort()).append("'; ");
inf.append("数据库:'").append(info.getBaseDN()).append("'; ");
log.setOptEvent("修改LDAP数据属性值");
log.setOperation(info.toString());
log.setOptType("waring");
} GGGLDAPUtils.sendMsgHttp(jsonByMap.toString());
} /**
* @description:重命名节点名称
* @param: []
* @return: void
* @exception:
* @author: dq
* @date: 13:55 2018/1/26
*/
@Action(value = "renameDN")
public void renameDN() throws LDAPException {
String oldDN = ServletActionContext.getRequest().getParameter("oldDN");
System.out.println(oldDN);
String newDN = ServletActionContext.getRequest().getParameter("newDN");
System.out.println(newDN);
String parentDN = ServletActionContext.getRequest().getParameter("parentDN");
System.out.println(parentDN);
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
Map<String, Object> stringObjectMap = ldapConectionInfoService.renameRDN(info, oldDN, newDN, parentDN);
String jsonByMap = LDAPConectionInfoService.getJsonByMap(stringObjectMap);
Object status = stringObjectMap.get("status");
int d = Integer.parseInt(status.toString());
if(d == 0){
StringBuffer inf = new StringBuffer("");
inf.append("重命名条目:'").append(oldDN).append("'; ");
inf.append("服务别名:'").append(info.getServerName()).append("'; ");
inf.append("IP地址:'").append(info.getIp()).append("'; ");
inf.append("端口:'").append(info.getPort()).append("'; ");
inf.append("数据库:'").append(info.getBaseDN()).append("'; ");
log.setOptEvent("重命名LDAP条目");
log.setOperation(info.toString());
log.setOptType("waring");
} GGGLDAPUtils.sendMsgHttp(jsonByMap.toString()); } /**
* @description:导出LDIF文件,默认文件名为ldapdb.ldif,下载路径为berkeleydb环境路径下
* @param: []
* @return: java.lang.String
* @exception:
* @author: dq
* @date: 13:52 2018/1/26
*/
@Action(value = "exportLDIF", results = { @Result(name = "success", type = "stream", params = {
"contentType", "application/octet-stream", "inputName",
"inputStream", "contentDisposition", "attachment;filename=${downName}","bufferSize", "1024" }) })
public String exporterLDIF() throws LDAPException, FileNotFoundException {
String bindirpath = GGGLDAPUtils.getLdapWorkPath()+ LDAPConstants.BERKELEYDB_ENVPATH;
String ldiffilepath = bindirpath + "/"+downName;
searchDN = ServletActionContext.getRequest().getParameter("baseDN");
System.out.println(searchDN);
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
ldapConectionInfoService.exportLDIF(info,searchDN,ldiffilepath);
inputStream = new FileInputStream(ldiffilepath);
return SUCCESS;
} /**
* @description:到LDIF导入界面
* @param: []
* @return: java.lang.String
* @exception:
* @author: dq
* @date: 17:40 2018/1/26
*/
@Action(value = "toImportLDIF", results = {@Result(name = "success", location = "/WEB-INF/pages/clientManager/importLDIF.jsp")})
public String toImportLDIF() throws LDAPException {
ldapConectionInfo = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
searchDN = ServletActionContext.getRequest().getParameter("baseDN");
System.out.println(searchDN);
return SUCCESS;
} /**
* @description:根据节点导入ldif文件
* @param: []
* @return: void
* @exception: `
* @author: dq
* @date: 17:42 2018/1/26
*/
@Action(value = "importLDIF")
public void importLDIF() throws LDAPException, UnsupportedEncodingException {
searchDN = new String(ServletActionContext.getRequest().getParameter("baseDN").getBytes("iso-8859-1"),"UTF-8");
System.out.println(searchDN);
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
Map<String, Object> stringIntegerMap = ldapConectionInfoService.importLDIF(info, ldifFile);
String jsonByMap = LDAPConectionInfoService.getJsonByMap(stringIntegerMap);
System.out.println(jsonByMap);
GGGLDAPUtils.sendMsgHttp(jsonByMap.toString()); } @Action(value = "numberOfEntries")
public void numberOfEntries() throws LDAPException {
System.out.println(searchDN);
LDAPConectionInfo info = ldapConectionInfoService.findUniqueBy("id", ldapConectionInfo.getId());
Map<String, Object> numberOfEntries = ldapConectionInfoService.getNumberOfEntries(info, searchDN);
String jsonByMap = LDAPConectionInfoService.getJsonByMap(numberOfEntries);
GGGLDAPUtils.sendMsgHttp(jsonByMap.toString()); } }

使用JLDAP操作LDAP,包含匿名连接、ldif导入导出、获取根节点、对数据的操作、LDAP错误码解析等的更多相关文章

  1. ASP.NET 之 常用类、方法的超级总结,并包含动态的EXCEL导入导出功能,奉上类库源码

    实用类:UtilityClass 包含如下方法 判断对象是否为空或NULL,如果是空或NULL返回true,否则返回false 验证手机号是否正确 13,15,18 验证邮箱 验证网址 MD5加密,返 ...

  2. ASPxTreeList控件去根节点的新增修改操作(写在onCommandColumnButtonInitialize()事件中)

    treelist去掉根节点按钮效果图: //去掉父节点及子节点旁的新增.修改.删除操作(写在onCommandColumnButtonInitialize事件中) protected void Tre ...

  3. Hive中导入Amazon S3中的分区表数据的操作

    Hive中创建S3的外部表 数据在S3存放的数据是按时间纬度存放的,每天的数据存放在各自的目录下,目录结构如下截图: 每个目录下面的数据是CSV文件,现在将其导入到Hive中进行查询,通过创建对应的表 ...

  4. LDAP禁止匿名访问

    LDAP默认是允许用户匿名访问的,如下图:在使用工具连接时,勾选匿名绑定后,不需要输入UserDN和密码就可能连接到LDAP服务器,但是只能进行read及search操作.不能做任何的修改及删除操作. ...

  5. ldap禁止匿名用户登录

    此处默认ldap已经安装完成,安装文档传送门:https://www.cnblogs.com/crysmile/p/9470508.html openldap默认安装完成,是允许匿名用户登录的,因此需 ...

  6. Java操作Sqlite数据库-jdbc连接

    Java操作Sqlite数据库步骤: 1. 导入Sqlite jdbc 本文使用sqlite-jdbc-3.7.2.jar,下载地址 http://pan.baidu.com/s/1kVHAGdD 2 ...

  7. 廖雪峰js教程笔记11 操作DOM(包含作业)

    由于HTML文档被浏览器解析后就是一棵DOM树,要改变HTML的结构,就需要通过JavaScript来操作DOM. 始终记住DOM是一个树形结构.操作一个DOM节点实际上就是这么几个操作: 更新:更新 ...

  8. 数据库连接工具类——包含取得连接和关闭资源 ConnUtil.java

    package com.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Prepare ...

  9. 【centOS】【xshell】xshell连接虚拟机上的centOS,操作途中突然断开连接,报错:connect closed by foreign host

    如题  xshell连接虚拟机上的centOS,操作途中突然断开连接,报错:connect closed by foreign host 快捷解决方法: 在虚拟机上centOS重新启动网络,即可解决问 ...

随机推荐

  1. 从零构建vue项目(一)--搭建node环境,拉取项目模板

    本文是基于vuecli2搭建的项目. 1. 下载安装nodejs     地址:https://nodejs.org/en/download/ 选择安装版windows .msi, 不要选择压缩版 下 ...

  2. C语言第十二周作业

        这个作业属于那个课程 C语言程序设计II 这个作业要求在哪 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/h ...

  3. Labview 错误1400-打包库封装类时将对类重命名导致

    现象 今天遇到了一个神奇的BUG,主程序调用了一个包含类的打包库,打包库中将字符串还原为类句柄时报错. 调用程序结构如下:. 主程序中将类句柄转化为XML字符串程序如下: 打包库内将字符串还原为句柄程 ...

  4. python爬取b站排行榜

    爬取b站排行榜并存到mysql中 目的 b站是我平时看得最多的一个网站,最近接到了一个爬虫的课设.首先要选择一个网站,并对其进行爬取,最后将该网站的数据存储并使其可视化. 网站的结构 目标网站:bil ...

  5. mysql简单命令

    库: 增 create database db1:新建一个默认编码的库 create database db1 charset uet8 ;建一个编码为 utf8 的库 删 drop database ...

  6. [LeetCode] 113. 路径总和 II

    题目链接 : https://leetcode-cn.com/problems/path-sum-ii/ 题目描述: 给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径 ...

  7. Python 流程控制 超全解析(不可错过)

    流程控制 程序执行结构流程 计算机程序在解决某个具体问题时,包括三种情形,即顺序执行所有的语句.选择执行部分的语句和循环执行部分语句,这正好对应着程序设计中的三种程序执行结构流程:顺序结构.选择结构和 ...

  8. GeoAdapter实现WMS、WMTS、ArcGIS MapService的区域权限授权管理

    背景: 在实际GIS应用中,我们经常会发布GIS地图服务,然后供WebGIS调用.在某些特殊情况下,需要对服务进行区域授权,特定的用户只能够浏览特定范围内的地图数据.通常情况下大家采用的实现方式是使用 ...

  9. python multiprocessing模块

    python multiprocessing模块 原文地址 multiprocessing multiprocessing支持子进程.通信和共享数据.执行不同形式的同步,提供了Process.Queu ...

  10. C 调试 gdb常用命令

    gdb常用命令: [root@redhat home]#gdb 调试文件:启动gdb (gdb) l :(字母l)从第一行开始列出源码 (gdb) break n :在第n行处设置断点 (gdb) b ...