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

📄 ldapprocess.java.sun.three

📁 这个是自由下载的
💻 THREE
📖 第 1 页 / 共 2 页
字号:
  {
          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());
                //用户名密码
                conn.authenticate(null,null);

                String searchDN ="usercertid="+userid +",aaac="+searchBase;

                //查询用户
                LDAPSearchResults rs = conn.search(searchDN,
                                         LDAPConnection.SCOPE_ONE,//查询causerDN以下的对象
                                         "(objectclass=certsn)",//只查询casert对象
                                         null,
                                         false
                                         );
                int i = 0;
                      //列出用户所有证书
                      PKI_DATA[] buf = new PKI_DATA[rs.getCount()];
                      while (rs.hasMoreElements()) {

                        LDAPEntry certentry = rs.next();
                        //得到证书的二进制流
                        buf[i] = new PKI_DATA();
                        byte[] buf1 =(certentry.getAttribute("accertificate").getByteValueArray())[0];
                        buf[i].setValue(buf1);
                        buf[i].setSize(buf1.length);
                        //将证书写入文件
                        i++;
                }
                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());
                //用户名密码
                conn.authenticate(null,null);

                String time1;
                String time2;
                      //String searchDN = "aaAC="+"GBAA";
                      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.hasMoreElements())
                      {
                              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+")(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+")(modifytimestamp<="+time2+")(objectclass=certsn)",//只查询causer对象
                                                         null,
                                                         false
                                                         );

                              }

                          //列出用户所有证书
                        i += rs.getCount();
                 }
                       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());
                //用户名密码
                conn.authenticate(null,null);

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

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

                int i = 0;
                PKI_DATA[] buf = new PKI_DATA[getCertNum(timeString)];
                      while (rs1.hasMoreElements())
                      {
                              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+")(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+")(modifytimestamp<="+time2+")(objectclass=certsn)",//只查询causer对象
                                                         null,
                                                         false
                                                         );

                              }

                          while (rs.hasMoreElements())
                        {

                                  LDAPEntry certentry = rs.next();

                                buf[i] = new PKI_DATA();
                                byte[] buf1 =(certentry.getAttribute("accertificate").getByteValueArray())[0];
                                buf[i].setValue(buf1);
                                buf[i].setSize(buf1.length);

                                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[] Data = ldaptest.WHLDAP_GetCertByMailAddr(1,"fantq@wellhope.sh");
    byte[] Data1 = ldaptest.WHLDAP_GetCertByMailAddr(2,"zhangxj@wellhope.sh");

    byte[] Data2 = ldaptest.WHLDAP_GetCertByUserid(1 ,"USER0001");
    byte[] Data3 = ldaptest.WHLDAP_GetCertByUserid(2,"USER0001");

    byte[] Data4 = ldaptest.WHLDAP_GetCertByCertID("CERT0001") ;

    byte[] Data5 = ldaptest.WHLDAP_GetCertByCertID("CERT0002") ;

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

    System.out.println(Data1.length);

    System.out.println(Data2.length);
    System.out.println(Data3.length);
    System.out.println(Data4.length);
    System.out.println(Data5.length);
    System.out.println(Data6.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 + -