Examples of LDAPAttribute


Examples of com.novell.ldap.LDAPAttribute

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

   * that corresponds to a DN <code>field</code>.
   */
  private LDAPAttribute getObjectClassAttribute(String field) {
    final String lowCaseField = field.toLowerCase();
    if(lowCaseField.equals("o")) {
      return new LDAPAttribute("objectclass", new String[] { "top", "organization" });
    } else if(lowCaseField.equals("ou")) {
      return new LDAPAttribute("objectclass", new String[] { "top", "organizationalUnit" });
    } else {
      String msg = intres.getLocalizedMessage("publisher.ldapintermediatenotappropriate", field);
      log.warn(msg);
      return new LDAPAttribute("objectclass");
    }
  }
View Full Code Here

Examples of com.novell.ldap.LDAPAttribute

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

Examples of com.novell.ldap.LDAPAttribute

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

Examples of com.novell.ldap.LDAPAttribute

  protected Collection<LDAPAttribute> getAttributesFromDN(String dn, String[] attributes) {
    Collection<LDAPAttribute> attributeList= new LinkedList<LDAPAttribute>();
    for (int i =0; i<attributes.length;i++){
      String attribute = CertTools.getPartFromDN(dn, attributes[i]);
      if (attribute != null) {
        attributeList.add(new LDAPAttribute(attributes[i], attribute));
      }
    }
    return attributeList;
  }
View Full Code Here

Examples of com.novell.ldap.LDAPAttribute

    ArrayList<LDAPModification> modset = new ArrayList<LDAPModification>();
    boolean modifyExisting = getModifyExistingAttributes();
    boolean addNonExisting = getAddNonExistingAttributes();
    for (int i =0; i<attributes.length;i++){
      String attribute = CertTools.getPartFromDN(dn, attributes[i]);
      LDAPAttribute oldattribute = oldEntry.getAttribute(attributes[i]);
      if (log.isDebugEnabled()) {
        if (oldattribute!=null) {
          log.debug("removeme, oldattribute="+oldattribute.toString());
        }
        if (dn!=null) {
          log.debug("removeme, dn="+dn);
        }
      }
      if ( ((attribute != null) && (oldattribute == null) && addNonExisting) || ( ((attribute != null) && (oldattribute != null )) && modifyExisting) ) {
        LDAPAttribute attr = new LDAPAttribute(attributes[i], attribute);
        modset.add(new LDAPModification(LDAPModification.REPLACE, attr));
      }
    }
    return modset;
  }
View Full Code Here

Examples of com.novell.ldap.LDAPAttribute

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

                sn = new String(cn.substring(index+1));
              }
            }
          }
        }
        LDAPAttribute oldsn = oldEntry.getAttribute("sn");
        if (((sn != null) && (oldsn == null) && addNonExisting) || ( (sn != null) && (oldsn != null ) && modifyExisting)) {
          LDAPAttribute attr = new LDAPAttribute("sn", sn);
          modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
        }
        // gn means givenname in LDAP, and is required for inetOrgPerson
        String gn = CertTools.getPartFromDN(dn, "GIVENNAME");
        LDAPAttribute oldgn = oldEntry.getAttribute("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) && (oldgn == null)) && addNonExisting) || ( ((gn != null) && (oldgn != null )) && modifyExisting) ) {
            LDAPAttribute attr = new LDAPAttribute("givenName", gn);
            modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
          }
        }
        String title = CertTools.getPartFromDN(dn, "T");
        LDAPAttribute oldTitle = oldEntry.getAttribute("Title");
        if ( ( (title != null) && (oldTitle == null) && addNonExisting) || ( (title != null) && (oldTitle != null ) && modifyExisting) ) {
          LDAPAttribute attr = new LDAPAttribute("givenName", title);
          modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
        }
        LDAPAttribute oldEmail = oldEntry.getAttribute("mail");
        if ( ( (email != null) && (oldEmail == null) && addNonExisting) || ( (email != null) && (oldEmail != null ) && modifyExisting) ) {
          LDAPAttribute mailAttr = new LDAPAttribute("mail", email);
          modSet.add(new LDAPModification(LDAPModification.REPLACE, mailAttr));                     
        }

        // All generic personal attributes
        modSet.addAll(getModificationSetFromDN(dn, oldEntry, MATCHINGPERSONALATTRIBUTES));
        // 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)
        Collection<Integer> usefields = getUseFieldInLdapDN();
        if (usefields.contains(Integer.valueOf(DNFieldExtractor.SN))) {
          String serno = CertTools.getPartFromDN(dn, "SN");
          LDAPAttribute oldserno = oldEntry.getAttribute("SN");
          if (((serno != null) && (oldserno == null) && addNonExisting) || ( (serno != null) && (oldserno != null ) && modifyExisting)) {
            LDAPAttribute attr = new LDAPAttribute("serialNumber", serno);
            modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
          }               
        }
       
        // 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)) && (addNonExisting || modifyExisting) ) {
          if (log.isDebugEnabled()) {
            log.debug("Modifying userPassword attribute");
          }
          LDAPAttribute attr = new LDAPAttribute("userPassword", password);
          modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
        }
      }
    }
    if (log.isTraceEnabled()) {
View Full Code Here

Examples of com.novell.ldap.LDAPAttribute

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

                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());
                    }
                }
            }
            return user;
        } catch (LDAPException e) {
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.