I am working on a project using Netbeans with Glassfish 3.1 and am trying to implement LDAP authorization. To do so, I also have an LDAP-enabled Apache2 server using mod_jk. The gist is, when an user visits any page on the site in the /sng/ directory, the Apache server should ask for credentials and forward the user to the Glassfish server that is running that part of the site.
Apache is properly queueing for, and accepting, LDAP credentials and then forwarding the user to the appropriate area. But it seems that the REMOTE_USER variable is either not being set by Apache and/or not sent by mod_jk. Related configuration files and code snippets follow:
httpd.conf
<Location />
AuthBasicProvider ldap
AuthLDAPURL ldap://mainframe/ou=People,dc=dtch,dc=com?uid?sub
AuthzLDAPAuthoritative off
AuthType Basic
AuthName "LDAP"
require valid-user
Options Indexes FollowSymLinks MultiViews +Includes
</Location>
conf.d/jk
JKWorersFile /path/to/workers.properties
JkShmFile /path/to/mod_jk.shm
JkLogFile /path/to/mod_jk.log
JkLogLevel info
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
workers.properties
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=127.0.0.1
worker.worker1.type=ajp13
sites-enabled/000-default
...
JkMount /*.jsp worker1
JkMount /sng/* worker1
web.xml
<filter>
<filter-name>RemoteUser</filter-name>
<filter-class>path.to.RemoteUser</filter-class>
</filter>
<filter-mapping>
<filter-name>RemoteUser</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
RemoteUser.java
//...
public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain )
throws IOException, ServletException
{
if( request instanceof HttpServletRequest )
{
HttpServletRequest httpServletRequest = ( HttpServletRequest )request;
String username = httpServletRequest.getHeader( "REMOTE_USER" );
if( username == null )
{
// enter here every time
}
// ...
}
//...
}
Finally I have registered a listener in the Glassfish control panel:
In short, I have no idea why null is being returned constantly and my searches on the internet have been of no help. Thanks in advance for any input you may provide.
note: httpServletRequest.getRemoteUser( )
provides the same null result.
I was never able to retrieve a RemoteUser header, but I found a work-around in the form of the authorization
header. Using getHeader( "authorization" )
returned to me a string in the form of:
Basic XXXX:YYYY
Where X is the username, and Y the password of the user accessing the page through Apache/mod_jk.
The portion of the string following 'Basic ' (X:Y) was Base64 encoded, so after decoding it with MiGBase64 I was finally provided with an username that I could use.