log.info("Starting search"); results = ldap.search("", pattern, new SearchControls(SearchControls.SUBTREE_SCOPE, 1, 1000*Integer.parseInt(Configuration.getProperty("no.feide.moria.backend.ldap.timeout", "15000")), new String[] {}, false, false));
log.info("Starting search for "+pattern); results = ldap.search("", pattern, new SearchControls(SearchControls.SUBTREE_SCOPE, 1, 1000*Integer.parseInt(Configuration.getProperty("no.feide.moria.backend.ldap.timeout", "15")), new String[] {}, false, false));
    private String ldapSearch(String pattern)    throws BackendException {        log.finer("ldapSearch(String)");                // Check for illegal content.        String[] illegals = {"*", "\2a"};        for (int i=0; i< illegals.length; i++)            if (pattern.indexOf(illegals[i]) > -1)                return null;                try {                        NamingEnumeration results;            try {                                // Start counting the (milli)seconds.                long searchStart = System.currentTimeMillis();                try {                    log.info("Starting search");                    results = ldap.search("", pattern, new SearchControls(SearchControls.SUBTREE_SCOPE, 1, 1000*Integer.parseInt(Configuration.getProperty("no.feide.moria.backend.ldap.timeout", "15000")), new String[] {}, false, false));                    log.info("Search completed");                    if (!results.hasMore()) {                        log.info("No results");                        log.warning("No match for "+pattern+" on "+ldap.getEnvironment().get(Context.PROVIDER_URL));                        return null;                    }                } catch (TimeLimitExceededException e) {                    log.severe("TimelimitExceededException caught after "+(System.currentTimeMillis()-searchStart)+"ms and re-thrown as BackendException");                    throw new BackendException(e);                }                            } catch (LdapReferralException e) {                                // We just caught a referral. Follow it recursively, enabling                // SSL.                log.info("Enabling SSL");                Hashtable refEnv = new Hashtable(defaultEnv);                refEnv.put(Context.SECURITY_PROTOCOL, "ssl");                try {                    log.info("Getting referral contest");                    refEnv = e.getReferralContext(refEnv).getEnvironment();                    log.info("OK");                    log.info("Matched "+pattern+" to referral "+refEnv.get(Context.PROVIDER_URL));                    log.info("Closing old context");                    ldap.close();                    log.info("Reopening new context");                    ldap = new InitialLdapContext(refEnv, null);                    log.info("Done");                } catch (TimeLimitExceededException ee) {                    log.severe("Time limit exceeded when following referral");                    throw new BackendException("Time limit exceeded when following referral");                }                return ldapSearch(pattern);                            }                        // We just found an element.            try {                log.info("Looking for search results");                SearchResult entry = (SearchResult)results.next();                log.info("Getting entry name");                String rdn = entry.getName();                log.info("Done");                log.info("Matched "+pattern+" on "+ldap.getEnvironment().get(Context.PROVIDER_URL)+" to element "+rdn);                log.info("All done");                return rdn;            } catch (TimeLimitExceededException e) {                log.severe("TimeLimitExceededException caught (when reading search results) and re-thrown as BackendException");                throw new BackendException(e);            }                        } catch (ConfigurationException e) {            log.severe("ConfigurationException caught and re-thrown as BackendException");            throw new BackendException(e);        } catch (NamingException e) {            e.printStackTrace();            log.severe("NamingException caught and re-thrown as BackendException");            throw new BackendException(e);        }    }