1
votes

I’m trying to use Oauth2 in Grails but can’t get it working. When trying to get access point I have NullPointerException.
So more details: Using Spring Security Oauth2 Provider plugin. I have registered a client (with BaseClientDetails) in BootStrap.groovy and according to the tutorial the client could login with the URL given in the tokenEndpointUrl setting (/oauth/token by default) by using the following url: localhost:8080/app/oauth/token?grant_type=client_credentials&client_id=clientId&client_secret=clientSecret .

But grails.plugin.cache.web.filter.PageFragmentCachingFilter throws exception, in the method described bellow controllerClass is null for some strange reason.

841  protected Object lookupController(Class<?> controllerClass) { <br>
842  return getBean(controllerClass.getName()); <br>
843  }

and controller class is null because grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter trying to get controller class from context ( getContext().getControllerClass() ) but null is returned.
Full stack is here http://pastebin.com/euramNaS

When I passing regular login flow (not directly using URL but via login form). I have LoginController fetched in the same place. And when in debug mode I set breakpoint to the “problematic” line and manually change controllerClass with LoginController (adding controllerClass = LoginController.class to watch) it made the trick and I receive JSON with tokens.

Tried to make empty application to clearly reproduce the problem and it is reproduced. So test project could be found http://goo.gl/1gmtT .
Any ideas why controller could be not initialized when accessing url directly?

2

2 Answers

2
votes

Uninstalling cache plugin will do the trick. It might be possible to configure cache plugin to ignore

/oauth 

urls

0
votes

As @cubic1271 said upgrading cache plugin to 1.1.1 worked for me.

In BuildConfig.groovy be sure of that

compile ':cache:1.1.1'

Also you can check it using grails list-plugins in command line

$ grails list-plugins
Plug-ins you currently have installed are listed below:
-------------------------------------------------------------
cache               1.1.1            --  Cache Plugin