Oracle REST Data Services (ORDS) : Authentication
This article gives a quick run through the authentication options available with Oracle REST Data Services (ORDS).
oracle miscconfigurationintermediate
by OracleDba
39 views
This article gives a quick run through the authentication options available with Oracle REST Data Services (ORDS).
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
ords --config /u01/config/ords config set security.verifySSL false
<entry key="security.verifySSL">false</entry>
$CATALINA_HOME/bin/shutdown.sh
$CATALINA_HOME/bin/startup.sh
conn / as sysdba
alter session set container=pdb1;
drop user testuser1 cascade;
create user testuser1 identified by testuser1
default tablespace users quota unlimited on users;
grant create session, create table to testuser1;
conn testuser1/testuser1@pdb1
create table emp (
empno number(4,0),
ename varchar2(10 byte),
job varchar2(9 byte),
mgr number(4,0),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2,0),
constraint pk_emp primary key (empno)
);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7369,'SMITH','CLERK',7902,to_date('17-DEC-80','DD-MON-RR'),800,null,20);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7499,'ALLEN','SALESMAN',7698,to_date('20-FEB-81','DD-MON-RR'),1600,300,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7521,'WARD','SALESMAN',7698,to_date('22-FEB-81','DD-MON-RR'),1250,500,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7566,'JONES','MANAGER',7839,to_date('02-APR-81','DD-MON-RR'),2975,null,20);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7654,'MARTIN','SALESMAN',7698,to_date('28-SEP-81','DD-MON-RR'),1250,1400,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7698,'BLAKE','MANAGER',7839,to_date('01-MAY-81','DD-MON-RR'),2850,null,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7782,'CLARK','MANAGER',7839,to_date('09-JUN-81','DD-MON-RR'),2450,null,10);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7788,'SCOTT','ANALYST',7566,to_date('19-APR-87','DD-MON-RR'),3000,null,20);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7839,'KING','PRESIDENT',null,to_date('17-NOV-81','DD-MON-RR'),5000,null,10);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7844,'TURNER','SALESMAN',7698,to_date('08-SEP-81','DD-MON-RR'),1500,0,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7876,'ADAMS','CLERK',7788,to_date('23-MAY-87','DD-MON-RR'),1100,null,20);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7900,'JAMES','CLERK',7698,to_date('03-DEC-81','DD-MON-RR'),950,null,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7902,'FORD','ANALYST',7566,to_date('03-DEC-81','DD-MON-RR'),3000,null,20);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7934,'MILLER','CLERK',7782,to_date('23-JAN-82','DD-MON-RR'),1300,null,10);
commit;
conn testuser1/testuser1@pdb1
begin
ords.enable_schema(
p_enabled => true,
p_schema => 'TESTUSER1',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'hr',
p_auto_rest_auth => false
);
commit;
end;
/
conn testuser1/testuser1@pdb1
begin
ords.enable_object (
p_enabled => true, -- Default { true | false }
p_schema => 'TESTUSER1',
p_object => 'EMP',
p_object_type => 'TABLE', -- Default { table | view }
p_object_alias => 'employees'
);
commit;
end;
/
http://localhost:8080/ords/hr/employees/7788
https://localhost:8443/ords/hr/employees/7788
$
curl -i -k https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: "jtC17IXyetESUjSkxB2ani/a1TnFh28yfor+fLmxxUzGr6G9IFxQ77+/Gd71W4Qzz0rSxf90Qqbl+ICwezTayQ=="
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 08:35:50 GMT
{"items":[{"empno":7788,"ename":"SCOTT","job":"ANALYST","mgr":7566,"hiredate":"1987-04-18T23:00:00Z","sal":3003,
"comm":null,"deptno":20}],"hasMore":false,"limit":0,"offset":0,"count":1,"links":[{"rel":"self",
"href":"https://localhost:8443/ords/hr/employees/7788"},{"rel":"describedby",
"href":"https://localhost:8443/ords/hr/metadata-catalog/employees/item"}]}
$
conn testuser1/testuser1@pdb1
begin
ords.create_role(
p_role_name => 'emp_role'
);
commit;
end;
/
-- Display the role.
column name format a20
select id, name
from user_ords_roles
where name = 'emp_role';
ID NAME
---------- --------------------
10312 emp_role
SQL>
conn testuser1/testuser1@pdb1
declare
l_roles_arr owa.vc_arr;
l_patterns_arr owa.vc_arr;
begin
l_roles_arr(1) := 'emp_role';
l_patterns_arr(1) := '/employees/*';
ords.define_privilege (
p_privilege_name => 'emp_priv',
p_roles => l_roles_arr,
p_patterns => l_patterns_arr,
p_label => 'EMP Data',
p_description => 'Allow access to the EMP data.'
);
commit;
end;
/
-- Display the privilege information.
column name format a20
select id, name
from user_ords_privileges
where name = 'emp_priv';
ID NAME
---------- --------------------
10313 emp_priv
SQL>
-- Display the privilege-role relationship.
column privilege_name format a20
column role_name format a20
select privilege_id, privilege_name, role_id, role_name
from user_ords_privilege_roles
where role_name = 'emp_role';
PRIVILEGE_ID PRIVILEGE_NAME ROLE_ID ROLE_NAME
------------ -------------------- ---------- --------------------
10313 emp_priv 10312 emp_role
SQL>
-- Display the mapping information.
column name format a20
column pattern format a20
select privilege_id, name, pattern
from user_ords_privilege_mappings
where name = 'emp_priv';
PRIVILEGE_ID NAME PATTERN
------------ -------------------- --------------------
10246 emp_priv /employees/*
SQL>
begin
ords.create_privilege(
p_name => 'emp_priv',
p_role_name => 'emp_role',
p_label => 'EMP Data',
p_description => 'Allow access to the EMP data.');
ords.create_privilege_mapping(
p_privilege_name => 'emp_priv',
p_pattern => '/employees/*');
commit;
end;
/
$
curl -i -k https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
Content-Type: text/html
Content-Length: 11577
Date: Wed, 29 Jun 2016 08:45:32 GMT
.
. Edited out for brevity.
.
$
conn testuser1/testuser1@pdb1
declare
l_roles_arr owa.vc_arr;
l_patterns_arr owa.vc_arr;
l_modules_arr owa.vc_arr;
begin
l_roles_arr(1) := 'emp_role';
l_modules_arr(1) := 'my_modules';
ords.define_privilege (
p_privilege_name => 'emp_priv',
p_roles => l_roles_arr,
p_patterns => l_patterns_arr,
p_modules => l_modules_arr,
p_label => 'My Module',
p_description => 'Allow access to My Module.'
);
commit;
end;
/
$
cd /u01/ords
$
$JAVA_HOME/bin/java -jar ords.war user emp_user emp_role
Enter a password for user emp_user:
Confirm password for user emp_user:
Jun 29, 2016 11:52:42 AM oracle.dbtools.standalone.ModifyUser execute
INFO: Created user: emp_user in file: /u01/ords/conf/ords/credentials
$
https://localhost:8443/ords/hr/employees/7788
$
curl -i -k --user emp_user:Password1 https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: "jtC17IXyetESUjSkxB2ani/a1TnFh28yfor+fLmxxUzGr6G9IFxQ77+/Gd71W4Qzz0rSxf90Qqbl+ICwezTayQ=="
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sat, 02 Jul 2016 06:19:47 GMT
{"items":[{"empno":7788,"ename":"SCOTT","job":"ANALYST","mgr":7566,"hiredate":"1987-04-18T23:00:00Z","sal":3003,
"comm":null,"deptno":20}],"hasMore":false,"limit":0,"offset":0,"count":1,"links":[{"rel":"self",
"href":"https://localhost:8443/ords/hr/employees/7788"},{"rel":"describedby",
"href":"https://localhost:8443/ords/hr/metadata-catalog/employees/item"}]}
$
<role rolename="emp_role"/>
<user username="emp_user" password="Password1" roles="emp_role"/>
$CATALINA_HOME/bin/shutdown.sh
$CATALINA_HOME/bin/startup.sh
conn testuser1/testuser1@pdb1
begin
oauth.create_client(
p_name => 'emp_client',
p_grant_type => 'client_credentials',
p_owner => 'My Company Limited',
p_description => 'A client for Emp management',
p_support_email => '[email protected]',
p_privilege_names => 'emp_priv'
);
commit;
end;
/
-- Display client details.
column name format a20
select id, name, client_id, client_secret
from user_ords_clients;
ID NAME CLIENT_ID CLIENT_SECRET
---------- -------------------- -------------------------------- --------------------------------
10316 emp_client 3NvJRo_a0UwGKx7Q-kivtA.. F5WVwyrWxXj3ykmhSONldQ..
SQL>
-- Display client-privilege relationship.
select name, client_name
from user_ords_client_privileges;
NAME CLIENT_NAME
-------------------- ------------------------------
emp_priv emp_client
SQL>
begin
oauth.grant_client_role(
p_client_name => 'emp_client',
p_role_name => 'emp_role'
);
commit;
end;
/
-- Display client-role relationship.
column client_name format a30
column role_name format a20
select client_name, role_name
from user_ords_client_roles;
CLIENT_NAME ROLE_NAME
------------------------------ --------------------
emp_client emp_role
SQL>
CLIENT_ID : 3NvJRo_a0UwGKx7Q-kivtA..
CLIENT_SECRET : F5WVwyrWxXj3ykmhSONldQ..
OAUTH URL : https://localhost:8443/ords/hr/oauth/token
$
curl -i -k --user 3NvJRo_a0UwGKx7Q-kivtA..:F5WVwyrWxXj3ykmhSONldQ.. --data "grant_type=client_credentials" https://localhost:8443/ords/hr/oauth/token
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 12:07:02 GMT
{"access_token":"
-zYl-sFyB2iLicAHw2TsRA..
","token_type":"bearer","expires_in":3600}
$
$
curl -i -k -H"Authorization: Bearer -zYl-sFyB2iLicAHw2TsRA.." https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: "jtC17IXyetESUjSkxB2ani/a1TnFh28yfor+fLmxxUzGr6G9IFxQ77+/Gd71W4Qzz0rSxf90Qqbl+ICwezTayQ=="
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 12:07:31 GMT
{"items":[{"empno":7788,"ename":"SCOTT","job":"ANALYST","mgr":7566,"hiredate":"1987-04-18T23:00:00Z","sal":3003,
"comm":null,"deptno":20}],"hasMore":false,"limit":0,"offset":0,"count":1,"links":[{"rel":"self",
"href":"https://localhost:8443/ords/hr/employees/7788"},{"rel":"describedby",
"href":"https://localhost:8443/ords/hr/metadata-catalog/employees/item"}]}
$
Conn testuser1/testuser1@pdb1
begin
oauth.create_client(
p_name => 'emp_client',
p_grant_type => 'authorization_code',
p_owner => 'My Company Limited',
p_description => 'A client for Emp management',
p_redirect_uri => 'https://localhost:8443/ords/hr/redirect',
p_support_email => '[email protected]',
p_support_uri => 'https://localhost:8443/ords/hr/support',
p_privilege_names => 'emp_priv'
);
commit;
end;
/
-- Display client details.
column name format a20
select id, name, client_id, client_secret
from user_ords_clients;
ID NAME CLIENT_ID CLIENT_SECRET
---------- -------------------- -------------------------------- --------------------------------
10333 emp_client gxqNSyxPbLUJhSj1yBe8qA.. E-_mKJBlOTfTdHc_zISniA..
SQL>
CLIENT_ID : gxqNSyxPbLUJhSj1yBe8qA..
State : 3668D7A713E93372E0406A38A8C02171
URL : https://localhost:8443/ords/hr/oauth/auth?response_type=code&client_id={client_id}&state={state}
https://localhost:8443/ords/hr/oauth/auth?response_type=code&client_id=
gxqNSyxPbLUJhSj1yBe8qA..
&state=
3668D7A713E93372E0406A38A8C02171
https://localhost:8443/ords/hr/redirect?code=
FF-APuIMukuBlrver1XU2A..
&state=3668D7A713E93372E0406A38A8C02171
CLIENT_ID : gxqNSyxPbLUJhSj1yBe8qA..
CLIENT_SECRET : E-_mKJBlOTfTdHc_zISniA..
User : CLIENT_ID:CLIENT_SECRET
Data : grant_type=authorization_code&code={authorization-code}
URL : https://localhost:8443/ords/hr/oauth/token
$
curl -i -k --user gxqNSyxPbLUJhSj1yBe8qA..:E-_mKJBlOTfTdHc_zISniA.. --data "grant_type=authorization_code&code=FF-APuIMukuBlrver1XU2A.." https://localhost:8443/ords/hr/oauth/token
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 12:38:52 GMT
{"access_token":"
cOYb2hFK_SyxOh8o9n6R7A..
","token_type":"bearer","expires_in":3600,"refresh_token":"RC33rvSwAfhguraOWlvgfA.."}
$
$
curl -i -k -H"Authorization: Bearer cOYb2hFK_SyxOh8o9n6R7A.." https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: "jtC17IXyetESUjSkxB2ani/a1TnFh28yfor+fLmxxUzGr6G9IFxQ77+/Gd71W4Qzz0rSxf90Qqbl+ICwezTayQ=="
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 12:40:34 GMT
{"items":[{"empno":7788,"ename":"SCOTT","job":"ANALYST","mgr":7566,"hiredate":"1987-04-18T23:00:00Z","sal":3003,
"comm":null,"deptno":20}],"hasMore":false,"limit":0,"offset":0,"count":1,"links":[{"rel":"self",
"href":"https://localhost:8443/ords/hr/employees/7788"},{"rel":"describedby",
"href":"https://localhost:8443/ords/hr/metadata-catalog/employees/item"}]}
$
conn testuser1/testuser1@pdb1
begin
oauth.create_client(
p_name => 'emp_client',
p_grant_type => 'implicit',
p_owner => 'My Company Limited',
p_description => 'A client for Emp management',
p_redirect_uri => 'https://localhost:8443/ords/hr/redirect',
p_support_email => '[email protected]',
p_support_uri => 'https://localhost:8443/ords/hr/support',
p_privilege_names => 'emp_priv'
);
commit;
end;
/
-- Display client details.
column name format a20
select id, name, client_id, client_secret
from user_ords_clients;
ID NAME CLIENT_ID CLIENT_SECRET
---------- -------------------- -------------------------------- --------------------------------
10325 emp_client 0docHbkL8__7Ic58n7GCBA..
SQL>
CLIENT_ID : 0docHbkL8__7Ic58n7GCBA..
State : 3668D7A713E93372E0406A38A8C02171
URL : https://localhost:8443/ords/hr/oauth/auth?response_type=code&client_id={client_id}&state={random-string}
https://localhost:8443/ords/hr/oauth/auth?response_type=token&client_id=
0docHbkL8__7Ic58n7GCBA..
&state=
3668D7A713E93372E0406A38A8C02171
https://localhost:8443/ords/hr/redirect#token_type=bearer&access_token=
5SVR_NVP5N_OnDQt6iSxJg..
&expires_in=3600&state=3668D7A713E93372E0406A38A8C02171
$
curl -i -k -H"Authorization: Bearer 5SVR_NVP5N_OnDQt6iSxJg.." https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: "jtC17IXyetESUjSkxB2ani/a1TnFh28yfor+fLmxxUzGr6G9IFxQ77+/Gd71W4Qzz0rSxf90Qqbl+ICwezTayQ=="
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 12:15:35 GMT
{"items":[{"empno":7788,"ename":"SCOTT","job":"ANALYST","mgr":7566,"hiredate":"1987-04-18T23:00:00Z","sal":3003,
"comm":null,"deptno":20}],"hasMore":false,"limit":0,"offset":0,"count":1,"links":[{"rel":"self",
"href":"https://localhost:8443/ords/hr/employees/7788"},{"rel":"describedby",
"href":"https://localhost:8443/ords/hr/metadata-catalog/employees/item"}]}
$
begin
oauth.revoke_client_role(
p_client_name => 'emp_client',
p_role_name => 'emp_role'
);
commit;
end;
/
begin
oauth.delete_client(
p_name => 'emp_client'
);
commit;
end;
/
begin
ords.delete_privilege_mapping(
p_privilege_name => 'emp_priv',
p_pattern => '/employees/*'
);
commit;
end;
/
begin
ords.delete_privilege (
p_name => 'emp_priv'
);
commit;
end;
/
begin
ords.delete_role(
p_role_name => 'emp_role'
);
commit;
end;
/1234567891011121314151617181920212223242526272829303132333435363738
conn / as sysdba
alter session set container=pdb1;
drop user testuser1 cascade;
create user testuser1 identified by testuser1
default tablespace users quota unlimited on users;
grant create session, create table to testuser1;
conn testuser1/testuser1@pdb1
create table emp (
empno number(4,0),
ename varchar2(10 byte),
job varchar2(9 byte),
mgr number(4,0),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2,0),
constraint pk_emp primary key (empno)
);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7369,'SMITH','CLERK',7902,to_date('17-DEC-80','DD-MON-RR'),800,null,20);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7499,'ALLEN','SALESMAN',7698,to_date('20-FEB-81','DD-MON-RR'),1600,300,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7521,'WARD','SALESMAN',7698,to_date('22-FEB-81','DD-MON-RR'),1250,500,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7566,'JONES','MANAGER',7839,to_date('02-APR-81','DD-MON-RR'),2975,null,20);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7654,'MARTIN','SALESMAN',7698,to_date('28-SEP-81','DD-MON-RR'),1250,1400,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7698,'BLAKE','MANAGER',7839,to_date('01-MAY-81','DD-MON-RR'),2850,null,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7782,'CLARK','MANAGER',7839,to_date('09-JUN-81','DD-MON-RR'),2450,null,10);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7788,'SCOTT','ANALYST',7566,to_date('19-APR-87','DD-MON-RR'),3000,null,20);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7839,'KING','PRESIDENT',null,to_date('17-NOV-81','DD-MON-RR'),5000,null,10);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7844,'TURNER','SALESMAN',7698,to_date('08-SEP-81','DD-MON-RR'),1500,0,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7876,'ADAMS','CLERK',7788,to_date('23-MAY-87','DD-MON-RR'),1100,null,20);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7900,'JAMES','CLERK',7698,to_date('03-DEC-81','DD-MON-RR'),950,null,30);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7902,'FORD','ANALYST',7566,to_date('03-DEC-81','DD-MON-RR'),3000,null,20);
insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (7934,'MILLER','CLERK',7782,to_date('23-JAN-82','DD-MON-RR'),1300,null,10);
commit;1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
conn testuser1/testuser1@pdb1
begin
ords.enable_schema(
p_enabled => true,
p_schema => 'TESTUSER1',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'hr',
p_auto_rest_auth => false
);
commit;
end;
/
conn testuser1/testuser1@pdb1
begin
ords.enable_object (
p_enabled => true, -- Default { true | false }
p_schema => 'TESTUSER1',
p_object => 'EMP',
p_object_type => 'TABLE', -- Default { table | view }
p_object_alias => 'employees'
);
commit;
end;
/
http://localhost:8080/ords/hr/employees/7788
https://localhost:8443/ords/hr/employees/7788
$
curl -i -k https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: "jtC17IXyetESUjSkxB2ani/a1TnFh28yfor+fLmxxUzGr6G9IFxQ77+/Gd71W4Qzz0rSxf90Qqbl+ICwezTayQ=="
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 08:35:50 GMT
{"items":[{"empno":7788,"ename":"SCOTT","job":"ANALYST","mgr":7566,"hiredate":"1987-04-18T23:00:00Z","sal":3003,
"comm":null,"deptno":20}],"hasMore":false,"limit":0,"offset":0,"count":1,"links":[{"rel":"self",
"href":"https://localhost:8443/ords/hr/employees/7788"},{"rel":"describedby",
"href":"https://localhost:8443/ords/hr/metadata-catalog/employees/item"}]}
$123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
conn testuser1/testuser1@pdb1
begin
ords.create_role(
p_role_name => 'emp_role'
);
commit;
end;
/
-- Display the role.
column name format a20
select id, name
from user_ords_roles
where name = 'emp_role';
ID NAME
---------- --------------------
10312 emp_role
SQL>
conn testuser1/testuser1@pdb1
declare
l_roles_arr owa.vc_arr;
l_patterns_arr owa.vc_arr;
begin
l_roles_arr(1) := 'emp_role';
l_patterns_arr(1) := '/employees/*';
ords.define_privilege (
p_privilege_name => 'emp_priv',
p_roles => l_roles_arr,
p_patterns => l_patterns_arr,
p_label => 'EMP Data',
p_description => 'Allow access to the EMP data.'
);
commit;
end;
/
-- Display the privilege information.
column name format a20
select id, name
from user_ords_privileges
where name = 'emp_priv';
ID NAME
---------- --------------------
10313 emp_priv
SQL>
-- Display the privilege-role relationship.
column privilege_name format a20
column role_name format a20
select privilege_id, privilege_name, role_id, role_name
from user_ords_privilege_roles
where role_name = 'emp_role';
PRIVILEGE_ID PRIVILEGE_NAME ROLE_ID ROLE_NAME
------------ -------------------- ---------- --------------------
10313 emp_priv 10312 emp_role
SQL>
-- Display the mapping information.
column name format a20
column pattern format a20
select privilege_id, name, pattern
from user_ords_privilege_mappings
where name = 'emp_priv';
PRIVILEGE_ID NAME PATTERN
------------ -------------------- --------------------
10246 emp_priv /employees/*
SQL>
begin
ords.create_privilege(
p_name => 'emp_priv',
p_role_name => 'emp_role',
p_label => 'EMP Data',
p_description => 'Allow access to the EMP data.');
ords.create_privilege_mapping(
p_privilege_name => 'emp_priv',
p_pattern => '/employees/*');
commit;
end;
/
$
curl -i -k https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
Content-Type: text/html
Content-Length: 11577
Date: Wed, 29 Jun 2016 08:45:32 GMT
.
. Edited out for brevity.
.
$
conn testuser1/testuser1@pdb1
declare
l_roles_arr owa.vc_arr;
l_patterns_arr owa.vc_arr;
l_modules_arr owa.vc_arr;
begin
l_roles_arr(1) := 'emp_role';
l_modules_arr(1) := 'my_modules';
ords.define_privilege (
p_privilege_name => 'emp_priv',
p_roles => l_roles_arr,
p_patterns => l_patterns_arr,
p_modules => l_modules_arr,
p_label => 'My Module',
p_description => 'Allow access to My Module.'
);
commit;
end;
/1234567891011121314151617181920212223242526
$
cd /u01/ords
$
$JAVA_HOME/bin/java -jar ords.war user emp_user emp_role
Enter a password for user emp_user:
Confirm password for user emp_user:
Jun 29, 2016 11:52:42 AM oracle.dbtools.standalone.ModifyUser execute
INFO: Created user: emp_user in file: /u01/ords/conf/ords/credentials
$
https://localhost:8443/ords/hr/employees/7788
$
curl -i -k --user emp_user:Password1 https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: "jtC17IXyetESUjSkxB2ani/a1TnFh28yfor+fLmxxUzGr6G9IFxQ77+/Gd71W4Qzz0rSxf90Qqbl+ICwezTayQ=="
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sat, 02 Jul 2016 06:19:47 GMT
{"items":[{"empno":7788,"ename":"SCOTT","job":"ANALYST","mgr":7566,"hiredate":"1987-04-18T23:00:00Z","sal":3003,
"comm":null,"deptno":20}],"hasMore":false,"limit":0,"offset":0,"count":1,"links":[{"rel":"self",
"href":"https://localhost:8443/ords/hr/employees/7788"},{"rel":"describedby",
"href":"https://localhost:8443/ords/hr/metadata-catalog/employees/item"}]}
$12345
<role rolename="emp_role"/>
<user username="emp_user" password="Password1" roles="emp_role"/>
$CATALINA_HOME/bin/shutdown.sh
$CATALINA_HOME/bin/startup.sh1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
conn testuser1/testuser1@pdb1
begin
oauth.create_client(
p_name => 'emp_client',
p_grant_type => 'client_credentials',
p_owner => 'My Company Limited',
p_description => 'A client for Emp management',
p_support_email => '[email protected]',
p_privilege_names => 'emp_priv'
);
commit;
end;
/
-- Display client details.
column name format a20
select id, name, client_id, client_secret
from user_ords_clients;
ID NAME CLIENT_ID CLIENT_SECRET
---------- -------------------- -------------------------------- --------------------------------
10316 emp_client 3NvJRo_a0UwGKx7Q-kivtA.. F5WVwyrWxXj3ykmhSONldQ..
SQL>
-- Display client-privilege relationship.
select name, client_name
from user_ords_client_privileges;
NAME CLIENT_NAME
-------------------- ------------------------------
emp_priv emp_client
SQL>
begin
oauth.grant_client_role(
p_client_name => 'emp_client',
p_role_name => 'emp_role'
);
commit;
end;
/
-- Display client-role relationship.
column client_name format a30
column role_name format a20
select client_name, role_name
from user_ords_client_roles;
CLIENT_NAME ROLE_NAME
------------------------------ --------------------
emp_client emp_role
SQL>
CLIENT_ID : 3NvJRo_a0UwGKx7Q-kivtA..
CLIENT_SECRET : F5WVwyrWxXj3ykmhSONldQ..
OAUTH URL : https://localhost:8443/ords/hr/oauth/token
$
curl -i -k --user 3NvJRo_a0UwGKx7Q-kivtA..:F5WVwyrWxXj3ykmhSONldQ.. --data "grant_type=client_credentials" https://localhost:8443/ords/hr/oauth/token
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 12:07:02 GMT
{"access_token":"
-zYl-sFyB2iLicAHw2TsRA..
","token_type":"bearer","expires_in":3600}
$
$
curl -i -k -H"Authorization: Bearer -zYl-sFyB2iLicAHw2TsRA.." https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: "jtC17IXyetESUjSkxB2ani/a1TnFh28yfor+fLmxxUzGr6G9IFxQ77+/Gd71W4Qzz0rSxf90Qqbl+ICwezTayQ=="
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 12:07:31 GMT
{"items":[{"empno":7788,"ename":"SCOTT","job":"ANALYST","mgr":7566,"hiredate":"1987-04-18T23:00:00Z","sal":3003,
"comm":null,"deptno":20}],"hasMore":false,"limit":0,"offset":0,"count":1,"links":[{"rel":"self",
"href":"https://localhost:8443/ords/hr/employees/7788"},{"rel":"describedby",
"href":"https://localhost:8443/ords/hr/metadata-catalog/employees/item"}]}
$123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
Conn testuser1/testuser1@pdb1
begin
oauth.create_client(
p_name => 'emp_client',
p_grant_type => 'authorization_code',
p_owner => 'My Company Limited',
p_description => 'A client for Emp management',
p_redirect_uri => 'https://localhost:8443/ords/hr/redirect',
p_support_email => '[email protected]',
p_support_uri => 'https://localhost:8443/ords/hr/support',
p_privilege_names => 'emp_priv'
);
commit;
end;
/
-- Display client details.
column name format a20
select id, name, client_id, client_secret
from user_ords_clients;
ID NAME CLIENT_ID CLIENT_SECRET
---------- -------------------- -------------------------------- --------------------------------
10333 emp_client gxqNSyxPbLUJhSj1yBe8qA.. E-_mKJBlOTfTdHc_zISniA..
SQL>
CLIENT_ID : gxqNSyxPbLUJhSj1yBe8qA..
State : 3668D7A713E93372E0406A38A8C02171
URL : https://localhost:8443/ords/hr/oauth/auth?response_type=code&client_id={client_id}&state={state}
https://localhost:8443/ords/hr/oauth/auth?response_type=code&client_id=
gxqNSyxPbLUJhSj1yBe8qA..
&state=
3668D7A713E93372E0406A38A8C02171
https://localhost:8443/ords/hr/redirect?code=
FF-APuIMukuBlrver1XU2A..
&state=3668D7A713E93372E0406A38A8C02171
CLIENT_ID : gxqNSyxPbLUJhSj1yBe8qA..
CLIENT_SECRET : E-_mKJBlOTfTdHc_zISniA..
User : CLIENT_ID:CLIENT_SECRET
Data : grant_type=authorization_code&code={authorization-code}
URL : https://localhost:8443/ords/hr/oauth/token
$
curl -i -k --user gxqNSyxPbLUJhSj1yBe8qA..:E-_mKJBlOTfTdHc_zISniA.. --data "grant_type=authorization_code&code=FF-APuIMukuBlrver1XU2A.." https://localhost:8443/ords/hr/oauth/token
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 12:38:52 GMT
{"access_token":"
cOYb2hFK_SyxOh8o9n6R7A..
","token_type":"bearer","expires_in":3600,"refresh_token":"RC33rvSwAfhguraOWlvgfA.."}
$
$
curl -i -k -H"Authorization: Bearer cOYb2hFK_SyxOh8o9n6R7A.." https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: "jtC17IXyetESUjSkxB2ani/a1TnFh28yfor+fLmxxUzGr6G9IFxQ77+/Gd71W4Qzz0rSxf90Qqbl+ICwezTayQ=="
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 12:40:34 GMT
{"items":[{"empno":7788,"ename":"SCOTT","job":"ANALYST","mgr":7566,"hiredate":"1987-04-18T23:00:00Z","sal":3003,
"comm":null,"deptno":20}],"hasMore":false,"limit":0,"offset":0,"count":1,"links":[{"rel":"self",
"href":"https://localhost:8443/ords/hr/employees/7788"},{"rel":"describedby",
"href":"https://localhost:8443/ords/hr/metadata-catalog/employees/item"}]}
$12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
conn testuser1/testuser1@pdb1
begin
oauth.create_client(
p_name => 'emp_client',
p_grant_type => 'implicit',
p_owner => 'My Company Limited',
p_description => 'A client for Emp management',
p_redirect_uri => 'https://localhost:8443/ords/hr/redirect',
p_support_email => '[email protected]',
p_support_uri => 'https://localhost:8443/ords/hr/support',
p_privilege_names => 'emp_priv'
);
commit;
end;
/
-- Display client details.
column name format a20
select id, name, client_id, client_secret
from user_ords_clients;
ID NAME CLIENT_ID CLIENT_SECRET
---------- -------------------- -------------------------------- --------------------------------
10325 emp_client 0docHbkL8__7Ic58n7GCBA..
SQL>
CLIENT_ID : 0docHbkL8__7Ic58n7GCBA..
State : 3668D7A713E93372E0406A38A8C02171
URL : https://localhost:8443/ords/hr/oauth/auth?response_type=code&client_id={client_id}&state={random-string}
https://localhost:8443/ords/hr/oauth/auth?response_type=token&client_id=
0docHbkL8__7Ic58n7GCBA..
&state=
3668D7A713E93372E0406A38A8C02171
https://localhost:8443/ords/hr/redirect#token_type=bearer&access_token=
5SVR_NVP5N_OnDQt6iSxJg..
&expires_in=3600&state=3668D7A713E93372E0406A38A8C02171
$
curl -i -k -H"Authorization: Bearer 5SVR_NVP5N_OnDQt6iSxJg.." https://localhost:8443/ords/hr/employees/7788
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
ETag: "jtC17IXyetESUjSkxB2ani/a1TnFh28yfor+fLmxxUzGr6G9IFxQ77+/Gd71W4Qzz0rSxf90Qqbl+ICwezTayQ=="
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 29 Jun 2016 12:15:35 GMT
{"items":[{"empno":7788,"ename":"SCOTT","job":"ANALYST","mgr":7566,"hiredate":"1987-04-18T23:00:00Z","sal":3003,
"comm":null,"deptno":20}],"hasMore":false,"limit":0,"offset":0,"count":1,"links":[{"rel":"self",
"href":"https://localhost:8443/ords/hr/employees/7788"},{"rel":"describedby",
"href":"https://localhost:8443/ords/hr/metadata-catalog/employees/item"}]}
$123456789101112131415161718
begin
oauth.revoke_client_role(
p_client_name => 'emp_client',
p_role_name => 'emp_role'
);
commit;
end;
/
begin
oauth.delete_client(
p_name => 'emp_client'
);
commit;
end;
/123456789101112131415161718192021222324252627
begin
ords.delete_privilege_mapping(
p_privilege_name => 'emp_priv',
p_pattern => '/employees/*'
);
commit;
end;
/
begin
ords.delete_privilege (
p_name => 'emp_priv'
);
commit;
end;
/
begin
ords.delete_role(
p_role_name => 'emp_role'
);
commit;
end;
/Please to add comments
No comments yet. Be the first to comment!