Examples of LDAPAttributeSet


Examples of com.novell.ldap.LDAPAttributeSet

        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) {
View Full Code Here

Examples of com.novell.ldap.LDAPAttributeSet

   * @param lc Active LDAP connection
   * @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()) {
View Full Code Here

Examples of com.novell.ldap.LDAPAttributeSet

    // 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);
    }
View Full Code Here

Examples of com.novell.ldap.LDAPAttributeSet

  protected LDAPAttributeSet getAttributeSet(Certificate cert, String objectclass, String dn, String email, boolean extra, boolean person,
      String password, ExtendedInformation extendedinformation) {
    if (log.isTraceEnabled()) {
      log.trace(">getAttributeSet(dn="+dn+", email="+email+")");     
    }
    LDAPAttributeSet attributeSet = new LDAPAttributeSet();
    LDAPAttribute attr = new LDAPAttribute("objectclass");
    // The full LDAP object tree is divided with ; in the objectclass
    StringTokenizer token = new StringTokenizer(objectclass,";");
    while (token.hasMoreTokens()) {
      String value = token.nextToken();
      if (log.isDebugEnabled()) {
        log.debug("Adding objectclass value: "+value);
      }
      attr.addValue(value);
    }
    attributeSet.add(attr);

    /* To Add an entry to the directory,
     *   -- Create the attributes of the entry and add them to an attribute set
     *   -- Specify the DN of the entry to be created
     *   -- Create an LDAPEntry object with the DN and the attribute set
     *   -- Call the LDAPConnection add method to add it to the directory
     */
    if (extra) {
      attributeSet.addAll(getAttributesFromDN(dn, MATCHINGEXTRAATTRIBUTES));

      // Only persons have (normally) all these extra attributes.
      // A CA might have them if you don't use the default objectClass, but we don't
      // handle that case.
      if (person) {
        // First get the easy ones where LDAP and EJBCA spelling is the same
        attributeSet.addAll(getAttributesFromDN(dn, MATCHINGPERSONALATTRIBUTES));
        // sn means surname in LDAP, and is required for persons
        String cn = CertTools.getPartFromDN(dn, "CN");
        String sn = CertTools.getPartFromDN(dn, "SURNAME");
        if ( (sn == null) && (cn != null) ) {
          // Only construct this if we are the standard object class
          if (getUserObjectClass().endsWith("inetOrgPerson")) {
            // Take surname to be the last part of the cn
            int index = cn.lastIndexOf(' ');
            if (index <=0) {
              // If there is no natural sn, use cn since sn is required
              sn = cn;
            } else {
              if (index < cn.length()) {
                sn = new String(cn.substring(index+1));
              }
            }
          }
        }
        if (sn != null) {
          attributeSet.add(new LDAPAttribute("sn", sn));
        }
        // gn means givenname in LDAP, and is required for persons
        String gn = CertTools.getPartFromDN(dn, "GIVENNAME");
        if ( (gn == null) && (cn != null) ) {
          // Only construct this if we are the standard object class
          if (getUserObjectClass().endsWith("inetOrgPerson")) {
            // Take givenname to be the first part of the cn
            int index = cn.indexOf(' ');
            if (index <=0) {
              // If there is no natural gn/sn, ignore gn if we are using sn
              if (sn == null) {
                gn = cn;
              }
            } else {
              gn = new String(cn.substring(0, index));
            }
          }
        }
        if (gn != null) {
          attributeSet.add(new LDAPAttribute("givenName", gn));
        }
        String title = CertTools.getPartFromDN(dn, "T");
        if (title != null) {
          attributeSet.add(new LDAPAttribute("title", title));
        }
        if (email != null) {
          attributeSet.add(new LDAPAttribute("mail", email));                     
        }
       
        // If we have selected to use the SN (serialNUmber DN field, we will also add it as an attribute
        // This is not present in the normal objectClass (inetOrgPerson)
        // Modifying the schema is as simple as adding serialNumber as MAY in the inetOrgPerson object class in inetorgperson.schema.
        Collection<Integer> usefields = getUseFieldInLdapDN();
        if (usefields.contains(Integer.valueOf(DNFieldExtractor.SN))) {
          String serno = CertTools.getPartFromDN(dn, "SN");
          if (serno != null) {
            attributeSet.add(new LDAPAttribute("serialNumber", serno));
          }               
        }
       
        // If this is an objectClass which is a SecurityObject, such as simpleSecurityObject, we will add the password as well, if not null.
        if (getSetUserPassword() && (password != null)) {
          if (log.isDebugEnabled()) {
            log.debug("Adding userPassword attribute");
          }
          attributeSet.add(new LDAPAttribute("userPassword", password));
        }
       
      }
    }
    if (log.isTraceEnabled()) {
View Full Code Here

Examples of com.novell.ldap.LDAPAttributeSet

     */
    protected LDAPAttributeSet getAttributeSet(Certificate cert, String objectclass, String dn, String email, boolean extra, boolean person,
                                           String password, ExtendedInformation extendedinformation) {
      log.debug("ADPublisher : getAttributeSet");
     
        LDAPAttributeSet attributeSet = super.getAttributeSet(cert, objectclass, dn, email, extra, person, password, extendedinformation);
       
        String cn = CertTools.getPartFromDN(dn, "CN");
        // Add AD specific attributes
        //attributeSet.add(new LDAPAttribute("userAccountControl", Integer.toString(getUserAccountControl())));
       
        if(cert!= null && cert instanceof X509Certificate){
          String upn = null;
    try {
      upn = CertTools.getUPNAltName((X509Certificate) cert);
    } catch (CertificateParsingException e) {}
      catch (IOException e) {}
    String samaccountname = upn;
    if(upn != null && upn.indexOf('@') != -1){
      // only use name part of UPN.
      samaccountname = samaccountname.substring(0, upn.indexOf('@'))
    }
   
   
          switch(getSAMAccountName()){
          case DNFieldExtractor.CN:
              samaccountname = cn;  
              break;
            case DNFieldExtractor.UID: 
              samaccountname = CertTools.getPartFromDN(dn, "UID");  
              break;         
          }
          if(samaccountname !=null){
            attributeSet.add(new LDAPAttribute("samaccountname", samaccountname));
          }
         
          if(upn != null) {
            attributeSet.add(new LDAPAttribute("userPrincipalName", upn));   
          } else {
            attributeSet.add(new LDAPAttribute("userPrincipalName", cn));
          }
        }
        attributeSet.add(new LDAPAttribute("displayName", cn));
        if(getUserDescription() != null && !getUserDescription().trim().equals("")){
          attributeSet.add(new LDAPAttribute("description", getUserDescription()));
        }

        if(getUseSSL()  && password != null){
          //Can only set password through SSL connection
         
          //attributeSet.add(new LDAPAttribute("userPassword", password)); 
         

          //Start out by taking the password and enclosing it in quotes, as in
            String newVal = new String("\"" + password + "\"");

          //Then, you need to get the octet string of the Unicode representation of
          //that.  You need to leave off the extra two bytes Java uses as length:
           
            byte _bytes[] = null;
      try {
        _bytes = newVal.getBytes("Unicode");
      } catch (UnsupportedEncodingException e) {}
      byte bytes[] = new byte[_bytes.length - 2];
            System.arraycopy(_bytes, 2, bytes, 0, _bytes.length - 2);

          //Take that value and stuff it into the unicodePwd attribute:         
            attributeSet.add(new LDAPAttribute("unicodePwd", bytes));                  
         
       
       
       
        return attributeSet;
View Full Code Here

Examples of com.novell.ldap.LDAPAttributeSet

                        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.LDAPAttributeSet

    }

    public static void addUserToLDAP(SysUser user) throws EasyJException {
        LDAPConnection connection = new LDAPConnection();
        try {
            LDAPAttributeSet attributeSet = new LDAPAttributeSet();

            attributeSet.add(new LDAPAttribute("objectclass", new String[] {
                "pilotPerson", "uidObject"
            }));
            attributeSet.add(new LDAPAttribute("uid", user.getUserName()));
            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");
View Full Code Here

Examples of com.novell.ldap.LDAPAttributeSet

              "(&(objectclass=person)(cn=biadmin))",
              attrIDs,false);
         
          // popolamento userAttributes con attributeName e attributeValue
          LDAPEntry entry = null;
          LDAPAttributeSet attributeSet = null;
          if (searchResults.hasMore()) {
                try {
                    entry = searchResults.next();
                }catch(LDAPException e) {
                  e.printStackTrace();
View Full Code Here

Examples of com.novell.ldap.LDAPAttributeSet

              "(&(objectclass=person)(cn=biadmin))",
              attrIDs,false);
         
          // popolamento userAttributes con attributeName e attributeValue
          LDAPEntry entry = null;
          LDAPAttributeSet attributeSet = null;
          if (searchResults.hasMore()) {
                try {
                    entry = searchResults.next();
                }catch(LDAPException e) {
                  e.printStackTrace();
View Full Code Here

Examples of com.novell.ldap.LDAPAttributeSet

              "(objectclass=organizationalUnit)",
              attrIDs,false);
         
          // popolamento userAttributes con attributeName e attributeValue
          LDAPEntry entry = null;
          LDAPAttributeSet attributeSet = null;
          while (searchResults.hasMore()){

                try {
                    entry = searchResults.next();
                    if (entry != null) {
                attributeSet = entry.getAttributeSet();
              groups.add(attributeSet.getAttribute("ou").getStringValue());
                    }
                }catch(LDAPException e) {
                  e.printStackTrace();
                    System.out.println("errore in UserContext:: getUserAttributes: " + e.getMessage());
                }           
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.