使用oracle DBMS_LDAP验证针对Microsoft Active Directory的用户凭据

psa*_*j12 3 oracle ldap oracle10g

我们正在尝试使用dbms_ldap针对Microsoft AD对我们的应用程序用户进行身份验证,我们无法在离岸环境中对其进行测试

我们有三个具体问题

1)如何验证用户是否存在于Microsoft Active Directory中

我们使用以下代码来获取Application用户的专有名称

DBMS_LDAP.USE_EXCEPTION := FALSE;
retval := DBMS_LDAP.search_s(ld       => ldapSession,
                           base     => LDAP_BASE,
                           scope    => DBMS_LDAP.SCOPE_SUBTREE,
                           filter   => '(&(objectclass=USER)(SAMAccountName=' ||
                                       p_username || '))',
                           attrs    => attrList,
                           attronly => 0,
                           res      => ldapMessage);
  -- get the DN
if retval <> DBMS_LDAP_UTL.SUCCESS THEN
RAISE l_ldap_exception;
END IF;
userDN := DBMS_LDAP.get_dn(ldapSession, ldapMessage);
Run Code Online (Sandbox Code Playgroud)

所以第一个问题是什么是价值

 userDN and ldapMessage
Run Code Online (Sandbox Code Playgroud)

如果用户不存在于Microsoft AD中

2)假设用户存在并且在这种情况下输入了错误的密码将是retval的返回值

if p_password is null then
raise_application_error(-20000, 'Invalid Null password');
else
retval := DBMS_LDAP.simple_bind_s(ldapSession,userDN, p_password);
end if;

if retval <> DBMS_LDAP_UTL.SUCCESS THEN
RAISE l_ldap_exception;
and if;
Run Code Online (Sandbox Code Playgroud)

3)我的第三个问题是假设用户已登录系统并且ldapsession仍然没有解除绑定识别重复会话的方式

Ant*_*yVO 5

警告警告警告

这不是一个答案,而是对使用以下代码验证用户的任何人的警告.

  retval := DBMS_LDAP.simple_bind_s(ldapSession, userDN, p_password);
Run Code Online (Sandbox Code Playgroud)

通过设计(LDAP设计),如果密码为空,则此函数调用将始终返回成功.这样做是为了允许匿名LDAP查询.这可能会在您的特定服务器上禁用,但并非总是如此.

因此,如果要使用此功能,请确保使用if块将其包装,以确保用户提供的密码不为空.例如

  if p_password is null then
    raise_application_error(-20000, 'Invalid Null password');
  else
    retval := DBMS_LDAP.simple_bind_s(ldapSession,userDN, p_password);
  end if;
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅:http://www.inside-oracle-apex.com/dbms_ldapsimple_bind_s-apex_ldapauthenticate-and-null-password/