Translate

Thursday, October 8, 2015

Java - Search for AD Groups and List Group Attributes

Added the ability to search for AD groups and get a Group's Attributes to my LDAP class:

 /**
  * 
  * @param groupName The name of the AD group.
  * @return The AD attributes for the group or null if error.
  * @throws NamingException
  */
    public Attributes getADGroupAttributes(String groupName) throws NamingException {
     this.userName = null;
        String searchFilter = "(&(objectClass=group)(cn=" + groupName + "))";
        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        NamingEnumeration  results = ctx.search("dc=MYDOMAIN,dc=LOCAL", searchFilter, searchControls);
        SearchResult searchResult = null;
        if(results.hasMoreElements()) {
             searchResult = (SearchResult) results.nextElement();
            //make sure there is not another item available, there should be only 1 match
            if(results.hasMoreElements()) {
                this.strRes = "Matched multiple groups for the group name: " + groupName;
                return null;
            }
        }
        else{
            this.strRes = "No groups found";
            return null;         
        }
        return searchResult.getAttributes();  
    } 
 
    /**
     * 
     * @param groupName The group name to search for. Can use wild cards.
     * @return A comma delimited list of the AD group names
     * @throws NamingException
     */
    public String searchforADGroup(String groupName) throws NamingException {
     this.userName = null;
        String searchFilter = "(&(objectClass=group)(cn=" + groupName + "))";
        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        NamingEnumeration  results = ctx.search("dc=MYDOMAIN,dc=LOCAL", searchFilter, searchControls);
        SearchResult searchResult = null;
        String strGroups = "";
        if(results!= null) {
         try {
    while(results.hasMore()) {
     searchResult = (SearchResult) results.nextElement();
     strGroups = strGroups + searchResult.getAttributes().get("cn") + ",";
    }
   } catch (Exception e) {

   }
        }
        else{
            this.strRes = "No groups found";
            return null;         
        }
        return strGroups;  
    } 

Wednesday, October 7, 2015

JQUERY - Object doesn't support property or method 'addEventListener' Error

Working on the new site and it works on my laptop for IE but loading from the site in IE it would come up was frozen. Nothing worked. Using the developer tools in IE I saw that I was getting the "Object doesn't support property or method 'addEventListener'" error in jquery. Added the following in the header of the JSP page fixed the problem:

 <meta http-equiv="X-UA-Compatible" content="IE=edge;" />

Thanks To

Tuesday, October 6, 2015

Java - Secure LDAP - simple bind failed: internews.local:636 Error

This took me a while to fix because I had to get the right certificates to install in the Java certificate store on the new server. I finally found the "cer" files on one of the domain controllers, copied the files to the new server, and then used the Java keytool utility to import the certificates into the Java certificate store.
Some tips:
Use "keytool.exe" located the the Java bin folder to import the certificates.
Import the certificates into the "cacerts" file located in the security folder under "jre\lib\security".

Monday, October 5, 2015

Tomcat - CertificateFile must be defined when using SSL with APR error

Setting Tomcat to use SSL and I was getting the "Connector attribute SSLCertificateFile must be defined when using SSL with APR" error. Had to disable APR in server.xml as follows:


  <!--
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  -->

Tomcat - Cannot Start Tomcat Service

I'm setting up a new server with Java Server 1.8 and Tomcat 8. Went to install Tomcat as a service on a Windows Server 2008 box and the install finished with an error but the Tomcat Service was there as a Windows Service. When I tried to start the service I would get an error message. The event log showed an error with Event ID 7024. The Tomcat commons-daemon log showed "[2015-10-04 07:18:16] [error] [12756] Failed creating java". What I needed to do is tell Tomcat the location of the "jvm.dll" file. I ran the tomcat8w utility located in the Tomcat bin folder and set the location on the Java tab: