Tải bản đầy đủ (.pdf) (34 trang)

Tài liệu controlling user access docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (254.49 KB, 34 trang )

Controlling User Access
16
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć2
Schedule: Timing Topic
25 minutes Lecture
20 minutes Practice
45 minutes Total
Class Management Note:
Files required for this lesson are:
Demonstration: None
Practice: None
This lesson should give students an overview of Oracle7 Server’s security
options. It is not intended to go into tremendous detail on each topic.
Controlling User Access 16Ć3
Objectives
This lesson describes the Oracle7 Server decentralized security system. Using
the commands covered in this lesson, you can control database access to specific
objects and add new users with different levels of access privileges. You can
provide alternative names for objects by using the CREATE SYNONYM
command.
At the end of this lesson, you should be able to
D Explain the concept of the database security model.
D Describe system privileges.
D Set up and maintain database access by using roles.
D Identify object privileges.
D Change a password.
D Grant and revoke object privileges.
D Create synonyms for ease of table access.
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć4
Server
Controlling User Access 16Ć5


Overview
In a multiple-user environment, you want to maintain security of the database access
and use. Oracle7 Server database security allows you to
D Control database access.
D Give access to specific objects in the database.
D Confirm given and received privileges with the Oracle data dictionary.
D 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 username and password, disk space allocated to users, and system operations
allowed by the user. Database security covers access and use of the database objects
and the actions that those users can have on the objects.
Privileges
Privileges are the right to execute particular SQL statements. The database
administrator 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.
Schema
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
Oracle7 Server Application Developer’s Guide, Release 7.3, “Establishing a Security
Policy” section and Oracle7 Server Concepts Manual, “Database Security” topic.
Class Management Note:
PowerPoint: The bottom slide contains the build feature.
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć6
Controlling User Access 16Ć7
System Privileges

There are more than eighty system privileges available for users and roles. System
privileges are typically provided by the database administrator.
Typical DBA Privileges
System Privilege
Operations Authorized
CREATE USER Allows grantee to create other Oracle users (a
privilege required for a DBA role).
DROP USER Drops another user.
DROP ANY TABLE Drops a table in any schema.
BACKUP ANY TABLE Backs up any table in any schema with the export
utility.
Creating a User
The DBA creates a new Oracle7 Server user by allocating a number of system
privileges to that user. These privileges in turn determine what the user can do at the
database level. The DBA creates the user by executing the CREATE USER
command. The user does not have any system privileges.
Abridged Syntax
CREATE USER user IDENTIFIED BY password;
where: user is the name of the user to be created.
password specifies that the user must log in with this
password.
For more information, see
Oracle7 Server SQL Reference, Release 7.3, “GRANT” (System Privileges and
Roles) and “CREATE USER.”
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć8
Controlling User Access 16Ć9
System Privileges continued
Now that the DBA has created a user, the DBA can assign privileges to that user.
Typical User Privileges
System Privilege

Operations Authorized
CREATE SESSION Connect to the database.
CREATE TABLE Create tables in the user’s schema.
CREATE SEQUENCE Create a sequence in the user’s schema.
CREATE VIEW Create a view in the user’s schema.
CREATE PROCEDURE Create a stored procedure, function, or package in
the user’s schema.
Granting System Privileges
The DBA uses the GRANT command to allocate system privileges to the user. Once
the user has been granted the privileges, the user can immediately use those
privileges.
Syntax
GRANT privilege [, privilege ] TO user [, user ];
where: privilege is the system privilege to be granted.
user is the name of the user.
Note: The above syntax is abridged.
Class Management Note:
Note for page 16-10.
Question: What is a role? Try to elicit answers from the students.
Answer: See the next slide for the answer.
PowerPoint: The top slide on page 16-10 contains the build feature.
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć10
Class Management Note:
Discuss the four following points about roles:
1.Named groups of related privileges
2.Can be granted to users
3.Simplifies the process of granting and revoking privileges
4.Created by a DBA
Controlling User Access 16Ć11
What Is a Role?

