Плагин безопасности Spring: Ошибка аутентификации, AuthenticationProvider не найден

Я пытаюсь интегрировать плагин Spring Security Rest версии 1.4.1 в моем приложении grails, но, столкнувшись с какой-то проблемой, я делаю вот так:

Настройка config.groovy:

  //login end point
    grails.plugin.springsecurity.rest.login.active=true
    grails.plugin.springsecurity.rest.login.endpointUrl='/api/login'
    grails.plugin.springsecurity.rest.login.failureStatusCode='401'

    //for  memcached
    grails.plugin.springsecurity.rest.token.storage.useMemcached=true
    grails.plugin.springsecurity.rest.token.storage.memcached.hosts='localhost:11211'
    grails.plugin.springsecurity.rest.token.storage.memcached.username=''
    grails.plugin.springsecurity.rest.token.storage.memcached.password=''
    grails.plugin.springsecurity.rest.token.storage.memcached.expiration=3600

    //logout endpoint
    grails.plugin.springsecurity.rest.logout.endpointUrl='/api/logout'
    grails.plugin.springsecurity.rest.token.validation.headerName='X-Auth-Token'

    //accept request params as map
    grails.plugin.springsecurity.rest.login.useRequestParamsCredentials=true
    grails.plugin.springsecurity.rest.login.usernamePropertyName='username'
    grails.plugin.springsecurity.rest.login.passwordPropertyName='password'

и

grails.plugin.springsecurity.filterChain.chainMap = [
        '/api/guest/**': 'anonymousAuthenticationFilter,restExceptionTranslationFilter,filterInvocationInterceptor',
        '/api/**': 'JOINED_FILTERS,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter,-rememberMeAuthenticationFilter',  // Stateless chain
        '/**': 'JOINED_FILTERS,-restTokenValidationFilter,-restExceptionTranslationFilter'                                                                          // Traditional chain
]

Как вы можете видеть из настроек, я использую Memcache для хранения токенов, когда я нажимаю URL-адрес api/login через клиент отдыха, я получил 401. Я включил журналы, в которых говорится, что провайдер аутентификации не найден

Вот журналы:

2015-04-03 23:30:31,030 [http-bio-8080-exec-8] DEBUG matcher.AntPathRequestMatcher  - Checking match of request : '/api/login'; against '/api/guest/**'
2015-04-03 23:30:31,031 [http-bio-8080-exec-8] DEBUG matcher.AntPathRequestMatcher  - Checking match of request : '/api/login'; against '/api/**'
2015-04-03 23:30:31,031 [http-bio-8080-exec-8] DEBUG web.FilterChainProxy  - /api/login?username=abu.srs@gmail&password=test456 at position 1 of 8 in additional filter chain; firing Filter: 'RestLogoutFilter'
2015-04-03 23:30:31,031 [http-bio-8080-exec-8] DEBUG web.FilterChainProxy  - /api/login?username=abu.srs@gmail&password=test456 at position 2 of 8 in additional filter chain; firing Filter: 'MutableLogoutFilter'
2015-04-03 23:30:31,031 [http-bio-8080-exec-8] DEBUG web.FilterChainProxy  - /api/login?username=abu.srs@gmail&password=test456 at position 3 of 8 in additional filter chain; firing Filter: 'RestAuthenticationFilter'
2015-04-03 23:30:31,031 [http-bio-8080-exec-8] DEBUG rest.RestAuthenticationFilter  - Actual URI is /api/login; endpoint URL is /api/login
2015-04-03 23:30:31,031 [http-bio-8080-exec-8] DEBUG rest.RestAuthenticationFilter  - Applying authentication filter to this request
2015-04-03 23:30:31,031 [http-bio-8080-exec-8] DEBUG credentials.RequestParamsCredentialsExtractor  - Extracted credentials from request params. Username: abu.srs@gmail, password: [PROTECTED]
2015-04-03 23:30:31,032 [http-bio-8080-exec-8] DEBUG credentials.RequestParamsCredentialsExtractor  - pswrd:  test456
2015-04-03 23:30:31,032 [http-bio-8080-exec-8] DEBUG rest.RestAuthenticationFilter  - Trying to authenticate the request: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@fdd5153a: Principal: abu.srs@gmail; Credentials: [PROTECTED]; Authenticated: false; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Not granted any authorities
2015-04-03 23:30:31,051 [http-bio-8080-exec-8] DEBUG rest.RestAuthenticationFilter  - Authentication failed: No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken
2015-04-03 23:30:31,051 [http-bio-8080-exec-8] DEBUG rest.RestAuthenticationFailureHandler  - Setting status code to 401
2015-04-03 23:30:31,051 [http-bio-8080-exec-8] DEBUG rest.RestAuthenticationFilter  - Not authenticated. Rest authentication token not generated.

Еще один момент: если я сделаю запрос типа localhost:8080/restspring/api/guest/controller/action (для запроса без аутентификации), нужно ли мне сделать для этого некоторую запись в сопоставлении URL-адресов? Мое приложение использует настраиваемого поставщика проверки подлинности. Любая идея будет полезна для меня, спасибо.


person Abs    schedule 03.04.2015    source источник
comment
Какая у вас версия Grails?   -  person Ramsharan    schedule 06.04.2015
comment
Я использую grails версии 2.4.3. Если вам нужна другая информация, пожалуйста, дайте мне знать, спасибо.   -  person Abs    schedule 06.04.2015
comment
Вы установили Memcached на свой компьютер? alvarosanchez.github. io / grails-spring-security-rest / 1.5.0.RC1 / И не смотрите на 401. Этот код вы берете при возникновении ошибок во время входа в систему (вы настраиваете его в конфигурации). Последний, если вы пропустите эту вещь.   -  person Koloritnij    schedule 07.04.2015
comment
Если с предыдущим все в порядке, не могли бы вы показать свой urlMapping и контроллер (если не по умолчанию)   -  person Koloritnij    schedule 07.04.2015
comment
@Abs вы сказали, что ваше приложение использует настраиваемого поставщика проверки подлинности, можете ли вы его расширить и сообщить нам, что делает ваше приложение, как / где вы зарегистрировали настраиваемого поставщика проверки подлинности и т. Д.   -  person Sudhir N    schedule 07.04.2015


Ответы (1)


Провайдер аутентификации не найден

Проблема может заключаться в том, что вы всегда возвращаете false в методе supports () вашего провайдера аутентификации.
Ссылка: Не найден AuthenticationProvider для UsernamePasswordAuthenticationToken

Если я сделаю запрос, например localhost: 8080 / restspring / api / guest / controller / action (для запроса без аутентификации), мне нужно сделать для этого некоторую запись в сопоставлении URL-адресов?

Да, вам нужно сделать некоторую запись в сопоставлении URL-адресов. Поскольку сопоставление URL-адресов по умолчанию:

"/$controller/$action?/$id?(.$format)?"{
            constraints {
                // apply constraints here
            }
        }

Это не может сгенерировать нужный вам URL, например localhost:8080/restspring/api/guest/controller/action

person Ramsharan    schedule 13.04.2015