Solved

Query LDAP via Oracle Pl/sql

Posted on 2010-11-20
4
2,199 Views
Last Modified: 2013-11-30
I want to query LDAP server via Pl/Sql code. I am able to connect to the LDAP server but having difficulty to search/retrieve LDAP attributes.

Attached is the code.

If I call the function with a valid input value for LDAP attribute "uid" it returns 1. Otherwise 0. When it returns 1 I want to search LDAP to get the value of the LDAP attribute "cn" corresponding to the input "uid" attribute.

How can I write the code?
CREATE OR REPLACE PACKAGE BODY TEST IS
 FUNCTION test (in_uid IN VARCHAR2) RETURN NUMBER AS
 retval           INTEGER;
 my_attr      VARCHAR2(256);
 my_str       VARCHAR2(256);
 my_session   DBMS_LDAP.session;
 my_attrs     DBMS_LDAP.string_collection;
 my_message   DBMS_LDAP.message;
 entry_index      PLS_INTEGER;
 ldap_host        VARCHAR2(256);
 ldap_port        VARCHAR2(256);
 ldap_user        VARCHAR2(256);
 ldap_passwd      VARCHAR2(256);
 ldap_base        VARCHAR2(256);

 BEGIN
 retval := -1;
 ldap_host  := 'server.myco.com';
 ldap_port  := '389';
 ldap_user  := '';
 ldap_passwd:= '';
 ldap_base  := 'ou=People, ou=Intranet, dc=XXX, dc=com';
 my_session := DBMS_LDAP.init(ldap_host, ldap_port);
 retval := DBMS_LDAP.simple_bind_s(my_session, '', '');
 my_attrs(1) := '*';
 my_attr := 'UID';
 my_str  := my_attr || '=' || TRIM(in_uid);
 retval := DBMS_LDAP.my_s(my_session, ldap_base, DBMS_LDAP.SCOPE_SUBTREE, my_str, my_attrs, 0, my_message);
 retval := DBMS_LDAP.count_entries(my_session, my_message);
 RETURN(retval);
 END;
END;

Open in new window

0
Comment
Question by:toooki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
ajexpert earned 500 total points
ID: 34182978


Do you think this link will help?

http://www.oracle-base.com/articles/9i/LDAPFromPLSQL9i.php

BTW I am not sure why are you overwriting the value of retval as
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 34182982
retval := DBMS_LDAP.my_s(my_session, ldap_base, DBMS_LDAP.SCOPE_SUBTREE, my_str, my_attrs, 0, my_message);

-- the above value will be overwritten with --
retval := DBMS_LDAP.count_entries(my_session, my_message);

Open in new window

0
 

Author Comment

by:toooki
ID: 34279454
retval := DBMS_LDAP.count_entries(my_session, my_message);

the above is optional.
0
 

Author Comment

by:toooki
ID: 34634259
It works somehow now.
Thank you.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

At the beginning of the year, the IT world was taken hostage by the shareholders of LogMeIn. Their free product, which had been free for ten years, all of the sudden became a "pay" product. Now, I am the first person who will say that software maker…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question