How do I get a custom Spring 2 Authentication Provider to accept a UsernamePasswordAuthenticationToken?

381 Views Asked by At

In Spring 2, I've created a custom authentication provider, because I can't grab the password out of the database like Spring seems to prefer, because there's a black box in the way. When I try to authenticate, I get:

No AuthenticationProvider found for org.springframework.security.providers.UsernamePasswordAuthenticationToken

I've put this bean in my security.xml:

<bean id="imsAuthProvider" class="com.terrapages.mokbeecds.ims.IMSAuthenticationProvider">
    <security:custom-authentication-provider />
</bean>

Which is, I believe, all I need. It should just grab the username and password from the form and pass it to my provider to deal with as it sees fit. I also have this in my customAuthenticationProvider:

public boolean supports(@SuppressWarnings("rawtypes") Class authentication) {
    return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
}

Which, as I understand it, is checked before giving the authentication token to the custom authentication provider. If it returns false, then Spring checks the next authentication provider.

The main authenticate(Authentication) method can only throw a BadCredentialsException or an AuthenticationServiceException, which, as I understand, should not cause the output above.

Information on Spring 2 is a little hard to find, with Spring 3 being everywhere at the moment.

How do I get my provider to accept the UsernamePasswordAuthenticationToken?

1

There are 1 best solutions below

3
On

Spring Security 2 is also documented pretty well: http://static.springsource.org/spring-security/site/docs/2.0.x/reference/html/springsecurity.html Please use the following support method:

public boolean supports(Class authentication) {
    return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
}

Edited

Suggestions:

  1. Remove your provider - the authentication should work. If not - fix the issue.
  2. Debug the authentication and supports method and see what is the problem