{"record":{"id":"70355442acc5aed2","repo":"flowable/flowable-engine","slug":"could-not-create-initialdircontext-for-ldap-connec-703554","errorCode":null,"errorMessage":"Could not create InitialDirContext for LDAP connection: {}","messagePattern":"Could not create InitialDirContext for LDAP connection: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/flowable-ldap/src/main/java/org/flowable/ldap/LDAPConnectionUtil.java","lineNumber":60,"sourceCode":"        properties.put(Context.SECURITY_AUTHENTICATION, ldapConfigurator.getSecurityAuthentication());\n        properties.put(Context.SECURITY_PRINCIPAL, principal);\n        properties.put(Context.SECURITY_CREDENTIALS, credentials);\n\n        if (ldapConfigurator.isConnectionPooling()) {\n            properties.put(\"com.sun.jndi.ldap.connect.pool\", \"true\");\n        }\n\n        if (ldapConfigurator.getCustomConnectionParameters() != null) {\n            for (String customParameter : ldapConfigurator.getCustomConnectionParameters().keySet()) {\n                properties.put(customParameter, ldapConfigurator.getCustomConnectionParameters().get(customParameter));\n            }\n        }\n\n        InitialDirContext context;\n        try {\n            context = new InitialDirContext(properties);\n        } catch (NamingException e) {\n            LOGGER.warn(\"Could not create InitialDirContext for LDAP connection: {}\", e.getMessage());\n            throw new FlowableException(\"Could not create InitialDirContext for LDAP connection: \" + e.getMessage(), e);\n        }\n        return context;\n    }\n\n    public static void closeDirectoryContext(InitialDirContext initialDirContext) {\n        try {\n            initialDirContext.close();\n        } catch (NamingException e) {\n            LOGGER.warn(\"Could not close InitialDirContext correctly!\", e);\n        }\n    }\n\n}\n","sourceCodeStart":42,"sourceCodeEnd":75,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-ldap/src/main/java/org/flowable/ldap/LDAPConnectionUtil.java#L42-L75","documentation":"Thrown by LDAPConnectionUtil.createDirectoryContext when javax.naming's InitialDirContext cannot be established with the configured LDAP properties; the underlying NamingException is wrapped in a FlowableException. This is almost always a connectivity, authentication, or configuration problem with the LDAP server.","triggerScenarios":"Wrong LDAP URL/host/port, unreachable server, invalid bind DN or credentials, bad security protocol (simple vs SSL), malformed java.naming properties passed to the context.","commonSituations":"LDAP server hostname typo or firewall blocking port 389/636; expired or wrong service-account password; using ldaps:// without configured truststore (certificate issues); Flowable IDM LDAP invoker misconfigured in flowable.properties.","solutions":["Verify the LDAP URL, port, and that the server is reachable (e.g. telnet/ldapsearch to host:port)","Validate the bind DN and password with ldapsearch -x -H <url> -D <bindDn> -w <password>","Check the exception's chained NamingException detail (e.g. 'Connection refused', 'Invalid credentials', 'SSLHandshakeException') for the exact cause","For ldaps, import the server certificate into the JVM truststore (-Djavax.net.ssl.trustStore=...)","Review the FlowableLdapProperties/ldap invoker configuration for typos"],"exampleFix":"// before\nldap.host=ldap.mycompany.com\nldap.port=389\nldap.user=cn=admin,dc=mycompany,dc=corp   // wrong base DN\n// after (verified with ldapsearch)\nldap.host=ldap.mycompany.com\nldap.port=389\nldap.user=cn=admin,ou=people,dc=mycompany,dc=com\nldap.password=correct-password","handlingStrategy":"validation","validationCode":"// pre-flight LDAP connectivity + bind check before engine start\nHashtable<String,Object> env = new Hashtable<>();\nenv.put(Context.INITIAL_CONTEXT_FACTORY, \"com.sun.jndi.ldap.LdapCtxFactory\");\nenv.put(Context.PROVIDER_URL, \"ldap://ldap.mycompany.com:389\");\nenv.put(Context.SECURITY_AUTHENTICATION, \"simple\");\nenv.put(Context.SECURITY_PRINCIPAL, bindDn);\nenv.put(Context.SECURITY_CREDENTIALS, password);\ntry { new InitialDirContext(env).close(); } catch (NamingException e) { throw new IllegalStateException(\"LDAP preflight failed: \" + e.getMessage()); }","typeGuard":null,"tryCatchPattern":"try {\n    ctx = LDAPConnectionUtil.createDirectoryContext(ldapConfig);\n} catch (FlowableException e) {\n    log.error(\"LDAP bind failed: {}\", e.getMessage());\n    // fail fast or fall back to cached auth\n}","preventionTips":["Verify host/port with ldapsearch before configuring Flowable","Use a dedicated service account with a non-expiring password","For ldaps, import server certs into the JVM truststore","Set connect/read timeouts in the JNDI properties"],"tags":["flowable","ldap","directory-context","authentication","naming-exception"],"backgroundTag":"authentication-required","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}