views:

23

answers:

2

We're using Spring Security with RequestHeaderAuthenticationFilter, and thus relying on a HTTP header to be set for the user name. On our local machines we don't have the software for authenticating, and thus not the header.

When testing with WebDriver or FireFox we can set the header and test correctly, but when manually testing with Internet Explorer we're not able to set the header value.

Is there a good way to set header values in IE, or a decent way to enable some kind of 'mocking' for the filter in development and test?

A: 

Set the exceptionIfMissingHeader property on your Spring context.

From the javadoc: http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/authentication/preauth/RequestHeaderAuthenticationFilter.html

"If the header is missing from the request, getPreAuthenticatedPrincipal will throw an exception. You can override this behaviour by setting the exceptionIfMissingHeader property. "

Frederic Conrotte
Sorry for the slow response, thought I would get an email when replies was entered. That doesn't really authenticate a user, and I need authtenticated users. If none of the functionality was secured this would work, but not when you need to emulate a login. I ended up doing a lot of hacking to be able to switch betweene header authentication, and a login form. Not too impressed with the internals of Spring Security. It took me quite some time to figure out, and the solution didn't end up very nice.
Anders S
A: 

I ended up using a Spring Java config with a command line parameter for switching between header authentication, and authenticating with a login form.

It required switching between (mock left, real right):

  • UsernamePasswordAuthenticationFilter and RequestHeaderAuthenticationFilter
  • LoginUrlAuthenticationEntryPoint and Http403ForbiddenEntryPoint
  • DaoAuthenticationProvider and PreAuthenticatedAuthenticationProvider

Not too impressed with the internals of Spring Security, and it took me a good while to figure this out. But if you need to do it, at least those are some pointers.

Anders S