1. 커스텀 인증 방식 생성
Name : CustomMyAuth
Scheme Type : Custom
Authentication Function Name : F_AUTHENTICATE_USER
2. 함수 생성
create or replace FUNCTION F_AUTHENTICATE_USER
(p_username in varchar2,
p_password in varchar2)
return boolean
is
l_user_name user_mst.login_id%type := upper(p_username);
l_password varchar2(255); --users.password%type;
l_hashed_password varchar2(1000);
l_count number;
begin
-- Returns from the AUTHENTICATE_USER function
-- 0 Normal, successful authentication
-- 1 Unknown User Name
-- 2 Account Locked
-- 3 Account Expired
-- 4 Incorrect Password
-- 5 Password First Use
-- 6 Maximum Login Attempts Exceeded
-- 7 Unknown Internal Error
--
-- First, check to see if the user exists
select count(*)
into l_count
from user_mst
where upper(login_id) = l_user_name
and use_yn = 'Y';
if l_count > 0 then
-- Hash the password provided
l_hashed_password := '1';--hash_password(l_user_name, p_password);
l_password := '1';
-- Get the stored password
/*
select password
into l_password
from users
where user_name = l_user_name; */
-- Compare the two, and if there is a match, return TRUE
if l_hashed_password = l_password then
-- Good result.
APEX_UTIL.SET_AUTHENTICATION_RESULT(0);
return true;
else
-- The Passwords didn't match
APEX_UTIL.SET_AUTHENTICATION_RESULT(4);
return false;
end if;
else
-- The username does not exist
APEX_UTIL.SET_AUTHENTICATION_RESULT(1);
return false;
end if;
-- If we get here then something weird happened.
APEX_UTIL.SET_AUTHENTICATION_RESULT(7);
return false;
exception
when others then
-- We don't know what happened so log an unknown internal error
APEX_UTIL.SET_AUTHENTICATION_RESULT(7);
-- And save the SQL Error Message to the Auth Status.
APEX_UTIL.SET_CUSTOM_AUTH_STATUS(sqlerrm);
return false;
end f_authenticate_user;
3. 커스텀 인증 방식을 현재 인증 방식으로 설정
* 주의 : 로그인 ID 가 로그인 테이블에 소문자로 저장되어 있어도 세션에 저장되는 :APP_USER 값은 대문자임.
참고.
https://blogs.oracle.com/apex/post/custom-authentication-and-authorization-using-built-in-apex-access-control-a-how-to