Oracle Concepts - Use Of Roles
Added 31 Jul 2008
Using roles has several benefits, including:
* Reducing the number of grants and thereby making it easier to manage security.
* Dynamically changing the privileges for many users with a single grant or revoke.
* Selectively enabling or disabling depending on the application.
Roles can be used for most system and object privileges. Privileges granted through a role cannot be used for creating an object (views, packages, procedures, and functions). You need to grant privileges directly to the user for this.
Creating Roles
You need to create the role first and then grant system and object privileges to that role. When you create the role, there are three password options available:
* No authentication
* Operating system authentication
* Password authentication
You can set operating system authentication either when the role is created or by using the database initialization parameters OS_ROLES=TRUE and REMOTE_OS_ROLES=TRUE. If you are using the multithreaded server option, you cannot use operating system authentication for roles.
To create a role, you must have the CREATE ROLE system privilege. You can create roles with Server Manager or at the command line in SQL*Plus. The command syntax for creating a role is seen in Listing 39.
Listing 39: Syntax for creating a role.
A role can also be identified globally by using the GLOBALLY keyword in the IDENTIFIED clause. This means the role will be authenticated by the Oracle Security Server.
Here is an example:
CREATE
ROLE appusers
GLOBALLY IDENTIFIED;
To alter a role, you must have the ALTER ANY ROLE system privilege or have been granted the role with the WITH ADMIN OPTION. The creator of any role automatically has the WITH ADMIN OPTION for that role.
Grants To Roles
To grant a role to a user, you must either be the creator of that role or have the GRANT ANY ROLE privilege. You can grant roles to users with Server Manager or at the command line in SQL*Plus. Grants to roles will not take effect for a user if that user is currently logged into the database with that role. When the user exits or sets another role, the changes will take effect. Once roles have been granted to a user, they can be enabled and disabled.
Here is an example:
GRANT
enduser
TO patrick ;
Here is an example for a role:
GRANT
create session
TO enduser;
Here is an example of granting an object privilege to a role:
GRANT
select
ON john.emp
TO enduser;
The only system privilege which cannot be granted to a role is the UNLIMITED TABLESPACE grant, however, it is implicitly granted whenever the DBA or RESOURCE role grant is made to a user. Grants on objects can be passed to other users or to roles if the grantee has been given the WITH GRANT OPTION. However, you cannot assign a privilege that includes the WITH GRANT OPTION to a role. The INDEX and REFERENCES privileges cannot be granted to a role; they must be granted only to a user. You can grant that role to a user or to another role. However, you cannot grant a role to itself.