A role is a named group of related privileges that can be granted to the user. This
method makes granting and revoking privileges easier to perform and maintain.
A user can have access to several roles, and several users can be assigned the same
role. Roles typically are created for a database application.
Creating and Assigning a Role
First, the DBA must create the role. Then, the DBA can assign privileges to the role
and users to the role.
Syntax
CREATE ROLE role;
where: role is the name of the role to be created.
Now that the role is created, the DBA can use the GRANT command to assign users
to the role as well as assign privileges to the role.
Example
Allow the managers to create tables and views. Give these privileges to Velasquez
and to Ropeburn.
SQL> CREATE ROLE manager;
Role created.
SQL> GRANT create table, create view TO manager;
Grant succeeded.
SQL> GRANT manager TO cvelasqu, aropebur;
Grant succeeded.
Technical Note:
Roles were introduced in the Oracle7 Server. Do not confuse roles at the
database level with roles that are also definable within SQL*Menu Version
5.0. They are not the same.
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć12
Controlling User Access 16Ć13
Changing Your Password
Every user has a password that is initialized by the DBA when the user is created.
You can change your password by using the ALTER USER command.

Syntax
ALTER USER user IDENTIFIED BY password;
where: user is the name of the user.
password specifies the new password.
Note: Although this command 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
Oracle7 Server SQL Reference, Release 7.3, “ALTER USER.”
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć14
Controlling User Access 16Ć15
Granting Object Privileges
The DBA can allow users to perform a particular action on a specific table, view,
sequence, or stored procedure by granting them object privileges. The object
privileges vary from object to object. The table on the facing page outlines the
privileges. An object owner has all privileges on the object. To give another user
access to your database objects, execute the GRANT command.
Syntax
GRANT {object_priv(, object_priv )|ALL}[(columns)]
ON object
TO {user[, user ]|role|PUBLIC}
[WITH GRANT OPTION];
where: object_priv is an object privilege to be granted.
ALL all object privileges.
columns specifies the column from a table or view on
which privileges are granted.
ON object is the object on which the privileges are granted.
TO identifies to whom the privilege is granted.
PUBLIC grants object privileges to all users.
WITH GRANT OPTION allows the grantee to grant the object privileges

to other users and roles.
Note: A procedure refers to standalone procedures and functions, and public
package constructs. The INDEX and REFERENCES privileges cannot be
granted to a role.
For more information, see
Oracle7 Server SQL Reference, Release 7.3, “GRANT.”
Technical Note:
Each object has a particular set of grantable privileges. Point out that the
only privileges that apply to a sequence are SELECT and ALTER.
UPDATE, REFERENCES, and INSERT can be restricted by specifying a
subset of updatable columns. SELECT can be restricted by specifying a
subset of selectable columns. Restricted SELECT creates a view with a
subset of columns and grants SELECT privileges on the view. A grant on a
synonym is converted to a grant upon the base table referenced by the
synonym.
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć16
Controlling User Access 16Ć17
Granting Object Privileges continued
Guidelines
D 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.
D An object owner can grant any object privilege on the object to any other user or
role of the database.
D The owner of an object automatically acquires all object privileges on that object.
Examples
Grant users Sue and Rich the privilege to query your S_EMP table.
SQL> GRANT select
2 ON s_emp
3 TO sue, rich;
Grant succeeded.

Grant UPDATE privileges on specific columns in the S_DEPT table to Scott and to
the manager role.
SQL> GRANT update (name, region_id)
2 ON s_dept
3 TO scott, manager;
Grant succeeded.
Technical Note:
DBAs generally allocate system privileges; any user who owns an object
can grant object privileges.
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć18
Class Management Note:
If a statement does not use the full name of an object, then the Oracle7
Server implicitly prefixes the object name with the current user’s name (or
schema). If user Scott queries the S_DEPT table, then the system will
SELECT from table SCOTT.S_DEPT.
If a statement does not use the full name of an object, and the current user
does not own an object of that name, then the system will prefix the object
name with PUBLIC. For example, if user Scott queries the
USER_OBJECTS table, and Scott does not own such a table, then the
system will SELECT from the data dictionary view by way of the
PUBLIC.USER_OBJECTS public synonym.
Controlling User Access 16Ć19
Granting Object Privileges continued
The WITH GRANT OPTION Keyword
A privilege that is granted WITH GRANT OPTION can be passed on to other users
and roles by the grantee. Object privileges granted WITH GRANT OPTION are
revoked when the grantor’s privilege is revoked.
Example
As user Alice, allow user Scott to access your S_DEPT table with the privileges to
query the table and add rows to the table. Allow Scott to give others these privileges.

