Overview
Basically, Oracle LDAP requires OID to connect LDAP using java, So we need some prerequisites, follow the below setup.
ORACLE SERVER or ORACLE LDAP SERVER [ if you have already an oracle server, just follow this link and set up the LDAP server in the oracle server]
After following those steps you might get this kind of error, while you trying with java code or third-party tool.
x
Caused by: oracle.net.ns.NetException: JNDI Package failure javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'cn=oracle-context,dc=test,dc=com'
Cause :
It's searching for the available object in the LDAP directory tree, but it's not available, so we might check the correct object name. if it's any typo or checks and provide the right object name.
I debugged the Oracle driver and saw orclNetDescString is empty, That's why the Oracle LDAP connection is not connected. So it requires some OID schema.
Solution :
Download the LDIF files that I mentioned below, those files help to connect to Oracle LDAP authentication.
Create a folder and copy LDIF files in that location
- oidbase.ldif
- oidnet.ldif
- oidrdbms.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/oracle-ldap/oidnet.ldif
Create the /etc/openldap/testdb.ldif file and paste the below lines
ldapadd -x -W -D "cn=Manager,dc=test,dc=com" -f testdb.ldif
Note: If you don't have the ldap.ora file, then create a new ldap.ora file under this $ORACLE_HOME/network/admin/ldap.ora
Finally, make the LDAP JDBC URI connect to oracle
jdbc:oracle:thin:@ldap://<Hostname or IP>:389/cn=testdb,dc=test,dc=com
Oracle LDAP authentication code example
package testdb.oracle.jdbc;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Properties;public class LDAPConn {public static void main(String[] args) throws SQLException {String url = "jdbc:oracle:thin:@ldap://<ip or hostname>:389/cn=testdb,dc=test,dc=com";Properties props = new Properties();props.setProperty("user", "testuser");props.setProperty("password", "ldappassword");DriverManager.registerDriver(new oracle.jdbc.OracleDriver());Connection conn = DriverManager.getConnection(url, props);if(!conn.isClosed()){System.out.println("<<<< LDAP auth connected successfully >>>>");}ResultSet res = conn.prepareCall("select 'Hello LDAP sirthik World' txt from dual").executeQuery();res.next();System.out.println(res.getString("TXT"));}}
Output
Social Plugin