gpt4 book ai didi

grails - 如何使用 Grails Spring Security 插件在访问操作之前要求登录?

转载 作者:行者123 更新时间:2023-12-02 15:03:13 27 4
gpt4 key购买 nike

我知道我可以使用注释或请求映射来限制某些特定角色对 ACTION 的访问。但现在我有不同的情况。

我的场景是:我网站的每个用户都可以发帖,他们可以自己发帖公共(public)、私有(private)或仅与其他一些用户共享 .我通过数据库表 PERMISSION 实现共享帖子,它指定用户是否有权查看帖子。

这里出现的问题是,当客户通过直接链接访问帖子时,我如何确定他/她有权查看它?有3种情况:

  1. The post is public, so it can be viewed by anyone (include not-login user)
  2. The post is private, so only the login-owner can view it
  3. The post is sharing, it means only the login-user that is shared and the owner can view it.


我想这样处理:

  1. If the requested post is public: ok.
  2. If the requested post is private/sharing: I want to redirect the customer to the login page; after logging in, the user will be re-direct to the page he wants to see.


这里的问题是我可以将用户重定向到登录 Controller /身份验证操作,但之后我不知道如何将其重定向回来。每个帖子的链接都因post_id而异,所以我不能使用 SpringSecurityUtils.securityConfig.successHandler.defaultTargetUrl
谁能知道这样做的方法?

最佳答案

不知道 grails,但 spring security 有一个 spring-security-redirect可用于在成功验证时将用户重定向到指定 url 的参数。

关于grails - 如何使用 Grails Spring Security 插件在访问操作之前要求登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4720292/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com