Sunday, 17 August 2014

User requests should come from a particular IP (i.e. that of Middleware). Request coming from any other IP will not be entertained.

 Here is the trigger to  entertained only one IP.



CREATE OR REPLACE TRIGGER system.check_ip_addresses 
AFTER LOGON 
ON DATABASE
DECLARE 
  l_ip_address VARCHAR2(16) := SYS_CONTEXT('USERENV', 'IP_ADDRESS'); 
BEGIN 
  IF USER IN ('SCOTT') THEN
    IF l_ip_address = '1*2.3*.3*.00' THEN
      NULL;
    ELSE
      RAISE_APPLICATION_ERROR(-20000, 'Can not log in from this IP address (' || l_ip_address || ')');
    END IF;
  END IF;
END; 
/



SQL> CREATE OR REPLACE TRIGGER system.check_ip_addresses
  2  AFTER LOGON
  3  ON DATABASE
  4  DECLARE
  5    l_ip_address VARCHAR2(16) := SYS_CONTEXT('USERENV', 'IP_ADDRESS');
  6  BEGIN
  7    IF USER IN ('SCOTT') THEN
  8      IF l_ip_address = '172.31.36.50' THEN
  9        NULL;
 10      ELSE
 11        RAISE_APPLICATION_ERROR(-20000, 'Can not log in from this IP address
(' || l_ip_address || ')');
 12      END IF;
 13    END IF;
 14  END;
 15  /

Trigger created.

SQL> conn scott/tiger -- Here i've try to connect using 127.0.0.1 IP.
ERROR:
ORA-00604: error occurred at recursive SQL level 1
ORA-20000: Can not log in from this IP address ()
ORA-06512: at line 8

No comments:

  Oracle 21c Cluster Setup & DB Creation on OEL-8.4 using Virtual-box       Moto: This document is created on traditional way to Insta...