Search This Blog

Sunday, December 10, 2006

How to set up squid proxy for testing the HTTPS-ORMI Connections and other autheticating proxy problems

How to set up squid proxy for testing the HTTPS-ORMI Connections.

This small write up should help if some one is trying to configure the squid proxy with the authentication.

How to set up squid proxy for testing the HTTPS-ORMI Connections.

open the file /etc/squid/squid.conf

Step 1.
======================
Add the following after this line

#Default:
http_port 9090

This is the port you need to specify for the proxyPorts.

Step 2.
===========================

Append the SSL ports to the list of the SSL ports , in this case I added port
8888.

acl SSL_ports port 443 563 8888

Step 3
=============

Add the following after this line ,
here I added the proxy_auth as required , and my IP address wher I am going to
access the proxy ports.

# And finally deny all other access to this proxy



http_access allow localhost
acl pass proxy_auth REQUIRED
http_access allow pass
acl allowed_clients src 152.69.168.138 152.69.168.139
http_access allow allowed_clients

#http_access deny all


Step 4
==========

Here I need to use the Authentication program that I will be using for the passwords.


And make sure you have the following lines in , after this line

#auth_param basic program


auth_param basic program /usr/lib/squid/ncsa_auth /etc/squidusers
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours

Step 5
=========

Create the /etc/squidusers file ,

/usr/bin/htpasswd -c /etc/squidusers ravi

Give the password as ravi

/usr/bin/htpasswd /etc/squidusers test

Give the password as test


Start the squid proxy servers using the commands ,

service squid restart

After this write the RMI client , for the EJB's


SessionEJBClient.java
======================



package mypackage7;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import mypackage7.SessionEJB;
import mypackage7.SessionEJBHome;
import javax.naming.NamingException;
import java.util.Hashtable;
import HTTPClient.*;

public class SessionEJBClient
{
public static void main(String [] args)
{
SessionEJBClient sessionEJBClient = new SessionEJBClient();
try
{

System.setProperty("http.proxyHost", "incq128ad.idc.oracle.com");
System.setProperty("http.proxyPort","9090");
System.setProperty("http.proxyUser", "ravi");
System.setProperty("http.proxyPassword", "ravi");

DefaultAuthHandler.setAuthorizationPrompter(new MyAuthPrompter(System.getProperty("http.proxyUser"),System.getProperty("http.proxyPassword") ));

Context context = getInitialContext();
SessionEJBHome sessionEJBHome = (SessionEJBHome)PortableRemoteObject.narrow(context.lookup("SessionEJB"), SessionEJBHome.class);
SessionEJB sessionEJB;

// Use one of the create() methods below to create a new instance
sessionEJB = sessionEJBHome.create();

// Call any of the Remote methods below to access the EJB
System.out.println( sessionEJB.sayHello());

}
catch(Throwable ex)
{
ex.printStackTrace();
}

}

private static Context getInitialContext() throws NamingException
{
Hashtable env = new Hashtable();
// Standalone OC4J connection details
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "welcome1");
env.put(Context.PROVIDER_URL, "https:ormi://indl224ad.idc.oracle.com:8888/ejb1");

return new InitialContext(env);
}
}

class MyAuthPrompter implements AuthorizationPrompter
{
private String pa_name, pa_pass;


MyAuthPrompter(String pa_name, String pa_pass)
{
this.pa_name = pa_name;
this.pa_pass = pa_pass;
}


public NVPair getUsernamePassword(AuthorizationInfo challenge, boolean forProxy) {
if (forProxy && pa_name != null)
{
return new NVPair(pa_name, pa_pass);
}

return null;

}
}