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'],
]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…