Search code examples
javaglassfishpath-finding

Java EE, differentiate context by path


I'm working on a workaround for the problem, that glassfish does not support individual certificates for virtual hosts.

My Application is supposed to be running context dependent based on which customer wants access to his data. I actually wanted to use seprarate domains for that, but since that is not possible, i've come up with a different idea:

I want to differentiate customers by the path they are entering. For example: www.application.com/customer1/pages/page.jsf or www.application.com/customer2/pages/page.jsf

But i dont know how to implement that. As far as i know, these adresses indicate paths on the webserver. Can i somehow do this, with the application still finding the pages?

Preferebly i want to store these entries (customer1 and customer2) in an external file so i can add a new entry without having to touch the code.


Solution

  • I'm assuming you mean SSL certificates. I would consider setting up a reverse proxy that handles the multiple domains and their SSL encryption and forwards the requests to normal HTTP on Glassfish.

    In the application itself the distinction by customers can be made via the login they use (roles/groups, ...). If simply using a path or domain to distinguish it's quite easy to access secured resources from different customers. If you want to have the domain information you can simply add a header in the proxy server to the incoming HTTP request.

    As for candidates for such a proxy I can recommend NGINX which is easy to set up. You can also use Apache or many others for doing so.