Examples of LDAPEntry


Examples of com.novell.ldap.LDAPEntry

        // Check if the entry is already present, we will update it with the new certificate.
        // To work well with the LdapSearchPublisher we need to pass the full certificate DN to the
        // search function, and not only the LDAP DN. The regular publisher should only use the LDAP DN though,
        // but the searchOldEntity function will take care of that.
        LDAPEntry oldEntry = searchOldEntity(username, ldapVersion, lc, certdn, userDN, email);

        // PART 2: Create LDAP entry
        LDAPEntry newEntry = null;
        ArrayList<LDAPModification> modSet = new ArrayList<LDAPModification>();
        LDAPAttributeSet attributeSet = null;
        String attribute = null;
        String objectclass = null;

        if (type == SecConst.CERTTYPE_ENDENTITY) {
          if (log.isDebugEnabled()) {
            log.debug("Publishing end user certificate to first available server of " + getHostnames());
          }
          if (oldEntry != null) {
            modSet = getModificationSet(oldEntry, certdn, email, ADD_MODIFICATION_ATTRIBUTES, true, password);
          } else {
            objectclass = getUserObjectClass(); // just used for logging
            attributeSet = getAttributeSet(incert, getUserObjectClass(), certdn, email, true, true, password, extendedinformation);
          }

          try {
            attribute = getUserCertAttribute();
            LDAPAttribute certAttr = new LDAPAttribute(getUserCertAttribute(), incert.getEncoded());
            if (oldEntry != null) {
              String oldDn = oldEntry.getDN();
              if (getAddMultipleCertificates()) {
                modSet.add(new LDAPModification(LDAPModification.ADD, certAttr));                       
                if (log.isDebugEnabled()) {
                  log.debug("Appended new certificate in user entry; " + username+": "+oldDn);
                }
              } else {
                modSet.add(new LDAPModification(LDAPModification.REPLACE, certAttr));                                           
                if (log.isDebugEnabled()) {
                  log.debug("Replaced certificate in user entry; " + username+": "+oldDn);
                }
              }
            } else {
              attributeSet.add(certAttr);
              if (log.isDebugEnabled()) {
                log.debug("Added new certificate to user entry; " + username+": "+dn);
              }
            }
          } catch (CertificateEncodingException e) {
            String msg = intres.getLocalizedMessage("publisher.errorldapencodestore", "certificate");
            log.error(msg, e);
            throw new PublisherException(msg);               
          }
        } else if ((type == SecConst.CERTTYPE_SUBCA) || (type == SecConst.CERTTYPE_ROOTCA)) {
          if (log.isDebugEnabled()) {
            log.debug("Publishing CA certificate to first available server of " + getHostnames());
          }
          if (oldEntry != null) {
            modSet = getModificationSet(oldEntry, certdn, null, false, false, password);
          } else {
            objectclass = getCAObjectClass(); // just used for logging
            attributeSet = getAttributeSet(incert, getCAObjectClass(), certdn, null, true, false, password, extendedinformation);
          }
          try {
            attribute = getCACertAttribute();
            LDAPAttribute certAttr = new LDAPAttribute(getCACertAttribute(), incert.getEncoded());
            if (oldEntry != null) {
              modSet.add(new LDAPModification(LDAPModification.REPLACE, certAttr));
            } else {
              attributeSet.add(certAttr);
              // Also create using the crlattribute, it may be required
              LDAPAttribute crlAttr = new LDAPAttribute(getCRLAttribute(), getFakeCRL());
              attributeSet.add(crlAttr);
              // Also create using the arlattribute, it may be required
              LDAPAttribute arlAttr = new LDAPAttribute(getARLAttribute(), getFakeCRL());
              attributeSet.add(arlAttr);
              if (log.isDebugEnabled()) {
                log.debug("Added (fake) attribute for CRL and ARL.");
              }
            }
          } catch (CertificateEncodingException e) {
            String msg = intres.getLocalizedMessage("publisher.errorldapencodestore", "certificate");
            log.error(msg, e);
            throw new PublisherException(msg);           
          }
        } else {
          String msg = intres.getLocalizedMessage("publisher.notpubltype", Integer.valueOf(type));
          log.info(msg);
          throw new PublisherException(msg);                     
        }

        // PART 3: MODIFICATION AND ADDITION OF NEW USERS
        // Try all the listed servers
        Iterator servers = getHostnameList().iterator();
        boolean connectionFailed;
        do {
          connectionFailed = false;
          String currentServer = (String) servers.next();
          try {
            TCPTool.probeConnectionLDAP(currentServer, Integer.parseInt(getPort()), getConnectionTimeOut())// Avoid waiting for halfdead-servers
            lc.connect(currentServer, Integer.parseInt(getPort()));
            // authenticate to the server
            lc.bind(ldapVersion, getLoginDN(), getLoginPassword().getBytes("UTF8"), ldapBindConstraints);           
            // Add or modify the entry
            if (oldEntry != null && getModifyExistingUsers()) {
              LDAPModification[] mods = new LDAPModification[modSet.size()];
              mods = (LDAPModification[])modSet.toArray(mods);
              String oldDn = oldEntry.getDN();
              if (log.isDebugEnabled()) {
                log.debug("Writing modification to DN: "+oldDn);
              }
              lc.modify(oldDn, mods, ldapStoreConstraints);
              String msg = intres.getLocalizedMessage("publisher.ldapmodify", "CERT", oldDn);
              log.info(msg)
            } else {
              if(this.getCreateNonExistingUsers()){    
                if (oldEntry == null) {          
                  // Check if the intermediate parent node is present, and if it is not
                  // we can create it, of allowed to do so by the publisher configuration
                  if(getCreateIntermediateNodes()) {
                    final String parentDN = new String(dn.substring(dn.indexOf(',') + 1));
                    try {
                      lc.read(parentDN, ldapSearchConstraints);
                    } catch(LDAPException e) {
                      if(e.getResultCode() == LDAPException.NO_SUCH_OBJECT) {
                        this.createIntermediateNodes(lc, dn);
                        String msg = intres.getLocalizedMessage("publisher.ldapaddedintermediate", "CERT", parentDN);
                        log.info(msg);
                      }
                    }
                  }
                  newEntry = new LDAPEntry(dn, attributeSet);
                  if (log.isDebugEnabled()) {
                    log.debug("Adding DN: "+dn);
                  }
                  lc.add(newEntry, ldapStoreConstraints);
                  String msg = intres.getLocalizedMessage("publisher.ldapadd", "CERT", dn);
View Full Code Here

Examples of com.novell.ldap.LDAPEntry

   * @param dn Distinguished name
   * @throws PublisherException
   */
  private void createIntermediateNodes(LDAPConnection lc, String dn) throws PublisherException {
    LDAPAttributeSet attrSet;
    LDAPEntry entry;
    String dnFragment, rdn, field, value;
    int ix = dn.lastIndexOf(getBaseDN()) - 1;

    while((ix = dn.lastIndexOf(',', ix - 1)) >= 0) {
      dnFragment = new String(dn.substring(ix + 1));
      rdn = new String(dnFragment.substring(0, dnFragment.indexOf(',')));
      field = new String(rdn.substring(0, rdn.indexOf('=')));
      value = new String(rdn.substring(rdn.indexOf('=') + 1));
      try {
        lc.read(dnFragment, ldapSearchConstraints);
      } catch(LDAPException e) {
        if(e.getResultCode() == LDAPException.NO_SUCH_OBJECT) {
          attrSet = new LDAPAttributeSet();
          attrSet.add(getObjectClassAttribute(field));
          attrSet.add(new LDAPAttribute(field.toLowerCase(), value));
          entry = new LDAPEntry(dnFragment, attrSet);

          try {
            lc.add(entry, ldapStoreConstraints);
            if (log.isDebugEnabled()) {
              log.debug("Created node " + dnFragment);
View Full Code Here

Examples of com.novell.ldap.LDAPEntry

    }

    LDAPConnection lc = createLdapConnection();

    // Check if the entry is already present, we will update it with the new CRL.
    LDAPEntry oldEntry = searchOldEntity(null, ldapVersion, lc, crldn, userDN, null);

    LDAPEntry newEntry = null;
    ArrayList modSet = new ArrayList();
    LDAPAttributeSet attributeSet = null;

    if (oldEntry != null) {
      modSet = getModificationSet(oldEntry, crldn, null, false, false, null);
    } else {
      attributeSet = getAttributeSet(null, this.getCAObjectClass(), crldn, null, true, false, null,null);
    }

    if(isDeltaCRL) {
      // It's a delta CRL.
      LDAPAttribute attr = new LDAPAttribute(getDeltaCRLAttribute(), incrl);
      if (oldEntry != null) {
        modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
      } else {
        attributeSet.add(attr);
      }
    } else {
      // It's a CRL
      LDAPAttribute crlAttr = new LDAPAttribute(getCRLAttribute(), incrl);
      LDAPAttribute arlAttr = new LDAPAttribute(getARLAttribute(), incrl);
      if (oldEntry != null) {
        modSet.add(new LDAPModification(LDAPModification.REPLACE, crlAttr));
        modSet.add(new LDAPModification(LDAPModification.REPLACE, arlAttr));
      } else {
        attributeSet.add(crlAttr);
        attributeSet.add(arlAttr);
      }
    }
    if (oldEntry == null) {
      newEntry = new LDAPEntry(dn, attributeSet);
    }
    // Try all the listed servers
    Iterator servers = getHostnameList().iterator();
    boolean connectionFailed;
    do {
View Full Code Here

Examples of com.novell.ldap.LDAPEntry

    // Extract the users email from the cert.
    String email = CertTools.getEMailAddress(cert);

    // Check if the entry is already present, we will update it with the new certificate.
    LDAPEntry oldEntry = searchOldEntity(username, ldapVersion, lc, certdn, userDN, email);

    ArrayList modSet = null;

    if (!CertTools.isCA(cert)) {
      if (log.isDebugEnabled()) {
        log.debug("Removing end user certificate from first available server of " + getHostnames());
      }
      if (oldEntry != null) {         
        if (removecert) {
          // Don't try to remove the cert if there does not exist any
          LDAPAttribute oldAttr = oldEntry.getAttribute(getUserCertAttribute());
          if (oldAttr != null) {
            modSet = getModificationSet(oldEntry, certdn, null, false, true, null);
            LDAPAttribute attr = new LDAPAttribute(getUserCertAttribute());
            modSet.add(new LDAPModification(LDAPModification.DELETE, attr));                   
          } else {
            String msg = intres.getLocalizedMessage("publisher.inforevokenocert");
            log.info(msg);
          }               
        }
      } else {
        String msg = intres.getLocalizedMessage("publisher.errorrevokenoentry");
        log.error(msg);           
        throw new PublisherException(msg);           
      }
    } else  {
      // Removal of CA certificate isn't support because of object class restrictions
      if (log.isDebugEnabled()) {
        log.debug("Not removing CA certificate from first available server of " + getHostnames() + ", because of object class restrictions.");
      }
    }

    // Try all the listed servers
    Iterator servers = getHostnameList().iterator();
    boolean connectionFailed;
    do {
      connectionFailed = false;
      String currentServer =(String) servers.next();
      if (log.isDebugEnabled()) {
        log.debug("currentServer: "+currentServer);
      }
      try {
        TCPTool.probeConnectionLDAP(currentServer, Integer.parseInt(getPort()), getConnectionTimeOut())// Avoid waiting for halfdead-servers
        lc.connect(currentServer, Integer.parseInt(getPort()));
        // authenticate to the server
        lc.bind(ldapVersion, getLoginDN(), getLoginPassword().getBytes("UTF8"), ldapBindConstraints);           
        // Add or modify the entry
        if (oldEntry != null && modSet != null && getModifyExistingUsers()) {
          if (removecert) {
            LDAPModification[] mods = new LDAPModification[modSet.size()];
            mods = (LDAPModification[])modSet.toArray(mods);
            lc.modify(oldEntry.getDN(), mods, ldapStoreConstraints);               
          }
          if (removeuser) {
            lc.delete(oldEntry.getDN(), ldapStoreConstraints);               
          }
          String msg = intres.getLocalizedMessage("publisher.ldapremove", dn);
          log.info(msg)
        } else {
          if (log.isDebugEnabled()) {
View Full Code Here

Examples of com.novell.ldap.LDAPEntry

   *  Apart from how they find existing users, the publishing works the same.
   * 
   *  @param dn the DN from the certificate, can be used to extract search information or a LDAP DN
   */
  protected LDAPEntry searchOldEntity(String username, int ldapVersion, LDAPConnection lc, String certDN, String userDN, String email) throws PublisherException {
    LDAPEntry oldEntry = null; // return value
    // Try all the listed servers
    final Iterator servers = getHostnameList().iterator();
    boolean connectionFailed;
    do {
      connectionFailed = false;
View Full Code Here

Examples of com.novell.ldap.LDAPEntry

    Iterator servers = getHostnameList().iterator();
    boolean connectionFailed;
    do {
      connectionFailed = false;
      String currentServer = (String) servers.next();
      LDAPEntry entry = null;
      try {
        TCPTool.probeConnectionLDAP(currentServer, Integer.parseInt(getPort()), getConnectionTimeOut())// Avoid waiting for halfdead-servers
        // connect to the server
        lc.connect(currentServer, Integer.parseInt(getPort()));
        // authenticate to the server
        lc.bind(ldapVersion, getLoginDN(), getLoginPassword().getBytes("UTF8"), ldapBindConstraints);
        // try to read the base object
        String baseDN = getBaseDN();
        if (log.isDebugEnabled()) {
          log.debug("Trying to read top node '"+baseDN+"'");
        }
        entry = lc.read(baseDN, ldapSearchConstraints);     
        if(entry == null) {
          String msg = intres.getLocalizedMessage("publisher.errornobinddn");
          throw new PublisherConnectionException(msg);
        }
        if (log.isDebugEnabled()) {
          log.debug("Entry" + entry.toString());
        }
      } catch (LDAPException e) {
        connectionFailed = true;
        if (servers.hasNext()) {
          log.warn("Failed to connect to " + currentServer + ". Trying next in list.", e);
View Full Code Here

Examples of com.novell.ldap.LDAPEntry

     *  Apart from how they find existing users, the publishing works the same.
     * 
     *  @param certDN the DN from the certificate, can be used to extract search information or a LDAP DN
     */
    protected LDAPEntry searchOldEntity(final String username, final int ldapVersion, final LDAPConnection lc, final String certDN, final String userDN, final String email) throws PublisherException {
        LDAPEntry oldEntry = null; // return value

    // Try all the listed servers
    Iterator servers = getHostnameList().iterator();
    boolean connectionFailed;
    do {
      connectionFailed = false;
      String currentServer = (String) servers.next();
          // PARTE 1: Search for an existing entry in the LDAP directory
      //  If it exists, s�lo se a�adir� al DN la parte del certificado (PARTE 2)
      //  if not exist, se a�adir� toda una entrada LDAP nueva (PARTE 2)
      try {
        TCPTool.probeConnectionLDAP(currentServer, Integer.parseInt(getPort()), getConnectionTimeOut())// Avoid waiting for halfdead-servers
        // connect to the server
        log.debug("Connecting to " + currentServer);
        lc.connect(currentServer, Integer.parseInt(getPort()));
        // authenticate to the server
        log.debug("Logging in with BIND DN " + getLoginDN());
        lc.bind(ldapVersion, getLoginDN(), getLoginPassword().getBytes("UTF8"), ldapBindConstraints);
        //searchFilter = "(&(objectclass=person)(uid=" + username + "))";
        String searchFilter = getSearchFilter();
        if (log.isDebugEnabled()) {
          log.debug("Compiling search filter: " +searchFilter+", from certDN '"+certDN+"' and userDN '"+userDN+"'.");
        }
        if (username != null) {
          Pattern USER = Pattern.compile("\\$USERNAME", Pattern.CASE_INSENSITIVE);
          searchFilter = USER.matcher(searchFilter).replaceAll(username);
        }
        if (email != null) {
          Pattern EMAIL = Pattern.compile("\\$EMAIL", Pattern.CASE_INSENSITIVE);
          searchFilter = EMAIL.matcher(searchFilter).replaceAll(email);
        }
        if (getPartFromDN(certDN, userDN, "CN") != null) {
          Pattern CN = Pattern.compile("\\$CN", Pattern.CASE_INSENSITIVE);
          searchFilter = CN.matcher(searchFilter).replaceAll(getPartFromDN(certDN, userDN, "CN"));
        }
        if (getPartFromDN(certDN, userDN, "O") != null) {
          Pattern O = Pattern.compile("\\$O", Pattern.CASE_INSENSITIVE);
          searchFilter = O.matcher(searchFilter).replaceAll(getPartFromDN(certDN, userDN, "O"));
        }
        if (getPartFromDN(certDN, userDN, "OU") != null) {
          Pattern OU = Pattern.compile("\\$OU", Pattern.CASE_INSENSITIVE);
          searchFilter = OU.matcher(searchFilter).replaceAll(getPartFromDN(certDN, userDN, "OU"));
        }
        if (getPartFromDN(certDN, userDN, "C") != null) {
          Pattern C = Pattern.compile("\\$C", Pattern.CASE_INSENSITIVE);
          searchFilter = C.matcher(searchFilter).replaceAll(getPartFromDN(certDN, userDN, "C"));
        }
        if (getPartFromDN(certDN, userDN, "UID") != null) {
          Pattern C = Pattern.compile("\\$UID", Pattern.CASE_INSENSITIVE);
          searchFilter = C.matcher(searchFilter).replaceAll(getPartFromDN(certDN, userDN, "UID"));
        }
        log.debug("Resulting search filter '" + searchFilter+"'.");
        log.debug("Making SRCH with BaseDN '" + getSearchBaseDN() + "' and filter '" + searchFilter+"'.");
        String searchbasedn = getSearchBaseDN();
        int searchScope = LDAPConnection.SCOPE_SUB;
            String attrs[] = { LDAPConnection.NO_ATTRS };
        boolean attributeTypesOnly = true;
        LDAPSearchResults searchResults = lc.search(searchbasedn, // container to search
            searchScope, // search scope
            searchFilter, // search filter
            attrs, // "1.1" returns entry name only
            attributeTypesOnly,
            ldapSearchConstraints); // no attribute values are returned
        // try to read the old object
        if (log.isDebugEnabled()) {
          log.debug("serachResults contains entries: "+searchResults.hasMore());
        }
        final String ldapDN;
        if (searchResults.hasMore()) {
          oldEntry = searchResults.next();
          ldapDN = oldEntry.getDN();
          if (searchResults.hasMore()) {
            log.debug("Found more than one matches with filter '" + searchFilter +
                "'. Using the first match with LDAP entry with DN: " +oldEntry.getDN());
          } else {
            log.debug("Found one match with filter: '"+searchFilter+"', match with DN: " + oldEntry.getDN());
          }
        } else {
          ldapDN = constructLDAPDN(certDN, userDN);
          log.debug("No matches found using filter: '" +searchFilter + "'. Using DN: " + ldapDN);
        }
View Full Code Here

Examples of com.novell.ldap.LDAPEntry

                        "easyJ.system.service.LDAPService.getUserFromLDAP(String)",
                        user.getUserName() + "的用户名密码错", "用户名密码错");
            }
            while (rs.hasMore()) {

                LDAPEntry entry = rs.next();
                LDAPAttributeSet attSet = entry.getAttributeSet();
                Iterator it = attSet.iterator();
                while (it.hasNext()) {
                    LDAPAttribute attr = (LDAPAttribute) it.next();
                    if (attr.getName().equalsIgnoreCase("userPassword")) {
                        user.setPassword(attr.getStringValue());
View Full Code Here

Examples of com.novell.ldap.LDAPEntry

            attributeSet.add(new LDAPAttribute("userPassword", user
                    .getPassword()));
            attributeSet.add(new LDAPAttribute("mail", user.getEmail()));
            attributeSet.add(new LDAPAttribute("sn", "snMass"));
            attributeSet.add(new LDAPAttribute("cn", "cnMass"));
            LDAPEntry entry = new LDAPEntry("uid=" + user.getUserName()
                    + ",ou=People,o=SEForge,dc=sei,dc=pku", attributeSet);
            connection.connect(LDAPServerAddress, 389);
            connection.bind(LDAPConnection.LDAP_V3, "cn=admin,dc=sei,dc=pku",
                    "seiseforge");
            connection.add(entry);
View Full Code Here

Examples of netscape.ldap.LDAPEntry

       
      // alle entries lesen
      while (res.hasMoreElements()) {
          try {
              // The next entry
          LDAPEntry entry = res.next();
          entries.add(entry);
           
        }
          catch (LDAPReferralException e) {
              // Ignore any referrals
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.