// get records for the specified username with access to the function
String query1 = "select HOST, current timestamp as TS from ACCESSLIST "+
"where USERNAME= " + DB2USR + " and ACCESS_" + mode + "= Y ";
System.out.println("Query = " + query1);
PreparedStatement ps1 = db2Conn.prepareStatement(query1);
ResultSet rs = ps1.executeQuery(); // run the query
if (! rs.next()) // no rows found?
System.out.println("no authorization for this username...");
else
{
String ts = rs.getString("TS"); // retrieve the timestamp (key)
String hostval = rs.getString("HOST"); // retrieve allowed hostname
// write the current connection info into a table
// with this table it is possible to use the SQL like function
String insertStr = "insert into APPLACCESS values " +
"( "+DB2USR+" , "+ipname+" , "+ipaddr+" , "+ts+" )";
System.out.println("Insert = " + insertStr);
PreparedStatement ps0 = db2Conn.prepareStatement(insertStr);
ps0.execute(); // run the insert
// check if the current connection info has an equivalent host entry
// (either IP name or IP address)
String query2 = "select 1 from APPLACCESS where "+
"TS= "+ts+" and "+
"HOSTNAME like "+hostval+" or IPADDR like "+hostval +" ";
while (rs.next()) // there can be more than one permitted hosts
{
hostval = rs.getString("HOST"); // retrieve the allowed hostname
query2 = query2 + " or HOSTNAME like " + hostval +
" or IPADDR like " + hostval + " ";
}
System.out.println("Query = " + query2);
PreparedStatement ps2 = db2Conn.prepareStatement(query2);
ResultSet rs2 = ps2.executeQuery(); // run the query
if (! rs2.next()) // no accordance found?
System.out.println("no authorization...");
else
{
System.out.println("You are authorized to go on!");
// here should be the call to the access controlled function
if (mode.equals("SEL")
{
// call the SELECT function
}
if (mode.equals("INS")
{
// call the INSERT function
Chapter 7. Application porting
225
footer
Our partners:
PHP: Hypertext Preprocessor Cheap Web Hosting
JSP Web Hosting
Ontario Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Java Hosting
Cheapest Hosting
Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved