2011-11-17 4 views
11

ma config web.xml estAucun AuthenticationProvider trouvé pour UsernamePasswordAuthenticationToken

<filter> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
    </filter> 

    <filter-mapping> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

ici est ma config de sécurité

<intercept-url pattern="/*" access="ROLE_USER" /> 
    <intercept-url pattern="/*.ico" filters="none" /> 


</http> 

<beans:bean id="customAuthenticationProvider" class="net.spring3.provider.MyAuthProvider" /> 

    <authentication-manager> 

     <authentication-provider ref="customAuthenticationProvider" /> 

    </authentication-manager> 

Voici ma classe customAuthProvider

public class MyAuthProvider implements AuthenticationProvider { 


    @Override 
    public boolean supports(Class<? extends Object> arg0) { 
     // TODO Auto-generated method stub 
     return false; 
    } 


    @SuppressWarnings("serial") 
     private static Map<String, String> SIMPLE_USERS = new HashMap<String, String>(2) {{ 
      put("joe", "joe"); 
      put("bob", "bob"); 
     }}; 

     @SuppressWarnings("serial") 
     private static List<GrantedAuthority> AUTHORITIES = new ArrayList<GrantedAuthority>(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 quand je saisis Bob et Bob comme connexion, l'erreur suivante apparaît. 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.springframew[email protected]ffff8dfd: Principal: sd; Credentials: [PROTECTED]; Authenticated: false; Details: org.sprin[email protected]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 ce .. qu'est-ce que je fais mal ici?

+0

Juste après affichage this.I lecture de doc ressort que la méthode doit renvoyer true pour indiquer que le fournisseur prend en charge l'authentification. Et je revenais faux !!! , Je l'ai juste changé pour vrai et ma première connexion d'application de sécurité de printemps fonctionne avec succès! J'espère que cette information sera utile pour tous ceux qui ont été coincés comme moi. @Override supports booléens publics (classe arg0) { // TODO Stub de méthode généré automatiquement return true; } – cherit

Répondre

29

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

public class MyAuthenticationProvider implements AuthenticationProvider, Serializable { 

    @Override 
    public boolean supports(Class<? extends Object> authentication) { 
     return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication)); 
    } 

    // ... 
} 
Questions connexes