Introduction: –
This document will be helpful to verify users from LDAP directory. I had a situation to users is exists in LDAP Directory or not then I need to do .
The following technologies has been used to achieve the same.
- Oracle APEX
- PL/SQL
Why we need to do: –
I had a situation to users is exists in LDAP Directory or not then I need to do.
How do we solve:
Step:1 – Create an Function.
Code: Create function using below code
create or replace function user validation(p_username IN varchar2, P_userpass IN varchar2)
return number as
L_LDAP_SESSION DBMS_LDAP.SESSION;
L_HOST VARCHAR2(100) :=xxx.com’ ;
L_PORT NUMBER := 389;
L_DN VARCHAR2 (300);
L_RESULT NUMBER;
Begin
L_DN := ‘xxxdomain)’ || p_username;
L_LDAP_SESSION := DBMS_LDAP. INIT (L_HOST, L_PORT) ;
L_RESULT := DBMS_LDAP.SIMPLE_BIND_S(L_LDAP_SESSION, L_DN, P_userpass) ;
RETURN L_RESULT;
END;
Step:2 – Then go to login page and call this function through Process or Function.
declare
begin
IF : P9999_USERNAME IS NULL THEN
RAISE_APPLICATION ERROR(-20001, ‘Please enter Username’):
apex_error .add_error (
P_message => ‘Please enter Username’
p_display_location => apex_error.C_inline_in_notification
ELSIF : P9999_PASSWORD IS NULL THEN
RAISE_APPLICATION ERROR(-20001, ‘Please enter Password’);
apex_error. add_error (
P_message => ‘Please enter Password’,
P_display_location => apex_error.c_inline_in_notification
);
ELSIF
user_validation (: P9999_USERNAME, :P9999_PASSWORD) != 1 then
apex_error. add_error (
p_message → ‘INVALID USER OR PASSWORD’,
P_display_location → apex_error.c_inline_in_notification
BEGIN
L_RESULT : =DBMS_LDAP.SIMPLE_BIND_S(L_LDAP_SESSION, L_DN, : P9999_PASSWORD);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
Raise_application_error(-20001, ‘LDAP Authentication failerd:’ || SQLERRM );
–error_messag := ‘LDAP Authentication failerd:’ || SQLERRM;
END;
DBMS_LDAP. UNBIND(L_LDAP_SESSION) ;
END IF;
APEX_APPLICATION.G_PRINT_SUCCESS_MESSAGE := ‘User exist in LDAP Directory!’;
end;
Step:3 – Create a Dynamic Action on the Global Page
Go to the Global Page and create a Dynamic Action with the event set to Page Load.
Add a JavaScript True Action and paste the following code:
var validPageIds = [“1”, “3”];
var currentPageId = apex.item(‘P0_PAGE_ID’).getValue();
if (validPageIds.includes(currentPageId)) {
apex.message.setDismissPreferences({
dismissPageSuccess: true,
dismissPageSuccessDuration: 10000 // Success message stays for 10 seconds
});
} else {
apex.message.setDismissPreferences({
dismissPageSuccess: true,
dismissPageSuccessDuration: 2000 // Success message stays for 2 seconds
});
}
Screen Shot
Conclusion:
Implementing verify users from LDAP directory in Oracle APEX is a simple yet effective way to to verify the user is avilable or not in the ldap directory.