SQL> GRANT select, insert
2 ON s_dept
3 TO scott
4 WITH GRANT OPTION;
Grant succeeded.
The PUBLIC Keyword
An owner of a table can grant access to all users by using the PUBLIC keyword.
Example
As user Scott, allow all users on the system to query data from Alice’s S_DEPT table.
SQL> GRANT select
2 ON alice.s_dept
3 TO PUBLIC;
Grant succeeded.
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć20
Controlling User Access 16Ć21
Confirming Privileges Granted
If you attempt to perform an unauthorized operation, for example, deleting a row
from a table for which you do not have the DELETE privilege, the Oracle7 Server
will not permit the operation to take place.
If you receive the Oracle7 Server error message “table or view does not exist,” you
have done either of the following:
D Named a table or view that does not exist
D Attempted to perform an operation on a table or view for which you do not have
the appropriate privilege
What Privileges Do You Have?
You can access the data dictionary to view the privileges you have.
Data Dictionary Table
Description
ROLE_SYS_PRIVS System privileges granted to roles.
ROLE_TAB_PRIVS Table privileges granted to roles.

USER_ROLE_PRIVS Roles accessible by the user.
USER_TAB_PRIVS_MADE Object privileges granted on the user’s objects.
USER_TAB_PRIVS_RECD Object privileges granted to the user.
USER_COL_PRIVS_MADE Object privileges granted on the columns of the
user’s objects.
USER_COL_PRIVS_RECD Object privileges granted to the user on specific
columns.
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć22
Controlling User Access 16Ć23
Revoking Object Privileges
Remove privileges granted to other users by using the REVOKE command. When
you use the REVOKE command, the privileges you specify are revoked from the
users you name, and from any other users to whom those privileges may have been
granted.
Syntax
REVOKE {privilege [, privilege ] | ALL}
ON object
FROM {user[, user ]|role|PUBLIC}
[CASCADE CONSTRAINTS]
where: CASCADE are required to remove any referential integrity
CONSTRAINTS constraints made to the object by means of the
REFERENCES privilege.
SQL> REVOKE select, insert
2 ON s_dept
3 FROM scott;
Revoke succeeded.
For more information, see
Oracle7 Server SQL Reference, Release 7.3, “REVOKE.”
Technical Note:
If a user is granted a privilege WITH GRANT OPTION, then that user can

also grant the privilege WITH GRANT OPTION, 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,
then the REVOKE cascades to all privileges granted.
For example, if user A grants SELECT privilege on a table to user B
including the WITH GRANT OPTION, then user B can grant to user C the
SELECT privilege WITH GRANT OPTION, and user C can then grant to
user D the SELECT privilege. If user A the revokes the privilege from user
B, then the privileges granted to users C and D are also revoked.
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder16Ć24
Class Management Note:
A common use of synonyms is to run an application against a set of test
tables. Then, when testing is completed, a set of synonyms can be defined
or redefined, directing the application to run against production tables.
An object need not currently exist and you need not have privileges to
access the object when creating the synonym.
Controlling User Access 16Ć25
Creating a Synonym for an Object
To refer to a table owned by another user, you need to prefix the table name with the
name of the user who created it followed by a period. Creating a synonym eliminates
the need to qualify the object name with the schema, and provides you with an
alternative name for a table, view, sequence, procedure, or other objects. This method
can be especially useful with lengthy object names, such as views.
Syntax
CREATE [PUBLIC] SYNONYM synonym
FOR object;
where: PUBLIC creates a synonym accessible to all users.
synonym is the name of the synonym to be created.
object identifies the object for which the synonym is
created.

Guidelines
D The object cannot be contained in a package.
D A private synonym name must be distinct from all other objects owned by the
same user.
Example
As user Scott, create a private synonym named S_DEPT for Alice’s S_DEPT table.
SQL> CREATE SYNONYM s_dept
2 FOR alice.s_dept;
Synonym created.
For more information, see
Oracle7 Server SQL Reference, Release 7.3, “CREATE SYNONYM.”

×