DBMS_LDAP mit Anbindung an primären und sekundären Domain Controller (active directory)

Ein Pwd-Test gegen ein active directory (AD) - z.B. für eine APEX-Anwendung - kann in PL/SQL z.B. so aussehen:

excp_ldap EXCEPTION; -- LDAP-Fehler
PRAGMA EXCEPTION_INIT(excp_ldap, -31202);

LDAP_HOST VARCHAR2(512); -- The LDAP Directory Host
LDAP_PORT VARCHAR2(512); -- The LDAP Directory Port
RETVAL PLS_INTEGER; -- Used for all API return values.
MY_SESSION DBMS_LDAP.SESSION; -- Used to store our LDAP Session

begin

-- AD-Serverdaten
LDAP_HOST := c_LDAP_HOST;

log(c_Modul, 'versuche LDAP_HOST: ' || LDAP_HOST, P_LOG);

-- Test, ob User-Pwd ok
MY_SESSION := DBMS_LDAP.INIT(LDAP_HOST, null);
RETVAL := DBMS_LDAP.SIMPLE_BIND_S(MY_SESSION, P_USERNAME, P_PASSWORD);
RETVAL := DBMS_LDAP.UNBIND_S(MY_SESSION);
log(c_Modul, 'LDAP Bind mit Userame ' || P_USERNAME || ' erfolgreich', P_LOG);

return(true);

exception
when excp_ldap then
RETVAL := DBMS_LDAP.UNBIND_S(MY_SESSION);
log(c_Modul, 'LDAP-Fehler - Login für '||P_USERNAME||' verweigert', true);
return(false);
when others then
v_ErrCode := sqlcode;
v_ErrTxt := substr(sqlerrm,1,300);
log(c_Modul, 'FEHLER check_AD_Login '||v_ErrCode||' / '||v_ErrTxt, true);
return(false);


Ein entscheidender Call ist die Zeile
MY_SESSION := DBMS_LDAP.INIT(LDAP_HOST, LDAP_PORT);

Mit DBMS_LDAP.INIT wird die LDAP-Session initialisiert. Der Aufruf benötigt zwei Parameter: die Adresse und den Port des Domain Controllers (DC).

Sinnvollerweise werden jedoch mindestens ZWEI oder mehr DC eingesetzt, um möglichst vollständige Verfügbarkeit sicherzustellen.


Wie können nun mehrere DC angesprochen werden? (Bei Ausfall des primären DC soll automatisch der sekundäre DC verwendet werden.)
Dazu die Oracle-Doku:



hostnameContains a space-separated list of host names or dotted strings representing the IP address of hosts running an LDAP server to connect to. Each host name in the list may include a port number, which is separated from the host by a colon. The hosts are tried in the order listed, stopping with the first one to which a successful connection is made.
portnumContains the TCP port number to connect to. If the port number is included with the host name, this parameter is ignored. If the parameter is not specified, and the host name does not contain the port number, a default port number of 3060 is assumed.

Quelle: http://download.oracle.com/docs/cd/E14571_01/oid.1111/e10186/dbmsldap_ref.htm#i1014933

Der Parameter LDAP_HOST kann also mehrere Adressen inkl. Port-Angabe enthalten. Der zweite Parameter wird dann ignoriert. (Muss aber angegeben werden - siehe Bsp.)

In PL/SQL könnte das dann so aussehen:

LDAP_HOST VARCHAR2(512):= '192.168.1.101:389 192.168.1.121:389'
...
MY_SESSION := DBMS_LDAP.INIT(LDAP_HOST, null);


... dann klappts auch mit mehreren DCs

Kommentare

Beliebte Posts aus diesem Blog

PGA unter Oracle 11g

trunc(sysdate) - nette Spiele mit dem Datum

Datapump - Verzeichnis erstellen