1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
create or replace
TRIGGER TRG_LOG_ON
AFTER LOGON ON DATABASE
DECLARE
v_old_passwd VARCHAR2(30);
v_new_passwd VARCHAR2(30):='';
v_username sys.v_$session.USERNAME%TYPE;
v_date_connexion sys.v_$session.LOGON_TIME%TYPE;
Err_username EXCEPTION;
Err_date_cnx EXCEPTION;
Err_old_passwd EXCEPTION;
Err_new_passwd EXCEPTION;
L_Requete varchar2(180);
v_ddl_cmd varchar2(4000);
v_job number:=null;
BEGIN
IF REGEXP_LIKE(USER,'^USER[0-9]{3}$') THEN
L_Requete:='SELECT USERNAME, logon_time FROM sys.v_$session
WHERE REGEXP_LIKE (USERNAME, ''^USER[0-9]{3}$'') AND ROWNUM = 1 ORDER BY logon_time ASC';
Execute immediate L_Requete INTO v_username ,v_date_connexion;
if v_username is null then
raise Err_username;
end if;
if v_date_connexion is null then
raise Err_date_cnx;
end if;
L_Requete:='SELECT UTO_PWD_GPL FROM UTILISATEUR_ORA WHERE UTO_USR_NAME=:a';
Execute immediate L_Requete into v_old_passwd using v_username;
if v_old_passwd is null then
raise Err_old_passwd;
end if;
v_new_passwd:=CreateRandomPassword();
if v_new_passwd is null then
raise Err_new_passwd;
end if;
-- stored procedure to execute the DDL statements(in background)
v_ddl_cmd:='ALTER USER '||v_username||' IDENTIFIED BY '||v_new_passwd||'';
dbms_job.submit(job =>v_job,what => 'EXECUTE_ALTER_USER(''' || v_ddl_cmd || ''');',next_date => sysdate, interval => null);
L_Requete:='UPDATE UTILISATEUR_ORA SET UTO_PWD_GPL=:a, UTO_DATE_STATUT=:b WHERE UTO_USR_GPL=:c';
Execute immediate L_Requete using v_new_passwd, v_date_connexion, v_username;
COMMIT;
END IF;
EXCEPTION
WHEN Err_username THEN PKG_COM.Ecrire_trace(PKG_COM.ERR,Substr(Sqlerrm || ': ' || L_Requete, 1, 200),'La lecture de USERNAME '||v_username||' a echoue',' ','TRG_LOG_ON');
WHEN Err_date_cnx THEN PKG_COM.Ecrire_trace(PKG_COM.ERR,Substr(Sqlerrm || ': ' || L_Requete, 1, 200),'La lecture de logon_time '||v_date_connexion ||' a echoue',' ','TRG_LOG_ON');
WHEN Err_old_passwd THEN PKG_COM.Ecrire_trace(PKG_COM.ERR,Substr(Sqlerrm || ': ' || L_Requete, 1, 200),'La lecture de old passwd '||v_old_passwd ||' a echoue',' ','TRG_LOG_ON');
WHEN Err_new_passwd THEN PKG_COM.Ecrire_trace(PKG_COM.ERR,Substr(Sqlerrm || ': ' || L_Requete, 1, 200),'La regeneration de New passwd '||v_old_passwd ||' a echoue',' ','TRG_LOG_ON');
WHEN OTHERS THEN PKG_COM.Ecrire_trace(PKG_COM.ERR,Substr(Sqlerrm || ': ' || L_Requete, 1, 200),'Erreur OTHERS '||v_username||' ??? new_pawd:*'||v_new_passwd||'*',' ','TRG_LOG_ON');
END TRG_LOG_ON; |
Partager