0

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?

AlbeyAmakiir
  • 2,217
  • 6
  • 25
  • 48
  • So, I should have learnt by now that, if something seems impossible, then it means something is wrong somewhere else. I found the solution, but now I know the question is wrong, and not useful to anyone. – AlbeyAmakiir Apr 18 '13 at 23:45

1 Answers1

0

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
Michael
  • 10,063
  • 18
  • 65
  • 104
  • I have been reading that, and I don't actually agree. It's been extremely hard to find what I want. Most of my successes have come from elsewhere. Also, that code you posted is _exactly_ what I have, minus the `SuppressWarnings`. Did you actually read the question? – AlbeyAmakiir Apr 16 '13 at 06:10
  • Yes :). Remove SuppressWarnings. I have created couple of providers in my life :) – Michael Apr 16 '13 at 06:11
  • As I thought, removing the annotation made no difference, because the annotation doesn't affect the code's behaviour once built. – AlbeyAmakiir Apr 17 '13 at 22:30