⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldapprocess.java

📁 这个是自由下载的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    return certValue;

  }

  public PKI_DATA[] WHLDAP_GetSOAFromLDAP(String certsn)
  {
          String ldapIp = conf.getParamValue("LDAPServerIP");
          String searchBase = conf.getParamValue("LDAPSOASearchBase");
          String ldapPort = conf.getParamValue("LDAPServerPort");

          WHLDAP_SVR_CONNCET_PARA para = new WHLDAP_SVR_CONNCET_PARA();
          para.m_dwSearchScop = LDAPConnection.SCOPE_ONE;
          para.m_ldapsvr_host = ldapIp;
          para.m_ldapsvr_port = new Integer(ldapPort).intValue();
          para.m_searchBase ="soaprivvalue="+searchBase;
          WHLDAP_SetSvrPara(para);
          WHLDAP_FILTER filter = new WHLDAP_FILTER();
          filter.pbData= "(objectclass=pvcertsn)";
          WHLDAP_SetFilter(filter,1);
          WHLDAP_Connect(1,2,null,null);
          
          PKI_DATA[] certValue = WHLDAP_GetAllData("spvcertificate","pvcertsn",1,2,0);
		  //System.out.println("certValue.length="+certValue.length);	
		  
          WHLDAP_DisConnect(1);
          return certValue;
  }


  public byte[] WHLDAP_GetAATFromLDAP(String certsn)
  {
          String ldapIp = conf.getParamValue("LDAPServerIP");
          String searchBase = conf.getParamValue("LDAPAATSearchBase");
          String ldapPort = conf.getParamValue("LDAPServerPort");

          WHLDAP_SVR_CONNCET_PARA para = new WHLDAP_SVR_CONNCET_PARA();
          para.m_dwSearchScop = LDAPConnection.SCOPE_ONE;
          para.m_ldapsvr_host = ldapIp;
          para.m_ldapsvr_port = new Integer(ldapPort).intValue();
          para.m_searchBase ="aatemplate="+searchBase;
          WHLDAP_SetSvrPara(para);
          WHLDAP_FILTER filter = new WHLDAP_FILTER();
          filter.pbData= "(objectclass=tempcertsn)";
          WHLDAP_SetFilter(filter,1);
          WHLDAP_Connect(1,2,null,null);

          byte[] certValue = WHLDAP_GetData("aatcertificate","tempcertsn",1,2,0);
          WHLDAP_DisConnect(1);
          return certValue;
  }

  public PKI_DATA[] WHLDAP_GetAACertFromLDAPByUserID(String userid)
  {
        String ldapIp = conf.getParamValue("LDAPServerIP");
        String searchBase = conf.getParamValue("LDAPAASearchBase");
        String ldapPort = conf.getParamValue("LDAPServerPort");
        try
        {
                //建立连接
                LDAPConnection conn = new LDAPConnection();
                conn.connect(ldapIp,new Integer(ldapPort).intValue());
                //System.out.println("conn success");
                
                //用户名密码,匿名
                byte[] pwd=null;
                  conn.bind(LDAPConnection.LDAP_V3,null ,pwd);//"cn=root,aaac=GBAA","wellhope"


                String searchDN ="usercertid="+userid +",aaac="+searchBase;
                //System.out.println("searchDN="+searchDN);
                
//                LDAPSearchConstraints er=new LDAPSearchConstraints();
//                er.setMaxResults(20000);

                //查询用户
                LDAPSearchResults rs = conn.search(searchDN,
                                         LDAPConnection.SCOPE_SUB,//查询causerDN以下的对象
                                         "(objectClass=certsn)",//只查询casert对象                                         
                                         null,
                                         false
 //                                        ,er                                         er
                                         );
               int i=0;
               //取节点个数
               while (rs.hasMore()) {
                 rs.next();
                 i++;
               }
               //System.out.println("节点个数="+i);

               rs = conn.search(searchDN,
                                        LDAPConnection.SCOPE_SUB,//查询causerDN以下的对象
                                        "(objectClass=certsn)",//只查询casert对象                                        
                                        null,
                                        false
//                                        ,er                                        er
                                        );

               PKI_DATA[] buf = new PKI_DATA[i];
               for(int j=0;j<i;j++)
               {
                        //得到证书的二进制流
                        LDAPEntry certentry = rs.next();
                        buf[j] = new PKI_DATA();
                        byte[] buf1 =(certentry.getAttribute("accertificate").getByteValueArray())[0];                        
                        buf[j].setValue(buf1);
                        buf[j].setSize(buf1.length);
                }
                conn.disconnect();
               return buf;
        }
        catch (Exception ex)
        {

                System.out.println(ex);
                return null;
        }

  }

  public int getCertNum(String timeString)
  {
          if((timeString.length()!=14) && (timeString.length()!=29))
          {
                  System.out.println("Time Invalid");
                  return 0;
          }

        String ldapIp = conf.getParamValue("LDAPServerIP");
        String searchBase = conf.getParamValue("LDAPAASearchBase");
        String ldapPort = conf.getParamValue("LDAPServerPort");

        try
          {
                //建立连接
                LDAPConnection conn = new LDAPConnection();
                conn.connect(ldapIp,new Integer(ldapPort).intValue());
                
                //用户名密码,匿名
                byte[] pwd=null;
                conn.bind(LDAPConnection.LDAP_V3, null,pwd);

                String time1;
                String time2;
                      String searchDN = "aaac="+searchBase;
                      LDAPSearchResults rs,rs1;

                      rs1 = conn.search(searchDN,
                                                 LDAPConnection.SCOPE_ONE,//查询causerDN以下的对象                                                 
                                                 "(objectclass=usersn)",//只查询causer对象                                                 
                                                 null,
                                                 false
                                                 );

                int i=0;
                      while (rs1.hasMore())
                      {                	
                              LDAPEntry userentry = rs1.next();
                              String userid = new String((userentry.getAttribute("usercertid").getByteValueArray())[0]);
                              String userDN = "usercertid="+userid+",aaac="+searchBase;

                              if(timeString.length()==14)
                              {
                                      time1 = timeString.substring(0,14);
                                      rs = conn.search(userDN,
                                                         LDAPConnection.SCOPE_ONE,//查询causerDN以下的对象
                                                         "(modifytimestamp>="+time1+"Z)(objectclass=certsn)",//只查询causer对象
                                                         null,
                                                         false
                                                         );
                              }
                              else
                              {
                                      time1 = timeString.substring(0,14);
                                      time2 = timeString.substring(15,29);
                                      rs = conn.search(userDN,
                                                         LDAPConnection.SCOPE_ONE,//查询causerDN以下的对象
                                                         "(modifytimestamp>="+time1+"Z)(modifytimestamp<="+time2+"Z)(objectclass=certsn)",//只查询causer对象
                                                         null,
                                                         false
                                                         );
                              }

                      //取节点个数
                       while (rs.hasMore()) {
                         rs.next();
                         i++;
                       }					  
                 }
                       conn.disconnect();
                       return i;
            }
    catch (Exception ex)
    {
        System.out.println(ex);
        return 0;
    }

  }

  public PKI_DATA[] WHLDAP_GetAACertFromLDAPByTime(String timeString)
  {
          if((timeString.length()!=14) && (timeString.length()!=29))
          {
                  System.out.println("Time Invalid");
                  return null;
          }

        String ldapIp = conf.getParamValue("LDAPServerIP");
        String searchBase = conf.getParamValue("LDAPAASearchBase");
        String ldapPort = conf.getParamValue("LDAPServerPort");

        try
          {
                //建立连接
                LDAPConnection conn = new LDAPConnection();
                conn.connect(ldapIp,new Integer(ldapPort).intValue());
               
                //用户名密码,匿名
                byte[] pwd=null;
                conn.bind(LDAPConnection.LDAP_V3, null,pwd);

                String time1;
                String time2;                      
                      String searchDN = "aaac="+searchBase;
                      LDAPSearchResults rs,rs1;

                      rs1 = conn.search(searchDN,
                                                 LDAPConnection.SCOPE_ONE,//查询causerDN以下的对象
                                                 "(objectclass=usersn)",//只查询causer对象                                                 
                                                 null,
                                                 false
                                                 );


                PKI_DATA[] buf = new PKI_DATA[getCertNum(timeString)];
                //System.out.println("初始化证书个数="+buf.length);
             
                      while (rs1.hasMore())
                      {                      	      
                              LDAPEntry userentry = rs1.next();
                              String userid = new String((userentry.getAttribute("usercertid").getByteValueArray())[0]);
                              String userDN = "usercertid="+userid+",aaac="+searchBase;
                              if(timeString.length()==14)
                              {
                                      time1 = timeString.substring(0,14);
                                      rs = conn.search(userDN,
                                                         LDAPConnection.SCOPE_ONE,//查询causerDN以下的对象
                                                         "(modifytimestamp>="+time1+"Z)(objectclass=certsn)",//只查询causer对象
                                                         null,
                                                         false
                                                         );
                              }
                              else
                              {
                                      time1 = timeString.substring(0,14);
                                      time2 = timeString.substring(15,29);
                                      rs = conn.search(userDN,
                                                         LDAPConnection.SCOPE_ONE,//查询causerDN以下的对象
                                                         "(modifytimestamp>="+time1+"Z)(modifytimestamp<="+time2+"Z)(objectclass=certsn)",//只查询causer对象
                                                         //"(modifytimestamp>="+time1+")(modifytimestamp<="+time2+")(objectclass=certsn)",//只查询causer对象
                                                         null,
                                                         false
                                                         );
                                      //System.out.println("Search "+time1+"==="+time2+" Success!");                   

                              }
						  int i =0;	
                          while (rs.hasMore())
                          {				
                                LDAPEntry certentry = rs.next();
								//System.out.print("i="+i);	
                                buf[i] = new PKI_DATA();
                                byte[] buf1 =(certentry.getAttribute("accertificate").getByteValueArray())[0];
                                buf[i].setValue(buf1);
                                buf[i].setSize(buf1.length);		                
                                i++;

                          }
                          //System.out.print("LDAP search count="+i);
                 }
                       conn.disconnect();
                       return buf;
            }
    catch (Exception ex)
    {
        System.out.println(ex);
        return null;
    }

  }

  public static void main(String[] args) {
   //   LDAPProcess ldaptest = new LDAPProcess();
  //    byte[] Data4 = ldaptest.WHLDAP_GetCertByCertID("100020002003122310100000023624") ;
  //    System.out.println(Data4.length);

  //  byte[] Data5 = ldaptest.WHLDAP_GetCertByCertID("100020002003122311100000023625") ;
  //  System.out.println(Data5.length);

  //  byte[] Data6 = ldaptest.WHLDAP_GetCRLFromLDAP();
  //  System.out.println(Data6.length);

  //  byte[] Data7 = ldaptest.WHLDAP_GetPaCertFromLdap("国办");
  //  System.out.println(Data7.length);

//     PKI_DATA[] Data8=ldaptest.WHLDAP_GetAACertFromLDAPByTime("20031113064115-20031230064115");
  //   System.out.println(Data8.length);

  //   PKI_DATA[] Data9 = ldaptest.WHLDAP_GetAACertFromLDAPByUserID("122334568798099090809004444440f1");
  //   System.out.println(Data9.length);

  //    byte[] Data10 = ldaptest.WHLDAP_GetAATFromLDAP(null);
  //    System.out.println(Data10.length);

  //    byte[] Data11 = ldaptest.WHLDAP_GetSOAFromLDAP(null);
  //    System.out.println(Data11.length);
 }

 public byte[] WHLDAP_GetPaCertFromLdap(String dn_ou)
  {
          String ldapIp =conf.getParamValue("PALDAPServerIP");
          String searchBase =conf.getParamValue("PALDAPSearchBase");
          int ldapPort=Integer.valueOf(conf.getParamValue("PALDAPServerPort")).intValue();

          WHLDAP_SVR_CONNCET_PARA para = new WHLDAP_SVR_CONNCET_PARA();
          para.m_dwSearchScop = LDAPConnection.SCOPE_ONE;
          para.m_ldapsvr_host = ldapIp;
          para.m_ldapsvr_port = ldapPort;
          para.m_searchBase ="pasn="+searchBase;
          WHLDAP_SetSvrPara(para);

          WHLDAP_FILTER filter = new WHLDAP_FILTER();
          filter.pbData= "(pausername="+dn_ou+")(objectclass=pauser)";
          WHLDAP_SetFilter(filter,1);

          WHLDAP_Connect(1,2,null,null);

          byte[] certValue = WHLDAP_GetData("usercertificate","pauser",1,1,0);

          WHLDAP_DisConnect(1);
          return certValue;
  }
}

class WHLDAP_SVR_CONNCET_PARA
{
   String m_ldapsvr_host;
   int    m_ldapsvr_port;
   int    m_ldagsvr_sslport;
   String m_searchBase;
   int    m_dwSearchScop;
}

class WHLDAP_FILTER
{
    String pbData;
    int    dwSize;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -