How to override URL mapping taken by a plugin in Grails 4?

354 Views Asked by At

In Grails 3.3 I was using a custom extension of RestOauthController from spring-security-rest:2.0.0.M2 plugin, which I'd overriden in UrlMappings.groovy like this:

"/oauth/access_token"(controller: "restOauthMy", action: "accessToken", method: "POST")

However, after upgrading to Grails 4, a POST request to /oauth/access_token now leads to the original controller, my RestOauthMyController.accessToken() is never called. Is there a way to get rid of the original URL mapping? More generally, what determines priority of conflicting URL mappings in Grails?

2

There are 2 best solutions below

6
andysh On

I found a functional workaround adding the URL mapping dynamically in BootStrap.groovy:

def grailsUrlMappingsHolder

def init = {
    grailsUrlMappingsHolder.addMappings {
        "/oauth/access_token" (controller: "restOauthMy", action: "accessToken", method: "POST")
    }
}

This way the dynamic mapping seems to take priority and my overriden code executes.

I would very much like to know how to do this properly, though.

2
Orubel On

So in looking over the Grails 4.0 code (and other plugins), this appears to be a VERY HARDCODED endpoint specific to spring-security-rest which was discontinued and brought in-house

So until they fix their issue, you have the best workaround. Still... this is a bug that they have yet to fix as functionality DID WORK in 3.0 when spring-security-rest was a separate plugin and now it is BORKED!