grails - Grails Spring安全性插件镜像访问控制

我正在尝试建立一个在线照片库,以便用户从其移动设备(如Android)将图像上传到服务器并可以访问它。
当前,我将Grails与Spring Security Plugin Core结合使用,并将所有上传的图像保存在/ web-app / uploaded-image的文件夹中。上载部分目前正在运行,我可以将图像从设备上载到服务器的上载图像文件夹。
但是,我有一个问题是,当前我正在Config.groovy中使用这些行来执行访问控制部分

grails.plugins.springsecurity.interceptUrlMap = [
/uploaded_image/**':['IS_AUTHENTICATED_REMEMBERED']
]

我计划让 Controller 将图像的路径与一个名为image的DomainClass关联,该DomainClass将与每个用户的DomainClass关联。
我的问题是,如何使非图像所有者的用户没有查看该图像的权限?
我尝试在Google搜索中找到答案,但没有找到很多有用的答案。
感谢您的时间。

最佳答案

您可以使用以下逻辑来确保不是图像所有者的用户没有查看图像的权限

class ImageController {


  def springSecurityService

  def showImage() {
  Image image=Image.get(parmas.long("id")

 // this is the user  who is trying to access image from ui
    User user = User.get(image.userId) 

 //this is the logged-in user       
  User logged = User.get(springSecurityService.principal.id)
   if (user.id != logged.id) {
  {
      redirect(action: "accessDenied", controller='access' id: params.long("id"))        
    //re-direct accessDenied page

 }else{
 //show image  
  }
  }

  Class AccessController{
 def accessDenied= {

    render(view: "accessDenied")

}
}

https://stackoverflow.com/questions/10038591/

相关文章:

grails - grails从 Controller 返回xml字符串

grails - Spock测试用例与Grails中的域类没有关系吗?

grails - 在这种情况下如何删除关系?

javascript - 将Javascript函数与Grails应用程序集成

spring - 是否使用基于注释的AOP修改 Controller 响应?

grails - 下拉菜单中的 Twitter Bootstrap 模式

grails - 如何在grails中进行网络搜索

json - 在Grails中编码Joda LocalTime

mongodb - 使用迭代动态构建条件 block

grails - Grails具有一个单向