Database Reference
In-Depth Information
conn = null;
// We are going to require that only we will set up initial proxy connections
if( c == null || c. isProxySession () ) return null;
else try {
// Set up a non-pooled proxy connection with Client Identifier
// To use an alternate solution, refer to code in OraSSOTests.java
String userName = getOSUserID() ;
if ( ( userName != null ) && ( !userName.equals( "" ) ) ) {
Properties prop = new Properties();
prop.setProperty( OracleConnection. PROXY_USER_NAME, userName );
c.openProxySession(OracleConnection.PROXYTYPE_USER_NAME, prop);
String metrics[] =
new String[OracleConnection.END_TO_END_STATE_INDEX_MAX];
metrics[OracleConnection.END_TO_END_ CLIENTID _INDEX] = userName ;
c.setEndToEndMetrics( metrics, ( short )0 );
// If we don't get here, no Connection will be available
conn = c;
} else {
// This is not a valid user
}
} catch ( Exception x ) {
x.printStackTrace();
}
return conn;
}
This code is exactly what we have been discussing for Oracle SSO. Notice that if the connection that
is handed to us is already a proxy connection, we discard it and nullify our Connection . We will not
recognize any proxy connections that are configured elsewhere—for security sake, we are jealous and
protective of our role in this.
Add an Overloaded setConnection() Method
We are returning the resultant, configured OracleConnection from the setConnection() methods listed in
8-24, and these will support an additional setConnection() method. The additional method (Listing 8-
25) takes the URL as a String , instantiates a Connection and calls the core setConnection() method,
which configures the connection with a proxy session and client identifier. It then returns the configured
OracleConnection . It is made relatively easy with a call to the other setConnection() methods, and
returning what they return.
Listing 8-25. Alternate Set Internal Connection, setConnection()
public static final OracleConnection setConnection ( String URL ) {
Connection c = null;
try {
Class.forName( "oracle.jdbc.driver.OracleDriver" );
c = DriverManager.getConnection( URL );
} catch ( Exception x ) {
x.printStackTrace();
 
Search WWH ::




Custom Search