From 8304f9885db3298cd7753ea6bb7a577feedfd347 Mon Sep 17 00:00:00 2001 From: Sweidan Omar Date: Mon, 6 Dec 2021 11:54:52 +0000 Subject: [PATCH] git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C32470 --- .../src/user/jobengine/zk/util/ADHandler.java | 360 +++++++++--------- 1 file changed, 184 insertions(+), 176 deletions(-) diff --git a/server/user.mediacube.gui/src/user/jobengine/zk/util/ADHandler.java b/server/user.mediacube.gui/src/user/jobengine/zk/util/ADHandler.java index b9603101..a84faac3 100644 --- a/server/user.mediacube.gui/src/user/jobengine/zk/util/ADHandler.java +++ b/server/user.mediacube.gui/src/user/jobengine/zk/util/ADHandler.java @@ -36,12 +36,12 @@ public class ADHandler { String[] parts = groupName.split(","); groupName = parts[0]; if (groupName.indexOf("=") > 0) { - groupName = groupName.substring(groupName.indexOf("=") + 1); //CN=icmadmin,CN=Users,DC=dev2003,DC=user,DC=hu + groupName = groupName.substring(groupName.indexOf("=") + 1); // CN=icmadmin,CN=Users,DC=dev2003,DC=user,DC=hu } if (!ret.contains(groupName) && groupName.matches(cfg.getProperty("ad_groupname_regexp"))) { ret.add(groupName); - //RECURSIVE CALL + // RECURSIVE CALL getADGroupsForCN(groupName, ret); } } @@ -79,12 +79,12 @@ public class ADHandler { String[] parts = groupName.split(","); groupName = parts[0]; if (groupName.indexOf("=") > 0) { - groupName = groupName.substring(groupName.indexOf("=") + 1); //CN=icmadmin,CN=Users,DC=dev2003,DC=user,DC=hu + groupName = groupName.substring(groupName.indexOf("=") + 1); // CN=icmadmin,CN=Users,DC=dev2003,DC=user,DC=hu } if (!ret.contains(groupName) && groupName.matches(cfg.getProperty("ad_groupname_regexp"))) { ret.add(groupName); - //RECURSIVE CALL + // RECURSIVE CALL getADGroupsForCN(groupName, ret); } } @@ -103,116 +103,121 @@ public class ADHandler { } /** - * Minden AD csoport els� CN nev�t adja vissza. + * Minden AD csoport első CN nevét adja vissza. */ - // static public void getAllADGroupName(Vector ret) throws Exception { + // static public void getAllADGroupName(Vector ret) throws Exception { // - // LdapContext ctx = null; - // NamingEnumeration answer = null; - // try { - // //Create the initial directory context - // ctx = getContext(); + // LdapContext ctx = null; + // NamingEnumeration answer = null; + // try { + // //Create the initial directory context + // ctx = getContext(); // - // //Create the search controls - // SearchControls searchCtls = new SearchControls(); + // //Create the search controls + // SearchControls searchCtls = new SearchControls(); // - // //Specify the search scope - // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); + // //Specify the search scope + // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); // - // //specify the LDAP search filter - // String searchFilter = "(&(objectClass=group))"; //(CN=All Research) + // //specify the LDAP search filter + // String searchFilter = "(&(objectClass=group))"; //(CN=All Research) // - // //Specify the Base for the search - // String searchBase = cfg.getProperty("ad_base_dn"); + // //Specify the Base for the search + // String searchBase = cfg.getProperty("ad_base_dn"); // - // //initialize counter to total the group members - // int totalResults = 0; + // //initialize counter to total the group members + // int totalResults = 0; // - // //Specify the attributes to return - // String returnedAtts[] = { "member" }; - // searchCtls.setReturningAttributes(returnedAtts); + // //Specify the attributes to return + // String returnedAtts[] = { "member" }; + // searchCtls.setReturningAttributes(returnedAtts); // - // //Search for objects using the filter - // answer = ctx.search(searchBase, searchFilter, searchCtls); + // //Search for objects using the filter + // answer = ctx.search(searchBase, searchFilter, searchCtls); // - // //Loop through the search results - // while (answer.hasMoreElements()) { - // SearchResult sr = (SearchResult) answer.next(); - // String grpname = sr.getName(); - // String[] parts = grpname.split(","); - // String[] firstCn = parts[0].split("="); - // ret.add(firstCn[1]); - // } + // //Loop through the search results + // while (answer.hasMoreElements()) { + // SearchResult sr = (SearchResult) answer.next(); + // String grpname = sr.getName(); + // String[] parts = grpname.split(","); + // String[] firstCn = parts[0].split("="); + // ret.add(firstCn[1]); + // } // - // } catch (Exception e) { - // } finally { - // try { - // if (answer != null) - // answer.close(); - // if (ctx != null) - // ctx.close(); - // } catch (Exception exc) { - // } - // } - // } + // } catch (Exception e) { + // } finally { + // try { + // if (answer != null) + // answer.close(); + // if (ctx != null) + // ctx.close(); + // } catch (Exception exc) { + // } + // } + // } - // synchronized static public String getAllFromAD(String name) throws Exception { + // synchronized static public String getAllFromAD(String name) throws Exception + // { // - // //if(1==1) return "-"; + // //if(1==1) return "-"; // - // String fullName = ""; - // LdapContext ctx = null; - // NamingEnumeration answer = null; - // try { - // //Create the initial directory context - // ctx = getContext(); + // String fullName = ""; + // LdapContext ctx = null; + // NamingEnumeration answer = null; + // try { + // //Create the initial directory context + // ctx = getContext(); // - // //Create the search controls - // SearchControls searchCtls = new SearchControls(); + // //Create the search controls + // SearchControls searchCtls = new SearchControls(); // - // //Specify the search scope - // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); + // //Specify the search scope + // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); // - // //Specify the LDAP search filter - // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" + name + "))"; //p�ld�k: "(&(objectClass=person)(objectCategory=Person)(CN=y011216s))"; "(&(objectClass=group)(objectCategory=Group)(CN=Users))"; + // //Specify the LDAP search filter + // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" + + // name + "))"; //p�ld�k: + // "(&(objectClass=person)(objectCategory=Person)(CN=y011216s))"; + // "(&(objectClass=group)(objectCategory=Group)(CN=Users))"; // - // //Specify the Base for the search - // String searchBase = cfg.getProperty("ad_base_dn"); + // //Specify the Base for the search + // String searchBase = cfg.getProperty("ad_base_dn"); // - // //Specify the attributes to return - // //String returnedAtts[]={"memberOf"}; //"member" - // //searchCtls.setReturningAttributes(returnedAtts); + // //Specify the attributes to return + // //String returnedAtts[]={"memberOf"}; //"member" + // //searchCtls.setReturningAttributes(returnedAtts); // - // //Search for objects using the filter - // answer = ctx.search(searchBase, searchFilter, searchCtls); + // //Search for objects using the filter + // answer = ctx.search(searchBase, searchFilter, searchCtls); // - // //Loop through the search results - // if (answer.hasMoreElements()) { - // SearchResult sr = (SearchResult) answer.next(); - // Attributes srAttrs = sr.getAttributes(); + // //Loop through the search results + // if (answer.hasMoreElements()) { + // SearchResult sr = (SearchResult) answer.next(); + // Attributes srAttrs = sr.getAttributes(); // - // for (NamingEnumeration enu = srAttrs.getAll(); enu.hasMore();) { - // Attribute attr = (Attribute) enu.next(); - // //System.out.println(attr); - // if (attr != null) { - // System.out.println("attrib: " + attr.getID() + " : " + attr.get(0).toString()); - // } - // } - // } - // } catch (Exception e) { - // System.out.println(e.getMessage()); - // } finally { - // try { - // if (answer != null) - // answer.close(); - // if (ctx != null) - // ctx.close(); - // } catch (Exception exc) { - // } - // } - // return fullName; - // } + // for (NamingEnumeration enu = srAttrs.getAll(); enu.hasMore();) { + // Attribute attr = (Attribute) enu.next(); + // //System.out.println(attr); + // if (attr != null) { + // System.out.println("attrib: " + attr.getID() + " : " + + // attr.get(0).toString()); + // } + // } + // } + // } catch (Exception e) { + // System.out.println(e.getMessage()); + // } finally { + // try { + // if (answer != null) + // answer.close(); + // if (ctx != null) + // ctx.close(); + // } catch (Exception exc) { + // } + // } + // return fullName; + // } synchronized static public LdapContext getContext() throws Exception { @@ -220,104 +225,107 @@ public class ADHandler { String adminPassword = cfg.getProperty("ad_nonsecure_user_password"); String ldapURL = "ldap://" + cfg.getProperty("ad_host") + ":" + cfg.getProperty("ad_nonsecureport"); - Hashtable env = new Hashtable(); + Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); - //set security credentials, note using simple cleartext authentication + // set security credentials, note using simple cleartext authentication env.put(Context.SECURITY_AUTHENTICATION, "simple"); - //env.put(Context.SECURITY_PRINCIPAL, adminName); + // env.put(Context.SECURITY_PRINCIPAL, adminName); env.put(Context.SECURITY_PRINCIPAL, "echotest@intra.echotv.hu"); env.put(Context.SECURITY_CREDENTIALS, adminPassword); - //connect to my domain controller + // connect to my domain controller env.put(Context.PROVIDER_URL, ldapURL); - //Create the initial directory context + // Create the initial directory context LdapContext ctx = new InitialLdapContext(env, null); return ctx; } - // synchronized static public String getDisplayName(String name) throws Exception { - // String fullName = ""; - // LdapContext ctx = null; - // NamingEnumeration answer = null; - // try { - // ctx = getContext(); - // SearchControls searchCtls = new SearchControls(); - // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); - // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" + name + "))"; - // String searchBase = cfg.getProperty("ad_base_dn"); - // answer = ctx.search(searchBase, searchFilter, searchCtls); - // if (answer.hasMoreElements()) { - // SearchResult sr = answer.next(); - // Attribute attr = sr.getAttributes().get("displayName"); - // if (attr != null) { - // return attr.get(0).toString(); - // } - // } - // } catch (Exception e) { - // System.out.println(e.getMessage()); - // } finally { - // try { - // if (answer != null) - // answer.close(); - // if (ctx != null) - // ctx.close(); - // } catch (Exception exc) { - // } - // } - // return fullName; - // } + // synchronized static public String getDisplayName(String name) throws + // Exception { + // String fullName = ""; + // LdapContext ctx = null; + // NamingEnumeration answer = null; + // try { + // ctx = getContext(); + // SearchControls searchCtls = new SearchControls(); + // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); + // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" + + // name + "))"; + // String searchBase = cfg.getProperty("ad_base_dn"); + // answer = ctx.search(searchBase, searchFilter, searchCtls); + // if (answer.hasMoreElements()) { + // SearchResult sr = answer.next(); + // Attribute attr = sr.getAttributes().get("displayName"); + // if (attr != null) { + // return attr.get(0).toString(); + // } + // } + // } catch (Exception e) { + // System.out.println(e.getMessage()); + // } finally { + // try { + // if (answer != null) + // answer.close(); + // if (ctx != null) + // ctx.close(); + // } catch (Exception exc) { + // } + // } + // return fullName; + // } // - // synchronized static public String getMail(String name) throws Exception { - // String fullName = ""; - // LdapContext ctx = null; - // NamingEnumeration answer = null; - // try { - // ctx = getContext(); - // SearchControls searchCtls = new SearchControls(); - // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); - // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" + name + "))"; - // String searchBase = cfg.getProperty("ad_base_dn"); - // answer = ctx.search(searchBase, searchFilter, searchCtls); - // if (answer.hasMoreElements()) { - // SearchResult sr = answer.next(); - // Attribute attr = sr.getAttributes().get("userPrincipalName"); - // if (attr != null) { - // return attr.get(0).toString(); - // } - // } - // } catch (Exception e) { - // System.out.println(e.getMessage()); - // } finally { - // try { - // if (answer != null) - // answer.close(); - // if (ctx != null) - // ctx.close(); - // } catch (Exception exc) { - // } - // } - // return fullName; - // } + // synchronized static public String getMail(String name) throws Exception { + // String fullName = ""; + // LdapContext ctx = null; + // NamingEnumeration answer = null; + // try { + // ctx = getContext(); + // SearchControls searchCtls = new SearchControls(); + // searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); + // String searchFilter = "(&(objectClass=person)(objectCategory=Person)(CN=" + + // name + "))"; + // String searchBase = cfg.getProperty("ad_base_dn"); + // answer = ctx.search(searchBase, searchFilter, searchCtls); + // if (answer.hasMoreElements()) { + // SearchResult sr = answer.next(); + // Attribute attr = sr.getAttributes().get("userPrincipalName"); + // if (attr != null) { + // return attr.get(0).toString(); + // } + // } + // } catch (Exception e) { + // System.out.println(e.getMessage()); + // } finally { + // try { + // if (answer != null) + // answer.close(); + // if (ctx != null) + // ctx.close(); + // } catch (Exception exc) { + // } + // } + // return fullName; + // } // - // //TEST CODE - // public static void main(String[] args) { - // try { - // Properties config = new Properties(); - // config.setProperty("ad_host", "10.10.254.11"); - // config.setProperty("ad_nonsecureport", "389"); - // config.setProperty("ad_base_dn", "DC=intra,DC=echotv,DC=hu"); - // config.setProperty("ad_nonsecure_user_dn", "CN=echotest,CN=Users"); - // config.setProperty("ad_nonsecure_user_password", "aA123456+"); - // ADHandler.setConfig(config); + // //TEST CODE + // public static void main(String[] args) { + // try { + // Properties config = new Properties(); + // config.setProperty("ad_host", "10.10.254.11"); + // config.setProperty("ad_nonsecureport", "389"); + // config.setProperty("ad_base_dn", "DC=intra,DC=echotv,DC=hu"); + // config.setProperty("ad_nonsecure_user_dn", "CN=echotest,CN=Users"); + // config.setProperty("ad_nonsecure_user_password", "aA123456+"); + // ADHandler.setConfig(config); // - // ADHandler.getMail("echotest"); - // System.out.println("Display name: " + ADHandler.getDisplayName("echotest")); - // Vector groups = new Vector(); - // ADHandler.getADGroupsForCN("echotest", groups); - // } catch (Exception e) { - // e.printStackTrace(); - // } - // } + // ADHandler.getMail("echotest"); + // System.out.println("Display name: " + ADHandler.getDisplayName("echotest")); + // Vector groups = new Vector(); + // ADHandler.getADGroupsForCN("echotest", groups); + // } catch (Exception e) { + // e.printStackTrace(); + // } + // } static public void setConfig(Properties _cfg) { ADHandler.cfg = _cfg; -- 2.54.0