是否可以在 grails 中分离常规 UrlMappings 和反向 UrlMappings ?
我有一个问题。对于许多现有链接,出于安全原因,我想添加加盐哈希。我不想查找和更改所有现有链接。真的,我很想在 UrlMappings 中解决这个问题。
这是适用于匹配传入请求的东西:
"/foo/$key/$hash" {
controller = "foo"
action = "bar"
}
这是适用于反向映射(createLink)的东西:
"/foo/$key/${DigestUtils.shaHex("$salt$key")}" {
controller = "foo"
action = "bar"
}
我似乎无法弄清楚如何将这两者结合在一起,或者如何让一个人处理传入请求和其他createLinks。
有什么想法吗?
I've got a problem. For a lot existing links, I'd like to add a salted hash for security reasons. I don't want to look up and change all existing links. Really, I'd love to solve this just in UrlMappings.
Here's something that works for matching incoming requests:
"/foo/$key/$hash" {
controller = "foo"
action = "bar"
}
Here's something that works for the reverse mapping (createLink):
"/foo/$key/${DigestUtils.shaHex("$salt$key")}" {
controller = "foo"
action = "bar"
}
What I can't seem to figure out is how to combine these two in one, or how to have one handle the incoming requests and the other the createLinks.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是创建一个自定义标签(在 TagLib 中),该标签将添加哈希值并环绕 createLink。
所以基本上
createHashLink = { attrs ->
然后
,在您的代码中,您可以调用 g.createHashLink( ... ) ,其工作方式与 createLink 相同。
One way to do it is to create a custom tag ( in a TagLib ) that will add the hash values and wrap around createLink.
So basically
createHashLink = { attrs ->
}
In your code, you can then just call g.createHashLink( ... ) which will work in the same way as createLink.