Im folgenden wird das DBMS_LDAP-Package genutzt um auf einen LDAP-Server anonym zuzugreifen und den Wert eines bestimmten Attributes zu lesen.
Konkret ist das hier die LDAP-ID (uidNumber) einer bestimmten Person (ufzperson).
Die ID der Person soll später als Primärschlüssel in einer Oracle-Tabelle genutzt werden.
DECLARE
l_ldap_host VARCHAR2(256) := 'hera.leipzig.ufz.de';
l_ldap_port VARCHAR2(256) := '389'; -- varchar?
l_ldap_base VARCHAR2(256) := 'dc=ufz,dc=de';
l_retval PLS_INTEGER;
l_session DBMS_LDAP.session;
l_attrs DBMS_LDAP.string_collection;
l_message DBMS_LDAP.message;
l_entry DBMS_LDAP.message;
l_vals DBMS_LDAP.string_collection;
BEGIN
l_session := DBMS_LDAP.init
(
hostname => l_ldap_host,
portnum => l_ldap_port
);
-- anonym anmelden
l_retval := DBMS_LDAP.simple_bind_s
(
ld => l_session,
dn => NULL,
passwd => NULL
);
-- Attribut welches gesucht wird
l_attrs(0) := 'uidNumber';
-- Suche ausführen
l_retval := DBMS_LDAP.search_s
(
ld => l_session,
base => l_ldap_base,
scope => DBMS_LDAP.SCOPE_SUBTREE,
filter => '(&(nsrole=*roleself*)(objectClass=ufzperson)(uid=dutzend))',
attrs => l_attrs,
attronly => 0,
res => l_message);
-- Wenn genau ein Eintrag gefunden wurde
IF DBMS_LDAP.count_entries(ld => l_session, msg => l_message) = 1
THEN
-- ersten Eintrag festlegen
l_entry := DBMS_LDAP.first_entry
(
ld => l_session,
msg => l_message
);
-- Wert des Eintrages holen
l_vals := DBMS_LDAP.get_values
(
ld => l_session,
ldapentry => l_entry,
attr => l_attrs(0)
);
END IF;
-- Attribut und Wert ausgeben
DBMS_OUTPUT.PUT_LINE(l_attrs(0) || ' = ' || l_vals(0));
-- Verbindung beenden
l_retval := DBMS_LDAP.unbind_s(ld => l_session);
END;
/
Keine Kommentare:
Kommentar veröffentlichen