How to make apache2 authenticate against MS SQL 2000 Server - Page 4
5.3. The new testConnection.javaimport java.sql.*;
import java.io.*;
import java.text.*;
public class testConnection
{
static InputStreamReader converter = new InputStreamReader (System.in);
static BufferedReader in = new BufferedReader (converter);
// Read a String from standard system input
public static String getString() {
try {
return in.readLine();
} catch( Exception e ) {
System.out.println("getString() exception, returning empty string");
return "";
}
}
public static void main(String[] args)
{
String userName;
String userPass;
// userName = args[0];
userName = getString();
// userPass = args[1];
userPass = getString();
DB db = new DB();
db.dbConnect(
"jdbc:jtds:sqlserver://xxx.xxx.xxx.xxx:1433/test",userName,userPass);
}
}
class DB
{
public DB() {}
public void dbConnect(String db_connect_string,
String db_userid, String db_password)
{
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
System.out.println("connected");
System.exit(0);
}
catch (Exception e)
{
//e.printStackTrace();
System.out.println("failed");
System.exit(1);
}
}
};
So after the ‘program’ was written I had to compile it and put in some place for apache. So there comes javac again javac testConnection.java and we pack it with jar jar cfm tc.jar manifest DB.class testConnection.class manifest file should tell the name of main class like that: Main-Class: testConnection I copied the tc.jar to /usr/local/testConn/ 5.4. Final apache configurationAnd after that configured apache to execute it as external authentication program by editing /etc/apache2/default-server.conf and adding following lines: AddExternalAuth archive_auth "/usr/lib/java/bin/java -jar /usr/local/testConn/tc.jar" SetExternalAuthMethod archive_auth pipe Final thing – tell to use particular authentication method for our ‘restricted’ directory in httpd.conf <Directory /srv/www/htdocs/secretarea>
Options Indexes FollowSymLinks
AllowOverride None
AuthType Basic
AuthName "Autorizacija!"
AuthExternal archive_auth
Require valid-user
</Directory>
After restart of apache if we try to access http://xxx.xxx.xxx.xxx/secretarea -
apache prompts for username and password.
|
Join the discussion.
www.seamlessenterprise.com
IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com
Wireless & Wireline Integration
Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com
Unified Communications 2009
Join the Discussion. Now.
www.seamlessenterprise.com
Red Hat Virtual Experience - a free virtual event. Dec. 9th




![Creative Commons Attribution License [Creative Commons Attribution License]](http://creativecommons.org/images/public/somerights20.gif)

print: 
Recent comments
9 hours 22 min ago
15 hours 10 min ago
17 hours 2 min ago
18 hours 47 min ago
22 hours 37 min ago
1 day 4 hours ago
1 day 4 hours ago
1 day 8 hours ago
1 day 14 hours ago
1 day 19 hours ago