6

I am trying to integrate spring security rest plugin version 1.4.1 in my grails app, but facing some issue, I am doing like that:

Config.groovy setting:

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

and

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
]

As you can see from setting I am using Memcache for token storage, when I hit the url api/login via a rest client I got 401 I enabled the logs In which it says that Authentication provider not found

Here is the logs:

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.

My another point is that: If I make a request like localhost:8080/restspring/api/guest/controller/action (for non-authenticated request) do I need to do some entry in URL mapping for this?My application uses the custom authentication provider. Any idea will be helpful for me, thanks.

ABC
  • 4,263
  • 10
  • 45
  • 72
  • What is your grails version? – Ramsharan Apr 06 '15 at 02:13
  • I am using grails version 2.4.3, If you need any other information then please let me know, thanx. – ABC Apr 06 '15 at 05:57
  • Did you have installed Memcached on your pc? http://alvarosanchez.github.io/grails-spring-security-rest/1.5.0.RC1/docs/guide/tokenStorage.html#memcached And don't look on the 401. This code you take if some errors during logIn(you configure it in config). The last one if you miss this thing. – Koloritnij Apr 07 '15 at 12:38
  • If with previous all ok, so could you show your urlMapping and controller(if not default) – Koloritnij Apr 07 '15 at 13:58
  • @Abs you have said that your application uses custom authentication provider, can you expand this and let us know what your application is doing, how /where did you register the custom authentication provider etc. – Sudhir N Apr 07 '15 at 15:21

1 Answers1

0

Authentication provider not found

The problem can be that you always return false in the supports() method of your authentication provider.
Reference : No AuthenticationProvider found for UsernamePasswordAuthenticationToken

If I make a request like localhost:8080/restspring/api/guest/controller/action (for non-authenticated request) do I need to do some entry in URL mapping for this?

Yes you need to do some entry in url mapping. Because the default url mapping is :

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

This cannot generate the url needed for you i.e. localhost:8080/restspring/api/guest/controller/action

Community
  • 1
  • 1
Ramsharan
  • 2,054
  • 2
  • 22
  • 26