How can I dynamically build a list of mappings – instead of:
class UrlMappings {
static mappings = {
"/helpdesk/user/$action?/$id?" (controller="helpdeskuser")
"/helpdesk/group/$action?/$id?" (controller="helpdeskgroup")
"/helpdesk/company/$action?/$id?" (controller="helpdeskcompany")
"/helpdesk/account/$action?/$id?" (controller="helpdeskaccount")
"/admin/company/$action?/$id?" (controller="admincompany")
"/admin/account/$action?/$id?" (controller="adminaccount")
}
}
something like this pseudo code:
class UrlMappings {
static mappings = {
application.controllerClasses.each {
if(it.name.startsWith('helpdesk'))
"/helpdesk/${it.name}/$action?/$id?" (controller="${it.name}")
if(it.name.startsWith('admin'))
"/admin/${it.name}/$action?/$id?" (controller="${it.name}")
}
}
}
(I don’t understand what the static mappings are – a hash map? free variables?)
What I am trying to achieve are mappings based on the controller type – e.g. helpdesk, admin or user controllers. Once I have set up the mappings I want to add security based on URLs but I don’t want to map each controller individually:
grails.plugins.springsecurity.interceptUrlMap = [
'/helpdesk/**': ['ROLE_HELPDESK','ROLE_ADMIN'],
]
I’ve just done the following in my application:
I’d not actually done this before, your question prompted me to fix this is my app. It’s been one of those things I’ve been trying to do for a while.