Grails 3.0.1 here. I'm looking to accomplish a specific URL/controller structure. My app deploys at the root context (/
), meaning locally it runs as http://localhost:8080
, and non-locally as http://someserver.example.org
.
I want everything under /app/*
to be authenticated and considered to be part of the "core app" (requires login). Anything outside of that URL is considered to be a part of the public website (unauthenticated). However, I want /app/
itself to just be a placeholder of sorts; I do not want it to be a Grails controller. Hence:
http://localhost:8080/app
may be configured (UrlMappings
?) to bring up a login pagehttp://localhost:8080/app/<controller>/<action>
follows typical Grails controller/action suit, and would invoke the correct controller actionHence http://localhost:8080/app/order/create
would be authenticated and, if logged in, invoke the OrderController#create
action, which might render a createOrder.gsp
.
I'm wondering what the Grails 3.x approach is to:
/app/
to exist, but not as a controller (like I said, perhaps just redirecting/mapping to a login page)/app/
to follow the controller/action paradigmThoughts on how to implement this?
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
}
"/app/$controller/$action?/$id?" {
???
}
"/"(view:"/index")
"500"(view:'/error')
"404"(view:'/notFound')
}
}
Grails has the possibility to declare namespaces for Controllers. With this, you can put all your controllers under the namespace 'app', which should result in exactly your second question. See docs for more details.
The security restriction then be accomplished with normal spring security settings (@Secured
e.g).