Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ORA-31204: DBMS_LDAP: PL/SQL - Invalid LDAP Session.

Kimani SnyderDec 21 2016 — edited Jan 25 2017

Our Setup

APEX 5

ORACLE 12C

ORDS 3.0

Tomcat

I'm attempting to using LDAP authentication on an APEX page.

I have a pl/sql apex page with the following code:

declare

result_set BOOLEAN;

begin

result_set := apex_data.ldap_auth('myusername','mypassword');

if result_set THEN
  htp.p('success');
else
htp.p('Not successful');
end if;

end;

Here is the LDAP_AUTH code:

create or replace FUNCTION ldap_auth(
  p_username IN VARCHAR2,
  p_password IN VARCHAR2
)
RETURN BOOLEAN IS
  l_ldap_host     VARCHAR2(256) := 'myorg.net';
  l_ldap_port     VARCHAR2(256) := '389';
  l_dn_prefix     VARCHAR2(100) := 'cn='; -- Amend as desired'.
  l_dn_suffix     VARCHAR2(100) := ',OU=Users,OU=Hospital,DC=myorg,DC=net';

  l_retval        PLS_INTEGER;
  l_session       DBMS_LDAP.session;
BEGIN
  -- Choose to raise exceptions.
  DBMS_LDAP.use_exception := TRUE;

  -- Connect to the LDAP server.
  l_session := DBMS_LDAP.init(hostname => l_ldap_host,
                              portnum  => l_ldap_port);

  l_retval := DBMS_LDAP.simple_bind_s(ld     => l_session,
                                      dn     => l_dn_prefix||p_username||l_dn_suffix,
                                      passwd => p_password);

  -- No exceptions mean you are authenticated.
  RETURN TRUE;
EXCEPTION
  WHEN OTHERS THEN
    -- Exception means authentication failed.
    l_retval := DBMS_LDAP.unbind_s(ld => l_session);
    APEX_UTIL.set_custom_auth_status(p_status => 'Incorrect username and/or password');
    RETURN FALSE;   
END;

I had our DBA create an ACL with this code:

BEGIN

  DBMS_NETWORK_ACL_ADMIN.create_acl (

  
acl          =>
'ldap_acl_file.xml',

    description  => 'ACL to
grant access to LDAP server',

    principal    =>
'APEX_050000',

    is_grant     =>
TRUE,

    privilege    =>
'connect',

    start_date   =>
SYSTIMESTAMP,

    end_date     =>
NULL);

  DBMS_NETWORK_ACL_ADMIN.assign_acl (

  
acl         => 'ldap_acl_file.xml',

  
host        => 'myorg.net',

    lower_port  => 389,

    upper_port  => NULL);

  COMMIT;

END;

And grant access to the underlying schema using this code:

BEGIN

  DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(acl     
=> 'ldap_acl_file.xml',

                                     
principal => 'APEX_DATA',

                                     
is_grant  => true,

                                     
privilege => 'connect');

END;

/

COMMIT;

Stilling getting the error: ORA-31204: DBMS_LDAP: PL/SQL - Invalid LDAP Session.

Any ideas?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 22 2017
Added on Dec 21 2016
8 comments
9,618 views