0

In url mappings:

     "/$controller/$action?/$id?"{
                constraints {
                // apply constraints here
                }
     }
    "/index"(controller: 'home', action: 'index')
    "/"(controller: 'home', action: 'index')

If the user uses index with the root url it redirects fine.

Controllers + action redirects fine.

But the root ("/") itself does not redirect to the home controller.

I'm also using spring security

grails.plugin.springsecurity.controllerAnnotations.staticRules = [
    [pattern: '/',               access: ['permitAll']],
    [pattern: '/index',          access: ['permitAll']]
]

What simple thing am I missing?

David Brown
  • 3,021
  • 3
  • 26
  • 46
user2782001
  • 3,380
  • 3
  • 22
  • 41
  • You said that a request to `/` does not redirect to the home controller but didn't say what actually does happen. Are you getting a 401? – Jeff Scott Brown Aug 19 '19 at 17:11
  • No. It just loads the default welcome to grails page for "/" but for "/index redirects as told. – user2782001 Aug 20 '19 at 01:01
  • I removed my answer below because after posting it I realized that you are using Spring Security. I am not sure if that is relevant and there isn't enough info in the question to know for sure. What version of the Spring Security plugin are you using and is the `controllerAnnotations.staticRules` property you show in the question the only Spring Security related config in the project? – Jeff Scott Brown Aug 20 '19 at 18:29

3 Answers3

2

For me this was caused by introducing org.grails.plugins:grails-google-visualization:2.2.1 in Grails 4.0.0.

Did not find a workaround other than disabling the grails-google-visualization plugin.

It appears that the plugin modifies/overwrites UrlMapping.

doelleri
  • 19,232
  • 5
  • 61
  • 65
  • It appears that the grails-spring-security-saml plugin (version 4.0.0) does this as well. I'm opening an issue with that plugin. – jnunderwood Oct 04 '19 at 15:20
  • The grails-spring-security-saml plugin has been updated (version 4.0.1) and fixes this problem. – jnunderwood Oct 08 '19 at 15:06
1

I've hit the same issue mapping the root, the only workaround I've found so far is to replace the controller and action with a uri: , e.g.

"/"(uri: "/home/index") // in place of (controller: 'home', action: "/index")

David Brown
  • 3,021
  • 3
  • 26
  • 46
-1

The most likely reason is that you have missed to permitAll /home/index in the staticRules in the config. Spring Security follows the pessimistic lockdown approach to deny access to all URLs by default.

Imran Mir
  • 79
  • 3