Aucun AuthenticationProvider trouvé pour UsernamePasswordAuthenticationToken

ma configuration web.xml est

 springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy   springSecurityFilterChain /*  

voici ma configuration de sécurité

         

Voici ma classe customAuthProvider

 public class MyAuthProvider implements AuthenticationProvider { @Override public boolean supports(Class arg0) { // TODO Auto-generated method stub return false; } @SuppressWarnings("serial") private static Map SIMPLE_USERS = new HashMap(2) {{ put("joe", "joe"); put("bob", "bob"); }}; @SuppressWarnings("serial" ) private static List AUTHORITIES = new ArrayList(1) {{ add(new GrantedAuthorityImpl("ROLE_USER")); }}; @Override public Authentication authenticate(Authentication auth) throws AuthenticationException { // All your user authentication needs System.out.println("==Authenticate Me=="); if (SIMPLE_USERS.containsKey(auth.getPrincipal()) && SIMPLE_USERS.get(auth.getPrincipal()).equals(auth.getCredentials())) { return new UsernamePasswordAuthenticationToken(auth.getName(), auth.getCredentials(), AUTHORITIES); } throw new BadCredentialsException("Username/Password does not match for " + auth.getPrincipal()); } } 

La page affiche le formulaire de connexion et lorsque je saisis bob and bob en tant que login, le message d’erreur suivant s’affiche.

 Your login attempt was not successful, try again. Reason: No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken 

J’ai vérifié les journaux au niveau de débogage ALL et voici ce que je reçois.

 FINE: Request is to process authentication Nov 17, 2011 5:37:36 AM org.springframework.context.support.AbstractApplicationContext publishEvent FINEST: Publishing event in Root WebApplicationContext: org.springframework.security.authentication.event.AuthenticationFailureProviderNotFoundEvent[source=org.springframework.security.authentication.UsernamePasswordAuthenticationToken@ffff8dfd: Principal: sd; Credentials: [PROTECTED]; Authenticated: false; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffe3f86: RemoteIpAddress: 127.0.0.1; SessionId: x4lg4vtktpw9; Not granted any authorities] Nov 17, 2011 5:37:36 AM org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter unsuccessfulAuthentication FINE: Authentication request failed: org.springframework.security.authentication.ProviderNotFoundException: No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken 

Toute aide sur ceci..que je fais mal ici?

Comme vous l’avez déjà écrit dans votre commentaire, le problème est que vous renvoyez toujours false dans la méthode supports() de votre fournisseur d’authentification. Mais au lieu de toujours renvoyer true vous devriez vérifier l’ authentication vous obtenez comme ceci:

 public class MyAuthenticationProvider implements AuthenticationProvider, Serializable { @Override public boolean supports(Class authentication) { return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication)); } // ... }