String[] parts = groupName.split(",");\r
groupName = parts[0];\r
if (groupName.indexOf("=") > 0) {\r
- groupName = groupName.substring(groupName.indexOf("=") + 1); //CN=icmadmin,CN=Users,DC=dev2003,DC=user,DC=hu\r
+ groupName = groupName.substring(groupName.indexOf("=") + 1); // CN=icmadmin,CN=Users,DC=dev2003,DC=user,DC=hu\r
}\r
if (!ret.contains(groupName) && groupName.matches(cfg.getProperty("ad_groupname_regexp"))) {\r
ret.add(groupName);\r
\r
- //RECURSIVE CALL\r
+ // RECURSIVE CALL\r
getADGroupsForCN(groupName, ret);\r
}\r
}\r
String[] parts = groupName.split(",");\r
groupName = parts[0];\r
if (groupName.indexOf("=") > 0) {\r
- groupName = groupName.substring(groupName.indexOf("=") + 1); //CN=icmadmin,CN=Users,DC=dev2003,DC=user,DC=hu\r
+ groupName = groupName.substring(groupName.indexOf("=") + 1); // CN=icmadmin,CN=Users,DC=dev2003,DC=user,DC=hu\r
}\r
if (!ret.contains(groupName) && groupName.matches(cfg.getProperty("ad_groupname_regexp"))) {\r
ret.add(groupName);\r
\r
- //RECURSIVE CALL\r
+ // RECURSIVE CALL\r
getADGroupsForCN(groupName, ret);\r
}\r
}\r
}\r
\r
/**\r
- * Minden AD csoport els� CN nev�t adja vissza.\r
+ * Minden AD csoport első CN nevét adja vissza.\r
*/\r
\r
- // static public void getAllADGroupName(Vector ret) throws Exception {\r
+ // static public void getAllADGroupName(Vector ret) throws Exception {\r
//\r
- // LdapContext ctx = null;\r
- // NamingEnumeration answer = null;\r
- // try {\r
- // //Create the initial directory context\r
- // ctx = getContext();\r
+ // LdapContext ctx = null;\r
+ // NamingEnumeration answer = null;\r
+ // try {\r
+ // //Create the initial directory context\r
+ // ctx = getContext();\r
//\r
- // //Create the search controls\r
- // SearchControls searchCtls = new SearchControls();\r
+ // //Create the search controls\r
+ // SearchControls searchCtls = new SearchControls();\r
//\r
- // //Specify the search scope\r
- // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);\r
+ // //Specify the search scope\r
+ // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);\r
//\r
- // //specify the LDAP search filter\r
- // String searchFilter = "(&(objectClass=group))"; //(CN=All Research)\r
+ // //specify the LDAP search filter\r
+ // String searchFilter = "(&(objectClass=group))"; //(CN=All Research)\r
//\r
- // //Specify the Base for the search\r
- // String searchBase = cfg.getProperty("ad_base_dn");\r
+ // //Specify the Base for the search\r
+ // String searchBase = cfg.getProperty("ad_base_dn");\r
//\r
- // //initialize counter to total the group members\r
- // int totalResults = 0;\r
+ // //initialize counter to total the group members\r
+ // int totalResults = 0;\r
//\r
- // //Specify the attributes to return\r
- // String returnedAtts[] = { "member" };\r
- // searchCtls.setReturningAttributes(returnedAtts);\r
+ // //Specify the attributes to return\r
+ // String returnedAtts[] = { "member" };\r
+ // searchCtls.setReturningAttributes(returnedAtts);\r
//\r
- // //Search for objects using the filter\r
- // answer = ctx.search(searchBase, searchFilter, searchCtls);\r
+ // //Search for objects using the filter\r
+ // answer = ctx.search(searchBase, searchFilter, searchCtls);\r
//\r
- // //Loop through the search results\r
- // while (answer.hasMoreElements()) {\r
- // SearchResult sr = (SearchResult) answer.next();\r
- // String grpname = sr.getName();\r
- // String[] parts = grpname.split(",");\r
- // String[] firstCn = parts[0].split("=");\r
- // ret.add(firstCn[1]);\r
- // }\r
+ // //Loop through the search results\r
+ // while (answer.hasMoreElements()) {\r
+ // SearchResult sr = (SearchResult) answer.next();\r
+ // String grpname = sr.getName();\r
+ // String[] parts = grpname.split(",");\r
+ // String[] firstCn = parts[0].split("=");\r
+ // ret.add(firstCn[1]);\r
+ // }\r
//\r
- // } catch (Exception e) {\r
- // } finally {\r
- // try {\r
- // if (answer != null)\r
- // answer.close();\r
- // if (ctx != null)\r
- // ctx.close();\r
- // } catch (Exception exc) {\r
- // }\r
- // }\r
- // }\r
+ // } catch (Exception e) {\r
+ // } finally {\r
+ // try {\r
+ // if (answer != null)\r
+ // answer.close();\r
+ // if (ctx != null)\r
+ // ctx.close();\r
+ // } catch (Exception exc) {\r
+ // }\r
+ // }\r
+ // }\r
\r
- // synchronized static public String getAllFromAD(String name) throws Exception {\r
+ // synchronized static public String getAllFromAD(String name) throws Exception\r
+ // {\r
//\r
- // //if(1==1) return "-";\r
+ // //if(1==1) return "-";\r
//\r
- // String fullName = "";\r
- // LdapContext ctx = null;\r
- // NamingEnumeration answer = null;\r
- // try {\r
- // //Create the initial directory context\r
- // ctx = getContext();\r
+ // String fullName = "";\r
+ // LdapContext ctx = null;\r
+ // NamingEnumeration answer = null;\r
+ // try {\r
+ // //Create the initial directory context\r
+ // ctx = getContext();\r
//\r
- // //Create the search controls\r
- // SearchControls searchCtls = new SearchControls();\r
+ // //Create the search controls\r
+ // SearchControls searchCtls = new SearchControls();\r
//\r
- // //Specify the search scope\r
- // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);\r
+ // //Specify the search scope\r
+ // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);\r
//\r
- // //Specify the LDAP search filter\r
- // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" + name + "))"; //p�ld�k: "(&(objectClass=person)(objectCategory=Person)(CN=y011216s))"; "(&(objectClass=group)(objectCategory=Group)(CN=Users))";\r
+ // //Specify the LDAP search filter\r
+ // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" +\r
+ // name + "))"; //p�ld�k:\r
+ // "(&(objectClass=person)(objectCategory=Person)(CN=y011216s))";\r
+ // "(&(objectClass=group)(objectCategory=Group)(CN=Users))";\r
//\r
- // //Specify the Base for the search\r
- // String searchBase = cfg.getProperty("ad_base_dn");\r
+ // //Specify the Base for the search\r
+ // String searchBase = cfg.getProperty("ad_base_dn");\r
//\r
- // //Specify the attributes to return\r
- // //String returnedAtts[]={"memberOf"}; //"member"\r
- // //searchCtls.setReturningAttributes(returnedAtts);\r
+ // //Specify the attributes to return\r
+ // //String returnedAtts[]={"memberOf"}; //"member"\r
+ // //searchCtls.setReturningAttributes(returnedAtts);\r
//\r
- // //Search for objects using the filter\r
- // answer = ctx.search(searchBase, searchFilter, searchCtls);\r
+ // //Search for objects using the filter\r
+ // answer = ctx.search(searchBase, searchFilter, searchCtls);\r
//\r
- // //Loop through the search results\r
- // if (answer.hasMoreElements()) {\r
- // SearchResult sr = (SearchResult) answer.next();\r
- // Attributes srAttrs = sr.getAttributes();\r
+ // //Loop through the search results\r
+ // if (answer.hasMoreElements()) {\r
+ // SearchResult sr = (SearchResult) answer.next();\r
+ // Attributes srAttrs = sr.getAttributes();\r
//\r
- // for (NamingEnumeration<?> enu = srAttrs.getAll(); enu.hasMore();) {\r
- // Attribute attr = (Attribute) enu.next();\r
- // //System.out.println(attr);\r
- // if (attr != null) {\r
- // System.out.println("attrib: " + attr.getID() + " : " + attr.get(0).toString());\r
- // }\r
- // }\r
- // }\r
- // } catch (Exception e) {\r
- // System.out.println(e.getMessage());\r
- // } finally {\r
- // try {\r
- // if (answer != null)\r
- // answer.close();\r
- // if (ctx != null)\r
- // ctx.close();\r
- // } catch (Exception exc) {\r
- // }\r
- // }\r
- // return fullName;\r
- // }\r
+ // for (NamingEnumeration<?> enu = srAttrs.getAll(); enu.hasMore();) {\r
+ // Attribute attr = (Attribute) enu.next();\r
+ // //System.out.println(attr);\r
+ // if (attr != null) {\r
+ // System.out.println("attrib: " + attr.getID() + " : " +\r
+ // attr.get(0).toString());\r
+ // }\r
+ // }\r
+ // }\r
+ // } catch (Exception e) {\r
+ // System.out.println(e.getMessage());\r
+ // } finally {\r
+ // try {\r
+ // if (answer != null)\r
+ // answer.close();\r
+ // if (ctx != null)\r
+ // ctx.close();\r
+ // } catch (Exception exc) {\r
+ // }\r
+ // }\r
+ // return fullName;\r
+ // }\r
\r
synchronized static public LdapContext getContext() throws Exception {\r
\r
String adminPassword = cfg.getProperty("ad_nonsecure_user_password");\r
String ldapURL = "ldap://" + cfg.getProperty("ad_host") + ":" + cfg.getProperty("ad_nonsecureport");\r
\r
- Hashtable env = new Hashtable();\r
+ Hashtable<String, String> env = new Hashtable<String, String>();\r
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");\r
- //set security credentials, note using simple cleartext authentication\r
+ // set security credentials, note using simple cleartext authentication\r
env.put(Context.SECURITY_AUTHENTICATION, "simple");\r
- //env.put(Context.SECURITY_PRINCIPAL, adminName);\r
+ // env.put(Context.SECURITY_PRINCIPAL, adminName);\r
env.put(Context.SECURITY_PRINCIPAL, "echotest@intra.echotv.hu");\r
env.put(Context.SECURITY_CREDENTIALS, adminPassword);\r
- //connect to my domain controller\r
+ // connect to my domain controller\r
env.put(Context.PROVIDER_URL, ldapURL);\r
\r
- //Create the initial directory context\r
+ // Create the initial directory context\r
LdapContext ctx = new InitialLdapContext(env, null);\r
return ctx;\r
}\r
\r
- // synchronized static public String getDisplayName(String name) throws Exception {\r
- // String fullName = "";\r
- // LdapContext ctx = null;\r
- // NamingEnumeration<SearchResult> answer = null;\r
- // try {\r
- // ctx = getContext();\r
- // SearchControls searchCtls = new SearchControls();\r
- // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);\r
- // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" + name + "))";\r
- // String searchBase = cfg.getProperty("ad_base_dn");\r
- // answer = ctx.search(searchBase, searchFilter, searchCtls);\r
- // if (answer.hasMoreElements()) {\r
- // SearchResult sr = answer.next();\r
- // Attribute attr = sr.getAttributes().get("displayName");\r
- // if (attr != null) {\r
- // return attr.get(0).toString();\r
- // }\r
- // }\r
- // } catch (Exception e) {\r
- // System.out.println(e.getMessage());\r
- // } finally {\r
- // try {\r
- // if (answer != null)\r
- // answer.close();\r
- // if (ctx != null)\r
- // ctx.close();\r
- // } catch (Exception exc) {\r
- // }\r
- // }\r
- // return fullName;\r
- // }\r
+ // synchronized static public String getDisplayName(String name) throws\r
+ // Exception {\r
+ // String fullName = "";\r
+ // LdapContext ctx = null;\r
+ // NamingEnumeration<SearchResult> answer = null;\r
+ // try {\r
+ // ctx = getContext();\r
+ // SearchControls searchCtls = new SearchControls();\r
+ // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);\r
+ // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" +\r
+ // name + "))";\r
+ // String searchBase = cfg.getProperty("ad_base_dn");\r
+ // answer = ctx.search(searchBase, searchFilter, searchCtls);\r
+ // if (answer.hasMoreElements()) {\r
+ // SearchResult sr = answer.next();\r
+ // Attribute attr = sr.getAttributes().get("displayName");\r
+ // if (attr != null) {\r
+ // return attr.get(0).toString();\r
+ // }\r
+ // }\r
+ // } catch (Exception e) {\r
+ // System.out.println(e.getMessage());\r
+ // } finally {\r
+ // try {\r
+ // if (answer != null)\r
+ // answer.close();\r
+ // if (ctx != null)\r
+ // ctx.close();\r
+ // } catch (Exception exc) {\r
+ // }\r
+ // }\r
+ // return fullName;\r
+ // }\r
//\r
- // synchronized static public String getMail(String name) throws Exception {\r
- // String fullName = "";\r
- // LdapContext ctx = null;\r
- // NamingEnumeration<SearchResult> answer = null;\r
- // try {\r
- // ctx = getContext();\r
- // SearchControls searchCtls = new SearchControls();\r
- // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);\r
- // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" + name + "))";\r
- // String searchBase = cfg.getProperty("ad_base_dn");\r
- // answer = ctx.search(searchBase, searchFilter, searchCtls);\r
- // if (answer.hasMoreElements()) {\r
- // SearchResult sr = answer.next();\r
- // Attribute attr = sr.getAttributes().get("userPrincipalName");\r
- // if (attr != null) {\r
- // return attr.get(0).toString();\r
- // }\r
- // }\r
- // } catch (Exception e) {\r
- // System.out.println(e.getMessage());\r
- // } finally {\r
- // try {\r
- // if (answer != null)\r
- // answer.close();\r
- // if (ctx != null)\r
- // ctx.close();\r
- // } catch (Exception exc) {\r
- // }\r
- // }\r
- // return fullName;\r
- // }\r
+ // synchronized static public String getMail(String name) throws Exception {\r
+ // String fullName = "";\r
+ // LdapContext ctx = null;\r
+ // NamingEnumeration<SearchResult> answer = null;\r
+ // try {\r
+ // ctx = getContext();\r
+ // SearchControls searchCtls = new SearchControls();\r
+ // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);\r
+ // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" +\r
+ // name + "))";\r
+ // String searchBase = cfg.getProperty("ad_base_dn");\r
+ // answer = ctx.search(searchBase, searchFilter, searchCtls);\r
+ // if (answer.hasMoreElements()) {\r
+ // SearchResult sr = answer.next();\r
+ // Attribute attr = sr.getAttributes().get("userPrincipalName");\r
+ // if (attr != null) {\r
+ // return attr.get(0).toString();\r
+ // }\r
+ // }\r
+ // } catch (Exception e) {\r
+ // System.out.println(e.getMessage());\r
+ // } finally {\r
+ // try {\r
+ // if (answer != null)\r
+ // answer.close();\r
+ // if (ctx != null)\r
+ // ctx.close();\r
+ // } catch (Exception exc) {\r
+ // }\r
+ // }\r
+ // return fullName;\r
+ // }\r
//\r
- // //TEST CODE\r
- // public static void main(String[] args) {\r
- // try {\r
- // Properties config = new Properties();\r
- // config.setProperty("ad_host", "10.10.254.11");\r
- // config.setProperty("ad_nonsecureport", "389");\r
- // config.setProperty("ad_base_dn", "DC=intra,DC=echotv,DC=hu");\r
- // config.setProperty("ad_nonsecure_user_dn", "CN=echotest,CN=Users");\r
- // config.setProperty("ad_nonsecure_user_password", "aA123456+");\r
- // ADHandler.setConfig(config);\r
+ // //TEST CODE\r
+ // public static void main(String[] args) {\r
+ // try {\r
+ // Properties config = new Properties();\r
+ // config.setProperty("ad_host", "10.10.254.11");\r
+ // config.setProperty("ad_nonsecureport", "389");\r
+ // config.setProperty("ad_base_dn", "DC=intra,DC=echotv,DC=hu");\r
+ // config.setProperty("ad_nonsecure_user_dn", "CN=echotest,CN=Users");\r
+ // config.setProperty("ad_nonsecure_user_password", "aA123456+");\r
+ // ADHandler.setConfig(config);\r
//\r
- // ADHandler.getMail("echotest");\r
- // System.out.println("Display name: " + ADHandler.getDisplayName("echotest"));\r
- // Vector groups = new Vector();\r
- // ADHandler.getADGroupsForCN("echotest", groups);\r
- // } catch (Exception e) {\r
- // e.printStackTrace();\r
- // }\r
- // }\r
+ // ADHandler.getMail("echotest");\r
+ // System.out.println("Display name: " + ADHandler.getDisplayName("echotest"));\r
+ // Vector groups = new Vector();\r
+ // ADHandler.getADGroupsForCN("echotest", groups);\r
+ // } catch (Exception e) {\r
+ // e.printStackTrace();\r
+ // }\r
+ // }\r
\r
static public void setConfig(Properties _cfg) {\r
ADHandler.cfg = _cfg;\r