This document discusses database user access and privileges in Oracle. It explains that the database administrator controls access by creating users, assigning them passwords and granting system and object privileges. System privileges control access to the database itself, while object privileges control access to specific database objects. The document provides examples of using SQL statements like CREATE USER, GRANT, ALTER USER, and REVOKE to manage users and privileges.
#3 Controlling User Access
In a multiple-user environment, you want to maintain security of the database access and use. With Oracle server database security, you can do the following:
Control database access
Give access to specific objects in the database
Confirm given and received privileges with the Oracle data dictionary
Create synonyms for database objects
Database security can be classified into two categories: system security and data security. System security covers access and use of the database at the system level, such as the username and password, the disk space allocated to users, and the system operations that users can perform. Database security covers access and use of the database objects and the actions that those users can have on the objects.
#4 Privileges
Privileges are the right to execute particular SQL statements. The database administrator (DBA) is a high-level user with the ability to grant users access to the database and its objects. The users require system privileges to gain access to the database and object privileges to manipulate the content of the objects in the database. Users can also be given the privilege to grant additional privileges to other users or to roles, which are named groups of related privileges.
Schemas
A schema is a collection of objects, such as tables, views, and sequences. The schema is owned by a database user and has the same name as that user.
For more information, see Oracle9i Application Developer’s Guide - Fundamentals, “Establishing a Security Policy” section, and Oracle9i Concepts, “Database Security” topic.
#5 System Privileges
More than 100 distinct system privileges are available for users and roles. System privileges typically are provided by the database administrator.
Typical DBA Privileges
#6 Creating a User
The DBA creates the user by executing the CREATE USER statement. The user does not have any privileges at this point. The DBA can then grant privileges to that user. These privileges determine what the user can do at the database level.
The slide gives the abridged syntax for creating a user.
In the syntax:
useris the name of the user to be created
passwordspecifies that the user must log in with this password
For more information, see Oracle9i SQL Reference, “GRANT” and “CREATE USER.”
Instructor Note
For information on DROP USER, refer to Oracle9i SQL Reference, “DROP USER.”
#7 Typical User Privileges
Now that the DBA has created a user, the DBA can assign privileges to that user.
In the syntax:
privilegeis the system privilege to be granted
user|role|PUBLICis the name of the user, the name of the role, or PUBLIC designates that every user is granted the privilege
Note: Current system privileges can be found in the dictionary view SESSION_PRIVS.
Instructor Note
The syntax displayed for the GRANT command is not the full syntax for the statement.
#8 Granting System Privileges
The DBA uses the GRANT statement to allocate system privileges to the user. Once the user has been granted the privileges, the user can immediately use those privileges.
In the example on the slide, user Scott has been assigned the privileges to create sessions, tables, sequences, and views.
Instructor Note
A user needs to have the required space quota to create tables.
#9 Changing Your Password
The DBA creates an account and initializes a password for every user. You can change your password by using the ALTER USER statement.
Syntax
ALTER USER user IDENTIFIED BY password;
In the syntax:
useris the name of the user
passwordspecifies the new password
Although this statement can be used to change your password, there are many other options. You must have the ALTER USER privilege to change any other option.
For more information, see Oracle9i SQL Reference, “ALTER USER.”
#10 Granting Object Privileges
Different object privileges are available for different types of schema objects. A user automatically has all object privileges for schema objects contained in the user’s schema. A user can grant any object privilege on any schema object that the user owns to any other user or role. If the grant includes WITH GRANT OPTION, then the grantee can further grant the object privilege to other users; otherwise, the grantee can use the privilege but cannot grant it to other users.
In the syntax:
object_privis an object privilege to be granted
ALLspecifies all object privileges
columnsspecifies the column from a table or view on which privileges are granted
ON objectis the object on which the privileges are granted
TOidentifies to whom the privilege is granted
PUBLICgrants object privileges to all users
WITH GRANT OPTION allows the grantee to grant the object privileges to other users and roles
#11 Guidelines
To grant privileges on an object, the object must be in your own schema, or you must have been granted the object privileges WITH GRANT OPTION.
An object owner can grant any object privilege on the object to any other user or role of the database.
The owner of an object automatically acquires all object privileges on that object.
The first example on the slide grants users Sue and Rich the privilege to query your EMPLOYEES table. The second example grants UPDATE privileges on specific columns in the DEPARTMENTS table to Scott and to the manager role.
If Sue or Rich now want to SELECT data from the employees table, the syntax they must use is:
SELECT *
FROM scott.employees;
Alternatively, they can create a synonym for the table and SELECT from the synonym:
CREATE SYNONYM emp FOR scott.employees;
SELECT * FROM emp;
Note: DBAs generally allocate system privileges; any user who owns an object can grant object privileges.
Instructor Note
Please read the Instructor Note at the end of this lesson.
#12 Revoking Object Privileges
You can remove privileges granted to other users by using the REVOKE statement. When you use the REVOKE statement, the privileges that you specify are revoked from the users you name and from any other users to whom those privileges were granted through the WITH GRANT OPTION clause.
In the syntax:
CASCADEis required to remove any referential integrity constraints made to the CONSTRAINTSobject by means of the REFERENCES privilege
For more information, see Oracle9i SQL Reference, “REVOKE.”
#13 Revoking Object Privileges (continued)
The example on the slide revokes SELECT and INSERT privileges given to user Scott on the DEPARTMENTS table.
Note: If a user is granted a privilege with the WITH GRANT OPTION clause, that user can also grant the privilege with the WITH GRANT OPTION clause, so that a long chain of grantees is possible, but no circular grants are permitted. If the owner revokes a privilege from a user who granted the privilege to other users, the revoking cascades to all privileges granted.
For example, if user A grants SELECT privilege on a table to user B including the WITH GRANT OPTION clause, user B can grant to user C the SELECT privilege with the WITH GRANT OPTION clause as well, and user C can then grant to user D the SELECT privilege. If user A revokes privilege from user B, then the privileges granted to users C and D are also revoked.
Instructor Note
Revoking system privileges is not within the scope of this lesson. For information on this topic refer to: Oracle9i SQL Reference, “REVOKE system_privileges_and_roles. ”