복붙노트

[SPRING] UsernamePasswordAuthenticationToken에 대한 AuthenticationProvider가 없습니다.

SPRING

UsernamePasswordAuthenticationToken에 대한 AuthenticationProvider가 없습니다.

내 web.xml 설정은 다음과 같습니다.

<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>

여기에 내 보안 설정이있다.

    <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>

다음은 내 맞춤 AuthProvider 클래스입니다.

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());
        }




}

이 페이지는 로그인 양식을 보여 주며 로그인으로 bob 및 bob을 입력하면 다음 오류가 발생합니다.

Your login attempt was not successful, try again.

Reason: No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken

디버그 레벨 ALL에서 로그를 확인했는데 여기에 있습니다.

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

이것에 대한 어떤 도움이 .. 내가 여기서 뭐하고 있는거야?

해결법

  1. ==============================

    1.여러분이 이미 여러분의 코멘트에 쓴 것처럼, 문제는 여러분이 autentication provider의 supports () 메소드에서 항상 false를 반환한다는 것입니다. 그러나 항상 true를 반환하는 대신 다음과 같이 인증을 확인해야합니다.

    여러분이 이미 여러분의 코멘트에 쓴 것처럼, 문제는 여러분이 autentication provider의 supports () 메소드에서 항상 false를 반환한다는 것입니다. 그러나 항상 true를 반환하는 대신 다음과 같이 인증을 확인해야합니다.

    public class MyAuthenticationProvider implements AuthenticationProvider, Serializable {
    
        @Override
        public boolean supports(Class<? extends Object> authentication) {
            return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
        }
    
        // ...
    }
    
  2. from https://stackoverflow.com/questions/8162698/no-authenticationprovider-found-for-usernamepasswordauthenticationtoken by cc-by-sa and MIT license