如何制作Grails';的Spring Security Core根据拒绝访问的原因呈现不同的页面
我正在使用SpringSecurityCore插件运行一个Grails应用程序 当已经登录的用户试图在没有访问权限的情况下访问某个页面时,将始终调用UrlMappings.groovy中配置为如何制作Grails';的Spring Security Core根据拒绝访问的原因呈现不同的页面,grails,spring-security,grails-2.0,grails-spring-security,Grails,Spring Security,Grails 2.0,Grails Spring Security,我正在使用SpringSecurityCore插件运行一个Grails应用程序 当已经登录的用户试图在没有访问权限的情况下访问某个页面时,将始终调用UrlMappings.groovy中配置为403的相同操作 我一直在努力使我的应用程序根据拒绝访问的原因呈现不同的页面。例如:如果已通过身份验证\u需要完全,我希望将用户重定向到一个表单,以便他可以重新进行身份验证。如果需要一个特定的角色,但不存在,我想将用户重定向到一个页面,在那里他可以请求这个角色。等等 有人知道如何存档吗 ==========
403
的相同操作
我一直在努力使我的应用程序根据拒绝访问的原因呈现不同的页面。例如:如果已通过身份验证\u需要完全
,我希望将用户重定向到一个表单,以便他可以重新进行身份验证。如果需要一个特定的角色,但不存在,我想将用户重定向到一个页面,在那里他可以请求这个角色。等等
有人知道如何存档吗
========================================更新==================================
我试图通过授权来解决这个问题t上描述的回调。不幸的是,不管触发它的规则是什么,事件参数总是相同的
至少我可以访问被拒绝访问的URI。有没有办法从URI中获取安全规则,以便与当前用户的角色和状态进行比较,并找出缺少的内容?这可能会解决问题。可能会在那里创建控制器和访问异常
static mappings = {
//....
"403"(controller:'error', action:'error403')
//......
}
class ErrorController {
def error403() {
def message = request.exception?.cause?.message; //access message and render right view
}
}
通过互联网进行了长时间的研究后,终于从@yariash的回复中获得了一些想法,并: 最后,在我的错误控制器中:
static mappings = {
//....
"403"(controller:'error', action:'error403')
//......
}
class ErrorController {
def error403() {
def missingAuthorities = request.getAttribute("MISSING_AUTHORITIES")
// Render the right view based on the missing authorities
}
}
嘿,谢谢你的快速回答。试过了。不幸的是,异常总是空的。我可以访问Spring Security在
onAuthorizationEvent
回调中抛出的AccessDeniedException
。但不管触发它的规则是什么,它都是一样的。我将编辑我的问题并提供更多详细信息。谢谢。就这么做了;)
beans = {
//...
authorizationFailureEventListener(AuthorizationFailureEventListener) { bean ->
bean.autowire = "byName"
}
//...
}
static mappings = {
//....
"403"(controller:'error', action:'error403')
//......
}
class ErrorController {
def error403() {
def missingAuthorities = request.getAttribute("MISSING_AUTHORITIES")
// Render the right view based on the missing authorities
}
}