I have an application with spring security installed and working well -- it is currently running out of www.exampledomain.com
.
I now want to expand the application running out of a subdomain. For example newapp.exampledomain.com
.
The only problem is that for this new app a user needs to log in. In spring it is very easy to intercept urls via <intercept-url pattern="/Admin/*" access="ROLE_GENERAL"/>
but what do you do when you want to intercept a subdomain for login? For example the following doesnt work for me:
<intercept-url pattern="http://newapp.exampledomain.com/*" access="ROLE_GENERAL"/>
Any thoughts on how to get around this?
One option would be to write your own AccessDecisionVoter which extends RoleVoter and adds an additional check based on the hostname. Something like this:
Then wire up your voter:
If you wanted to take it a step further you could also write your own configuration attributes which would allow you remove the hardcoded hostname checks in the voter and do something like:
In your session cookie, domain should be explicitly set to exampledomain.com.
Application server is responsible for session cookie creation (JSESSIONID) but not Spring Security.
All you have to do is to inform your app server that you want to always have the same domain in cookie.
Add to your web.xml: