Wallet / ACL / Network Access

From dbawiki
Revision as of 08:50, 23 May 2017 by Stuart (talk | contribs)
Jump to: navigation, search

Nice, clear example found on AskTOM

Create a wallet

mkdir /home/oracle/wallet
orapki wallet create -wallet /home/oracle/wallet -pwd MyWallePassword999 -auto_login
orapki wallet add    -wallet /home/oracle/wallet -trusted_cert -cert /tmp/cert1.cer -pwd MyWallePassword999
orapki wallet add    -wallet /home/oracle/wallet -trusted_cert -cert /tmp/cert2.cer -pwd MyWallePassword999
orapki wallet add    -wallet /home/oracle/wallet -trusted_cert -cert /tmp/cert3.cer -pwd MyWallePassword999

Create an ACL

begin
    dbms_network_acl_admin.create_acl ( acl          => 'utl_http.xml'
                                      , description  => 'my acl'
                                      , principal    => 'MCDONAC'
                                      , is_grant     => TRUE
                                      , privilege    => 'connect'
                                      , start_date   => null
                                      , end_date     => null
                                      );
    commit;
end;
/

Add privilege to ACL

begin
    dbms_network_acl_admin.add_privilege ( acl         => 'utl_http.xml'
                                         , principal   => 'MCDONAC'
                                         , is_grant    => false
                                         , privilege   => 'connect'
                                         , position    => null
                                         , start_date  => null
                                         , end_date    => null
                                         );

    commit;
end;
/

Open the wallet and use UTL_HTTP to retrieve a web page

set serverout on
declare
    l_url            varchar2(100) := 'https://www.litle.com/';
    l_req            utl_http.req;
    l_result         utl_http.resp;
    l_data           varchar2(32767);
begin
    utl_http.set_wallet('file:/home/oracle/wallet', 'MyWallePassword999');
    l_req    := utl_http.begin_request(l_url);
    l_result := utl_http.get_response(l_req);

    begin
        loop
            utl_http.read_text(l_result, l_data, 1000);
            dbms_output.put_line (l_data);
        end loop;
    exception
    when utl_http.end_of_body then
        utl_http.end_response(l_result);
    end;
end;
/