Package com.novell.ldap

Examples of com.novell.ldap.LDAPConnection


 
  private List getAllGroups() throws Exception {
    List groups = new ArrayList();
     
      LDAPConnection connection = createConnection();
      if (connection != null) {
      try {
        String[] attrIDs = {"description","ou"};
          LDAPSearchResults searchResults = connection.search("ou=Group,dc=spagobi,dc=com",
              LDAPConnection.SCOPE_SUB,
              "(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());
                }           
        }


     }catch (LDAPException e) {
         System.out.println("errore in UserContext:: getUserAttributes: " + e);            
         throw e;
     }finally {
       if (connection != null)
         connection.disconnect();
     }
     
      }
     
      return groups;
View Full Code Here


     * @throws UnsupportedEncodingException
     *                 the unsupported encoding exception
     */
    public boolean autenticateUser(String userId, String psw) throws LDAPException, UnsupportedEncodingException {
  logger.debug("IN");
  LDAPConnection connection = null;
  String compsedUserId = userDn.replace("*", userId);
  try {
      connection = new LDAPConnection();
      connection.connect(host, port);
      if (connection.isConnected()) {
    connection.bind(LDAPConnection.LDAP_V3, compsedUserId, psw.getBytes("UTF8"));
      }
      if (connection.isBound()) {
    logger.debug("OUT");
    return true;
      }
      if (!connection.isConnected() || !connection.isBound()) {
    logger.debug("OUT");
    logger.warn("!connection.isConnected() || !connection.isBound()");
    return false;
      }

View Full Code Here

     */
    public HashMap getUserAttributes(String userId) throws LDAPException, UnsupportedEncodingException {
  logger.debug("IN");
  HashMap userAttributes = new HashMap();

  LDAPConnection connection = createConnection();
  if (connection != null) {
      try {
    LDAPSearchResults searchResults = connection.search(searchRoot, LDAPConnection.SCOPE_SUB,
      "(&(objectclass=" + objectClass + ")(cn=" + userId + "))", attrIDs, false);

    LDAPEntry entry = null;
    if (searchResults.hasMore()) {
        try {
      entry = searchResults.next();
        } catch (LDAPException e) {
      logger.error("LDAPException",e);
        }

        if (entry != null) {
      userAttributes.put("dn", entry.getDN());
      for (int i = 0; i < attrIDs.length; i++) {
          String attr = attrIDs[i];
          userAttributes.put(attr, entry.getAttribute(attr).getStringValue());
      }

        }
    }
      } catch (LDAPException e) {
    logger.error("LDAPException",e);
    throw e;
      } finally {
    if (connection != null)
        connection.disconnect();
      }

  }
  logger.debug("OUT");
  return userAttributes;
View Full Code Here

     */
    public List getUserGroup(String userId) throws LDAPException, UnsupportedEncodingException {
  logger.debug("IN");
  List userAttributes = new ArrayList();

  LDAPConnection connection = createConnection();
  if (connection != null) {
      try {
    String[] attributes = new String[1];
    attributes[0] = ouAttributeName;
    LDAPSearchResults searchResults = connection.search(searchRoot, LDAPConnection.SCOPE_SUB,
      "(&(objectclass=" + objectClass + ")(cn=" + userId + "))", attributes, false);

    // popolamento userAttributes con attributeName e attributeValue
    LDAPEntry entry = null;
    if (searchResults.hasMore()) {
        try {
      entry = searchResults.next();
        } catch (LDAPException e) {
      logger.error("LDAPException",e);
      throw e;
        }
        if (entry != null) {
      String[] ou = entry.getAttribute(ouAttributeName).getStringValueArray();
      for (int i = 0; i < ou.length; i++) {
          if (ou[i].indexOf("=") > 0) {
        String[] appUserOUs = LDAPDN.explodeDN(ou[i], false);
        for (int j = appUserOUs.length - 1; j >= 0; j--) {
            String s = appUserOUs[j];
            if (s.toUpperCase().startsWith("OU") && !userAttributes.contains(s.substring(3))) {
          userAttributes.add(s.substring(3));
            }
        }

          } else {
        userAttributes.add(ou[i]);
          }
      }
        }
    }
      } catch (LDAPException e) {
    logger.error("LDAPException",e);
    throw e;
      } finally {
    if (connection != null)
        connection.disconnect();
      }

  }
  logger.debug("OUT");
  return userAttributes;
View Full Code Here

     */
    public List getAllGroups() throws LDAPException, UnsupportedEncodingException {
  logger.debug("IN");
  List groups = new ArrayList();

  LDAPConnection connection = createConnection();
  if (connection != null) {
      try {

    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;
        }
    }

      } catch (LDAPException e) {
    logger.error("LDAPException",e);
    throw e;
      } finally {
    if (connection != null)
        connection.disconnect();
      }

  }
  logger.debug("OUT");
  return groups;
View Full Code Here

     * @throws UnsupportedEncodingException
     */
    private LDAPConnection createConnection() throws LDAPException, UnsupportedEncodingException {
  logger.debug("IN");
  DefaultCipher defaultCipher = new DefaultCipher();
  LDAPConnection connection = null;

  try {
      connection = new LDAPConnection();
      connection.connect(host, port);
      if (connection.isConnected()) {
    connection.bind(LDAPConnection.LDAP_V3, adminUser, (defaultCipher.decrypt(adminPsw)).getBytes("UTF8"));
      }
      if (connection.isBound()) {
    logger.debug("OUT");
    return connection;
      }
      if (!connection.isConnected() || !connection.isBound()) {
    logger.debug("OUT");
    logger.warn("!connection.isConnected() || !connection.isBound()");
    throw new LDAPException();
      }

View Full Code Here

  private static String username = "bruce.zhang@sky-mobi.com";
  private static String password = "";

  public static void getAllUser(char i) throws LDAPException, UnsupportedEncodingException
  {
    LDAPConnection conn = null;
    LDAPSearchResults rs = null;

    conn = new LDAPConnection();

    conn.connect(ldapserver, ldapport);

    conn.bind(3, username, password.getBytes("UTF-8"));
    System.out.println("--" + conn.getSaslBindProperties());

    String filter = null;
    filter = "(sAMAccountName=" + i + "*)";

    System.out.println("prefix:" + i);

    String[] atrr = (String[])null;
    atrr = new String[] { "DisplayName", "mail", "memberOf",
      "sAMAccountName" };

    rs = conn.search("ou=skymobi,dc=sky-mobi,dc=com", 2, filter, atrr,
      false);

    int icnt = 0;
    if (rs != null) {
      while (rs.hasMore()) {
        LDAPEntry entry = rs.next();
        if (entry.getAttribute("sAMAccountName") != null) {
          System.out.println(icnt++ + "X " +
            entry.getAttribute("sAMAccountName") + " " +
            entry.getAttribute("DisplayName") + " ");
        }
      }
    }

    conn.disconnect();
  }
View Full Code Here

      {
         System.out.println("LDAP Server is not started on host:" + LDAP_HOST + " port:" + LDAP_PORT);
         return;
      }
      int ldapVersion = LDAPConnection.LDAP_V3;
      LDAPConnection conn = new LDAPConnection();
      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
      conn.delete(EXO_DEVELOPER_DN);
      conn.disconnect();
   }
View Full Code Here

      {
         System.out.println("LDAP Server is not started on host:" + LDAP_HOST + " port:" + LDAP_PORT);
         return;
      }
      int ldapVersion = LDAPConnection.LDAP_V3;
      LDAPConnection conn = new LDAPConnection();
      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
      conn.delete(EXO_DEVELOPER_DN);
      conn.disconnect();
   }
View Full Code Here

          + MY_URL.length() + 1);
    String sPort2 = sPort1.substring(0, sPort1.indexOf("/"));
    int MY_PORT = 389;
    if (sPort2.matches("^\\d+$"))
      MY_PORT = Integer.parseInt(sPort2);
    LDAPConnection lc = null;
    try {
      lc = new LDAPConnection();
      lc.connect(MY_URL, MY_PORT);
      lc.bind(3, MY_USER, password.getBytes("UTF8"));
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    } catch (LDAPException e) {
      e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of com.novell.ldap.LDAPConnection

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.