We run Apache infront of Tomcat and use mod_jk. Our single sign on Apache module sets information about the user which we can retrieve in Java with a getAttribute() call.
String mobileNumber = request.getAttribute("WEBAUTH_LDAP_MOBILE");
This works fine. Now I wanted to retrieve all attributes and look for ones named with a prefix “WEBAUTH_LDAP_”. I used getAttributeNames() for this.
Enumeration<String> enumeration = request.getAttributeNames();
to get the attribute names. To my surprise there is no attribute named “WEBAUTH_LDAP_MOBILE”.
Is this expected? Is there a way to get all attributes? The JavaDoc makes it sound like something in getAttribute() should also be in getAttributeNames().
We are using Tomcat 6.0.28.
This is because any attributes set with mod_jk are available with
getAttribute()but not throughgetAttributeNames(). According to the documentationI debugged through all the RequestWrappers (per BalusC’s suggestion) and the underlying request has an internal map of attributes which are used for
getAttributeNames(). However,getAttribute()has a fall through to another object when the internal map’s value is null. From the javadoc and documentation, this is working as designed.This behavior has previously been reported as a bug, but the fix fails the TCK test:
So in short,
getAttributeNames()will return attributes set withsetAttribute()whilegetAttribute()can return attributes set through various other (internal) means.