We have an application controller that serves various kinds of content, some public and some protected. Hence, we need to leave the endpoint unprotected, yet with the option to require authentication when needed, pseudo-like this:
The questions are like this:Code:public serverContent (request, response) { if (hasInsufficientAuthentication()) { // Option 1: Works, unless you capture exceptions for display (SimpleMappingExceptionResolver) throw new InsufficientAuthenticationException("You need to be authenticated!"); // Option 2: Don't know how to best find these beans, and don't know if this is a good way: ExceptionTranslationFilter etf = ...; // Where to find this? AuthenticationEntryPoint aep = etf.getAuthenticationEntryPoint(); // Or some other way? aep.commence (request, response, new InsufficientAuthenticationException("You need to be authenticated!")); return; } ... }
- What is the best way to solve this requirement (One of the above? Something else?)
- If #2, how do I best access the required beans?


Reply With Quote