Database Reference
In-Depth Information
In that thread, the first thing we do is attempt to create the user on both the
orcl
and
apver
instances. We did not need an Oracle user until we decided to grant the user access to the applications.
Then we assign applications. We get the
dataVector
from the user's proxies table model. That is our
planned, resultant list of proxies for the user. Some of these may be added proxies. Some may be proxies
the user had previously. There may also be proxy grants that the user had that have now been removed
from this list. So we have to handle the following three cases:
•
Retain existing proxies that are in the list.
•
Add new proxies that are in the list.
•
Remove existing proxies that are no longer in the list.
In Listing 12-41, we handle these three cases. We select the existing list of proxies from an Oracle
query and walk through the
ResultSet
. We are only concerned with proxies for the selected user. For
each existing proxy in the
ResultSet
, we create a new
itemVector
with that as an item. We can find if the
dataVector
has an
itemVector
like that by calling the
contains()
method. If it does, then this is a proxy
we want to retain. We have dealt with that proxy, so we remove it from the
dataVector
. Later, we will see
what proxies are still left in the
dataVector
—those will have to be newly granted to the user.
If the existing proxy we got from our query is not in the
dataVector
, then it was removed from the
list, and we need to revoke the proxy grant. We do that by calling the
p_drop_proxy_through
procedure.
Finally, we are left with a
dataVector
with just those proxies that did not exist previously. For each of
those, we call the
p_set_proxy_through
procedure to add a new proxy grant for the selected user.
Listing 12-41.
Save Updates to User's Proxies
OracleCallableStatement stmt2 = null;
Statement stmt = null;
ResultSet rs = null;
try {
// First, try to create user on both instances
stmt2 =
(OracleCallableStatement)conn.prepareCall(
"CALL sys.usr_role_adm_pkg.
p_create_user_once
(?)");
stmt2.setString(1, userID);
stmt2.executeUpdate();
if (stmt2 != null)
stmt2.close();
stmt2 =
(OracleCallableStatement)conn.prepareCall(
"CALL sys.usr_role_adm_pkg.
p_create_user_many
(?)");
stmt2.setString(1, userID);
stmt2.executeUpdate();
if (stmt2 != null)
stmt2.close();
stmt2 =
(OracleCallableStatement)conn.prepareCall(
"CALL ojsaadm.apver_usr_adm_pkg.
p_create_apver_user
(?)");
stmt2.setString(1, userID);
stmt2.executeUpdate();
if (stmt2 != null)
stmt2.close();