Change tomcat filter from NTLMv1 to NTLMv2 or Kerberos

We have an old Application running on Tomcat 5.5 that uses a NTLMv1 filter to verify the users.
We need to upgrade the JAVA filter to use NTLMv2 or Kerberos.

The NTLM code from the filter is included below:

//NLTM Module here
                  String auth = request.getHeader("Authorization");
                  
                  if (auth == null)
                  {
                    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
                    response.setHeader("WWW-Authenticate", "NTLM");
                    //response.flushBuffer();
                    LogManager.debug("First Authentication check failed",AuthenticationFilter.class);
                    return;
                  }
                  if (auth.startsWith("NTLM"))
                  {
                    byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
                    LogManager.debug("NTLM response="+new String(msg, Charset.forName("ISO-8859-1")),AuthenticationFilter.class);
                    int off = 0, length, offset;
                    if (msg[8] == 1)
                    {
                        LogManager.debug("Second Authentication check failed",AuthenticationFilter.class);
                      byte z = 0;
                      byte[] msg1 = {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S', (byte)'S', (byte)'P', z,(byte)2, z, z, z, z, z, z, z,(byte)40, z, z, z, (byte)1, (byte)130, z, z,z, (byte)2, (byte)2, (byte)2, z, z, z, z, z, z, z, z, z, z, z, z};
                      response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
                      response.setHeader("WWW-Authenticate", "NTLM " + new sun.misc.BASE64Encoder().encodeBuffer(msg1).trim());
                      //response.flushBuffer();
                      //response.sendError(response.SC_UNAUTHORIZED);
                      LogManager.debug("Sending unauthorized and flushing buffer",AuthenticationFilter.class);
                      return;
                    }
                    else if (msg[8] == 3)
                    {
                        LogManager.debug("Third Authentication check passed",AuthenticationFilter.class);
                      off = 30;
            
                      //get details
                      length = msg[off+17]*256 + msg[off+16];
                      offset = msg[off+19]*256 + msg[off+18];
                      remoteHost = cleanString(new String(msg, offset, length));
            
                      length = msg[off+1]*256 + msg[off];
                      offset = msg[off+3]*256 + msg[off+2];
                      domain = cleanString(new String(msg, offset, length));
            
                      length = msg[off+9]*256 + msg[off+8];
                      offset = msg[off+11]*256 + msg[off+10];
                      username = cleanString(new String(msg, offset, length));
                        
                        LogManager.info(new StringBuilder("User [").append(username).append("] NTLM Authenticated...domain[").append(domain).append("] RemoteHost: [").append(remoteHost).append("]").toString(),AuthenticationFilter.class);
                    
                  //Userid check here
dbasplusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gheistCommented:
It is not far sighted to call NTLM function from application.
One can set up any of windows-friendly per-tomcat authentication modules and application just neutrally request authentication:
https://tomcat.apache.org/tomcat-7.0-doc/windows-auth-howto.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
btanExec ConsultantCommented:
will suggest go for Kerberos (need AD or LDAP directory store) if possible as compared to NTLM as the latter is weaker for v2 using HMAC-MD5. May want to check out  http://spnego.sourceforge.net/spnego_tomcat.html tutorial to try to config Tomcat to use spnego. Some run through stated http://webmoli.com/2009/08/29/single-sign-on-in-java-platform/
0
dbasplusAuthor Commented:
Go with Waffle.
Add the jar files to the lib directory of the webapp.
Update the web.xml for the webapp (use the example from the Waffle website).
Thats it.
We had to remove the previous bit of code (above) that did the authentication as Waffle handles this amazingly well.
To just use NTLM (NTMLv1 or NTMLv2 what ever is available) change the protocol in the setup.
We tried countless other solutions and this was just too simple not to use. We had an old versions of Tomcat and Java that were also handles without updating. Thank you to all the people who contributed to these libraries.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.