We’re building a web application that is available to both authenticated and anonymous users. If you decide not to register/login you only have a limited set of features. User authentication is done over OpenID with Spring Security. That works fine.
However, the application also comes with an admin UI that is deployed at <host>/<context-root>/admin. Can we have two separate realms with Spring Security (e.g. basic auth for /admin/**)? How does that have to be configured?
Spring Security has added support for this scenario in version 3.1, which is currently available as a Release Candidate. It was implemented by SEC-1171 and details of the syntax are in the manual included with 3.1.
However it’s pretty simple to use. Basically you just define multiple
httpelements in your Spring Security configuration, one for each realm. We’re using it like this:The key thing to note is the
pattern="/admin/**"on the firsthttpelement. This tells Spring that all URLs under/adminare subject to that realm instead of the default realm — and thus URLs under/adminuse basic authentication instead.