Package com.novell.ldap

Examples of com.novell.ldap.LDAPAttributeSet


    LDAPSearchResults searchResults = connection.search(searchRootGroup, LDAPConnection.SCOPE_SUB,
      "(objectclass=" + objectClassGroup + ")", attrIDsGroup, false);

    LDAPEntry entry = null;
    LDAPAttributeSet attributeSet = null;
    while (searchResults.hasMore()) {

        try {
      entry = searchResults.next();
      if (entry != null) {
          attributeSet = entry.getAttributeSet();
          groups.add(attributeSet.getAttribute(ouAttributeName).getStringValue());

      }
        } catch (LDAPException e) {
      logger.error("LDAPException",e);
      throw e;
View Full Code Here


      conn.connect(LDAP_HOST, LDAP_PORT);
      // conn.authenticate("cn=Manager,dc=example,dc=com", "secret");
      conn.bind(ldapVersion, ROOT_DN, ROOT_PASSWORD.getBytes("utf-8"));

      System.out.println("========> create ldap entry " + EXO_DEVELOPER_DN);
      LDAPAttributeSet attributeSet = new LDAPAttributeSet();
      attributeSet.add(new LDAPAttribute("objectClass", "person"));
      attributeSet.add(new LDAPAttribute("cn", "exo"));
      attributeSet.add(new LDAPAttribute("sn", "platform"));
      attributeSet.add(new LDAPAttribute("telephonenumber", "0989654990"));
      LDAPEntry newEntry = new LDAPEntry(EXO_DEVELOPER_DN, attributeSet);
      conn.add(newEntry);
      System.out.println("<======Added object: " + EXO_DEVELOPER_DN + " successfully.");

      System.out.println("\nAdded object: " + EXO_DEVELOPER_DN + " successfully.");

      LDAPSearchResults results = conn.search(DEVELOPER_UNIT_DN, // search only
         // the object in
         // the subtree of
         // this dn
         LDAPConnection.SCOPE_SUB, // return
         // all the
         // objects
         // that
         // match
         // the
         // filter
         // criteria
         // and in
         // the sub
         // tree
         "(objectclass=person)", // query
         // filter, (
         // objectclass
         // =*) for
         // all the
         // object
         null, // return all the attributes
         // of the object
         false); // return attrs and values

      // assertEquals("Expect to find 1 entry", 1, results.getCount()) ;
      while (results.hasMore())
      {
         LDAPEntry nextEntry = null;
         nextEntry = results.next();
         System.out.println("\n entry: " + nextEntry.getDN());
         System.out.println("  Attributes: ");
         LDAPAttributeSet attrs = nextEntry.getAttributeSet();
         printLDAPAttributeSet(attrs);
      }
      System.out.println("   ---> count: " + results.getCount());
      System.out.println("<======search " + DEVELOPER_UNIT_DN + " successfully.");
      // delete the new created ldap entry
View Full Code Here

      conn.connect(LDAP_HOST, LDAP_PORT);
      // conn.authenticate("cn=Manager,dc=example,dc=com", "secret");
      conn.bind(ldapVersion, ROOT_DN, ROOT_PASSWORD.getBytes("utf-8"));

      System.out.println("========> create ldap entry " + EXO_DEVELOPER_DN);
      LDAPAttributeSet attributeSet = new LDAPAttributeSet();
      attributeSet.add(new LDAPAttribute("objectClass", "person"));
      attributeSet.add(new LDAPAttribute("cn", "exo"));
      attributeSet.add(new LDAPAttribute("sn", "platform"));
      attributeSet.add(new LDAPAttribute("telephonenumber", "0989654990"));
      LDAPEntry newEntry = new LDAPEntry(EXO_DEVELOPER_DN, attributeSet);
      conn.add(newEntry);
      System.out.println("<======Added object: " + EXO_DEVELOPER_DN + " successfully.");

      System.out.println("\nAdded object: " + EXO_DEVELOPER_DN + " successfully.");

      LDAPSearchResults results = conn.search(DEVELOPER_UNIT_DN, // search only
         // the object in
         // the subtree of
         // this dn
         LDAPConnection.SCOPE_SUB, // return
         // all the
         // objects
         // that
         // match
         // the
         // filter
         // criteria
         // and in
         // the sub
         // tree
         "(objectclass=person)", // query
         // filter, (
         // objectclass
         // =*) for
         // all the
         // object
         null, // return all the attributes
         // of the object
         false); // return attrs and values

      // assertEquals("Expect to find 1 entry", 1, results.getCount()) ;
      while (results.hasMore())
      {
         LDAPEntry nextEntry = null;
         nextEntry = results.next();
         System.out.println("\n entry: " + nextEntry.getDN());
         System.out.println("  Attributes: ");
         LDAPAttributeSet attrs = nextEntry.getAttributeSet();
         printLDAPAttributeSet(attrs);
      }
      System.out.println("   ---> count: " + results.getCount());
      System.out.println("<======search " + DEVELOPER_UNIT_DN + " successfully.");
      // delete the new created ldap entry
View Full Code Here

  // 根据sn取得邮箱地址
  public static String getLDAPEmailBySN(String user) {
    String mail = null;
    LDAPEntry fullEntry = null;
    LDAPConnection lc = null;
    LDAPAttributeSet set = null;
    LDAPSearchResults rs = null;

    try {
      lc = getConnection();

      rs = lc.search(ENTRYDN, LDAPConnection.SCOPE_SUB, "sn=" + user,
          attrNames, false);

      while (rs.hasMore()) {
        try {
          fullEntry = rs.next();
          set = fullEntry.getAttributeSet();
          Iterator<?> attrs = set.iterator();
          while (attrs.hasNext()) {
            LDAPAttribute attribute = (LDAPAttribute) attrs.next();
            String name = attribute.getName();
            String value = attribute.getStringValue();
            if (name != null && "mail".equals(name.trim())) {
View Full Code Here

  // 根据cn取得邮箱地址
  public static String getLDAPEmailByCN(String user) {
    String mail = null;
    LDAPEntry fullEntry = null;
    LDAPConnection lc = null;
    LDAPAttributeSet set = null;
    LDAPSearchResults rs = null;

    try {
      lc = getConnection();
      rs = lc.search(ENTRYDN, LDAPConnection.SCOPE_SUB, "cn=" + user,
          attrNames, false);

      while (rs.hasMore()) {
        try {
          fullEntry = rs.next();
          set = fullEntry.getAttributeSet();
          Iterator<?> attrs = set.iterator();
          while (attrs.hasNext()) {
            LDAPAttribute attribute = (LDAPAttribute) attrs.next();
            String name = attribute.getName();
            String value = attribute.getStringValue();
            if (name != null && "mail".equals(name.trim())) {
View Full Code Here

  // 根据中文姓名(cn)取得sn
  public static String getLDAPSNByCN(String cn) {
    String sn = null;
    LDAPEntry fullEntry = null;
    LDAPConnection lc = null;
    LDAPAttributeSet set = null;
    LDAPSearchResults rs = null;
    try {
      lc = getConnection();
      rs = lc.search(ENTRYDN, LDAPConnection.SCOPE_SUB, "cn=" + cn,
          attrNames, false);

      while (rs.hasMore()) {
        try {
          fullEntry = rs.next();
          set = fullEntry.getAttributeSet();
          Iterator<?> attrs = set.iterator();
          while (attrs.hasNext()) {
            LDAPAttribute attribute = (LDAPAttribute) attrs.next();
            String name = attribute.getName();
            String value = attribute.getStringValue();
            if (name != null && "sn".equals(name.trim())) {
View Full Code Here

  // 根据sn取得cn
  public static String getLDAPCNBySN(String sn) {
    String cn = null;
    LDAPEntry fullEntry = null;
    LDAPConnection lc = null;
    LDAPAttributeSet set = null;
    LDAPSearchResults rs = null;

    try {
      lc = getConnection();
      rs = lc.search(ENTRYDN, LDAPConnection.SCOPE_SUB, "sn=" + sn,
          attrNames, false);

      while (rs.hasMore()) {
        try {
          fullEntry = rs.next();
          set = fullEntry.getAttributeSet();
          Iterator<?> attrs = set.iterator();
          while (attrs.hasNext()) {
            LDAPAttribute attribute = (LDAPAttribute) attrs.next();
            String name = attribute.getName();
            String value = attribute.getStringValue();
            if (name != null && "cn".equals(name.trim())) {
View Full Code Here

  // 根据用户名取得邮箱地址
  private String getEmail(String user) {
    String mail = null;
    LDAPEntry fullEntry = null;
    LDAPConnection lc = null;
    LDAPAttributeSet set = null;
    LDAPSearchResults rs = null;
    final String MY_HOST = "localhost";
    final int MY_PORT = 389;
    final String ENTRYDN = "o=zephyr.com.cn";
    final String[] attrNames = { "sn", "mobile", "mail" };

    try {
      lc = new LDAPConnection();
      lc.connect(MY_HOST, MY_PORT);
      String password = "secret";
      try {
        lc.bind(3, "cn=Manager,o=zephyr.com.cn", password
            .getBytes("UTF8"));
      } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
      }
      rs = lc.search(ENTRYDN, LDAPConnection.SCOPE_SUB, "sn=" + user,
          attrNames, false);

      while (rs.hasMore()) {
        try {
          fullEntry = rs.next();
          set = fullEntry.getAttributeSet();
          Iterator<?> attrs = set.iterator();
          while (attrs.hasNext()) {
            LDAPAttribute attribute = (LDAPAttribute) attrs.next();
            String name = attribute.getName();
            String value = attribute.getStringValue();
            if ("mail".equals(name)) {
View Full Code Here

TOP

Related Classes of com.novell.ldap.LDAPAttributeSet

Copyright © 2018 www.massapicom. 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.