Hi.
i have requirement to get Users in LDAP using the realm information give in my application xml file museadmin.xml ( i have attached this file)
i want to get JNDIRealm information , i will use real object to get information like getConnectionURL etc.
I have seen code give below published in site
Server server = ServerFactory.getServer();
//Note, this assumes the Container is "Catalina"
Service service = server.findService("Catalina");
Engine engine = (Engine) service.getContainer();
Host host = (Host)
engine.findChild(engine.getDefaultHost());
//Note, this assumes your context is "myContext"
Context context = (Context) host.findChild("myContext");
Realm realm = context.getRealm();
I want to use this code in my servlet to get JNDIRealm information
i am not able to get the service object , i am getting the NullPointerException in line Service service = server.findService("Catalina");
i have observed that server object is not initialized properly , If i try to print the server.findServices().length it is printing as 0
please some one help me in resolving this problem,
my Servlet Class is below :
public class JNDIRealmServlet extends HttpServlet {
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
JNDIRealm realm= (JNDIRealm)getJNDIRealm();
}
public JNDIRealm getJNDIRealm(){
JNDIRealm realm=null;
try
{
Server server = ServerFactory.getServer();
Service ser[]=server.findServices();
System.out.println("length = "+server.findServices().length);
for(int i=0;i< server.findServices().length;i++){
System.out.println("service[ "+i+"] = "+ser[i]);
}
//Note, this assumes the Container is "Catalina"
Service service = server.findService("Catalina");
Engine engine = (Engine) service.getContainer();
Host host = (Host) engine.findChild(engine.getDefaultHost());
//Note, this assumes your context is "myContext"
Context context = (Context) host.findChild("myContext");
realm = (JNDIRealm)context.getRealm();
}catch(Exception ex){
ex.printStackTrace();
}
return realm;
}
}
Thanks and Regards
Chandra,
SoftwareEngineer,
FlextronicsSoftwareSystems.
Yahoo! Photos Showcase holiday pictures in hardcover
Photo Books. You design it and well bind it!
<!-- Context configuration file for the Tomcat Administration Web App
$Id: admin.xml,v 1.3 2004/02/20 17:09:19 remm Exp $ --> <myContext path="/museadmin" docBase="${catalina.home}/webapps/museadmin" debug="0" privileged="true"> <!--<Realm className="org.apache.catalina.realm.JNDIRealm" debug="99" connectionName="cn=manager,dc=alcatel,dc=com" connectionPassword="secret" connectionURL="ldap://localhost:389" roleBase="ou=roles,dc=alcatel,dc=com" roleName="cn" roleSearch="(uniqueMember={0})" roleSubtree="false" userSearch="(uid={0})" userPassword="userPassword" userPattern="uid={0},ou=people,dc=alcatel,dc=com" />--> <Realm className="org.apache.catalina.realm.JNDIRealm" debug="99" connectionName="cn=Manager, dc =alcatel, dc =com" connectionPassword="secret" connectionURL="ldap://10.203.201.178:666" roleBase="dc=alcatel,dc=com" roleName="cn" userSearch="((cn=*))" /> <Resource name="ldap/museadmin" auth="Container" type="org.apache.catalina.realm.JNDIRealm" debug="99" connectionName="cn=manager,dc=alcatel,dc=com" connectionPassword="secret" connectionURL="ldap://10.203.201.178:666" roleBase="ou=roles,dc=alcatel,dc=com" roleName="cn" roleSearch="(uniqueMember={0})" roleSubtree="false" userSearch="(uid={0})" userPassword="userPassword" userPattern="uid={0},ou=people,dc=alcatel,dc=com"/> <Resource auth="Container" description="Oracle Datasource example" name="jdbc/museadmin" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/museadmin"> <parameter> <name>maxWait</name> <value>5000</value> </parameter> <parameter> <name>maxActive</name> <value>4</value> </parameter> <parameter> <name>password</name> <value>maatusr1</value> </parameter> <parameter> <name>url</name> <value>jdbc:oracle:thin:@10.203.201.180:1521:SNM</value> </parameter> <parameter> <name>driverClassName</name> <value>oracle.jdbc.driver.OracleDriver</value> </parameter> <parameter> <name>maxIdle</name> <value>2</value> </parameter> <parameter> <name>username</name> <value>maatusr1</value> </parameter> </ResourceParams> <!-- Uncomment this Valve to limit access to the Admin app to localhost for obvious security reasons. Allow may be a comma-separated list of hosts (or even regular expressions). <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127.0.0.1"/> --> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_admin_log." suffix=".txt" timestamp="true"/> </myContext>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]