I'll preface this post by saying that I'm new to J2EE.  My problem is that some 
of our code that ran on Tomcat 5.0.28 doesn't work on JBoss 4.0.3CR2.

Principal p = request.getUserPrincipal();

This code in Tomcat 5.0.28 returned a principle that we could use to 
reflectively invoke 'getRealm' to get the LDAP config info that was stored in 
our webapp's context.xml.  In JBoss 4.0.3CR2, it returns a SimplePrinciple 
which doesn't have the 'getRealm' method.  This is the root of the problem, but 
it's not really what I want to fix.  I want to remove the LDAP dependency from 
our code and just query JAAS or the app server itself, whichever is the more 
proper J2EE way to do it.

There's a servlet that gets a list of users in a specific role, which are added 
to a combo box in a JSP.  Here's the code that sets up the connection to LDAP:

Object r = p.getClass().getMethod("getRealm", null).invoke(p, null);
  | 
  | // The hashtable to hold the LDAP details to setup the connection
  | Hashtable env = new Hashtable ();
  |   
  | // Pull all the relevant data out of the realm with reflection
  | String connectionFactory = (String) 
r.getClass().getMethod("getContextFactory", null).invoke (r, null);
  | String connectionName    = (String) 
r.getClass().getMethod("getConnectionName", null).invoke (r, null);
  | String connectionPassword = (String) 
r.getClass().getMethod("getConnectionPassword", null).invoke (r, null);
  | String connectionURL = (String) r.getClass().getMethod ("getConnectionURL", 
null).invoke (r, null);
  | String authentication = (String) 
r.getClass().getMethod("getAuthentication", null).invoke (r, null);
  | String protocol = (String) r.getClass().getMethod("getProtocol", 
null).invoke (r, null);
  | String referrals = (String) r.getClass().getMethod ("getReferrals", 
null).invoke (r, null);
  | 
  | String userBase = (String) r.getClass().getMethod ("getUserBase", 
null).invoke (r, null);
  | String roleBase = (String) r.getClass().getMethod ("getRoleBase", 
null).invoke (r, null);

This code may be "bad" because I'm sure there are much better ways to do this.  
I didn't write it but I'm looking to replace it with something not dependent on 
LDAP.

I know what this code is doing, pulling out the LDAP config information that 
Tomcat read from the context.xml (which is where database connections and 
Realms were defined in Tomcat 5.0.28), and then using that to set up the JNDI 
lookup to reconnect to the LDAP server.

Here's the question though:  Shouldn't there be a way to query the application 
server for this information instead of going directly to LDAP?  This creates a 
dependency I don't want in the code.  If we take away LDAP and switch JBoss to 
a JAAS policy using file-based authentication for some reason, the code trying 
to get to LDAP will fail.

If I switched out the LDAP lookups to JAAS lookups, that would work.  Or if 
it's more "proper" to query the app server in some other way, I'd like to find 
out how.

Sorry for a bit of a jumbled post.  I hope someone can point me in the right 
direction.  Using google up until now has been an exercise in information 
overload for me. :)

- Jeff


View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3942574#3942574

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3942574


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to