Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在grails中阻止对特定URL的访问_Url_Grails_Spring Security - Fatal编程技术网

如何在grails中阻止对特定URL的访问

如何在grails中阻止对特定URL的访问,url,grails,spring-security,Url,Grails,Spring Security,我有类似的URL 公司可以创建帐户,然后创建联系人。它生成URL中使用的联系人id。任何一家公司都可以访问另一家公司的联系人,只需将id替换为一个随机数字,如 如何防止一家公司访问另一家公司的联系人。而且,如果该id不在数据库中,它将显示错误。如果id不存在,我如何重定向到404页面 我将Grails2.2.1与spring security一起使用。我试着用requestmap来解决这个问题 def structureMap2 = Requestmap.findByUrl("cont

我有类似的URL

公司可以创建帐户,然后创建联系人。它生成URL中使用的联系人id。任何一家公司都可以访问另一家公司的联系人,只需将id替换为一个随机数字,如

如何防止一家公司访问另一家公司的联系人。而且,如果该id不在数据库中,它将显示错误。如果id不存在,我如何重定向到404页面

我将Grails2.2.1与spring security一起使用。我试着用requestmap来解决这个问题

    def structureMap2 = Requestmap.findByUrl("contacts/contactProfile/*") ?: new Requestmap(url: "contacts/contactProfile/*",configAttribute: "ROLE_COMPANY").save(failOnError:true)
但它不起作用

如果我必须重新构造URL,我该怎么做。或者还有其他方法。多谢各位

好吧,我会用Contacts/contactProfile控制器方法来做。 检查访问它的用户是否有权打开它。如果是,则呈现页面,如果不是,则返回flash.error或任何其他,并重定向到404。大概是这样的:

def contactProfile() {
    def user = = springSecurityService.currentUser
    def contact = Contact.get(params.id)
    if (!contact) {
        flash.error = "There is no such contact!"
        redirect(controller: "errors", action: "404")
    } else if (contact.company.id == user.company.id) {
        //create the stuff
        [contact: contact] //render the page
    } else {
        flash.error = "You are not authorised to view this contact!"
        redirect(controller: "errors", action: "404")
    }
}
这是在假设您已将公司分配给用户,并且联系人也有为其创建的公司的情况下编写的