michalv82
michalv82

Reputation: 1979

configure tomcat for client authentication only for specific URL patterns

I have an application with a few war files all deployed on the same tomcat server. I need to force client authentication only for one war context, and only for a specific URL.

I've read a lot on the web and similar questions here, but the conclusions I've reached are not matching the solution I need:

  1. define 2 connectors with different ports (one with clientAuth enabled and one without) and access the specific URL with the relevant port ==> this solution is not good since if a hacker tries to access this URL with the other port he can succeed
  2. define transport-guarantee in web.xml (for example Enabling mutual SSL per service in Tomcat) ==> this is also not good since I don't want to define users in some realm, I just want the server to ask for the client certificate and verify it is trusted and valid.

Is there a way to use option 2 without defining users? Or maybe a third option?

Thanks in advance!

Upvotes: 3

Views: 4810

Answers (2)

Oliv
Oliv

Reputation: 10812

If you want to accept any certificate from trusted CAs, just put clientAuth="want" to Connector and write a filter to check, if a certificate was sent. Assign that filter to desired web app only. In the filter, get the certificate using:

request.getAttribute("javax.servlet.request.X509Certificate");

and check it's CA.

But remember, that any certificate from that CA will allow access. If this is a public CA, anyone can buy one and access your app. You should always check the DN, in Tomcat you do this by defining a user, or manually in a filter.

Upvotes: 1

user207421
user207421

Reputation: 310840

You can't do this in pure Tomcat. The best solution is to put an Apache HTTP in front of it, that terminates the SSL connection, and in which you can configure SSL to your heart's content right down to the level of an individual directory.

Upvotes: 1

Related Questions