grails 5 spring security 5 403错误页面

sycxhyv7  于 2023-10-20  发布在  Spring
关注(0)|答案(1)|浏览(155)

我正在使用Grails 5.2.5和Spring Security 5.6.0。当发生403时,拒绝访问的消息会写入浏览器文档中。我想显示一个403特定的视图页面。但它不起作用。代码如下:
URLMap:

'403'(controller: 'error', action: 'denied')

错误控制器拒绝操作:

def denied() {
    render(view: '/error/denied', model: [errorMessage: "403 sample error"])
}

拒绝查看错误目录下的页面:

<section class="content">
        <h1 style="color: red">${errorMessage}</h1>
    </section>

但它不起作用。相反,它会向浏览器写入以下消息:

Access to localhost was denied 
You don't have authorization to view this page.
HTTP ERROR 403

groovy应用程序>>

// Added by the Spring Security Core plugin:
grails.plugin.springsecurity.userLookup.userDomainClassName = 'com.org.auth.User'
grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'com.org.auth.UserRole'
grails.plugin.springsecurity.authority.className = 'com.org.auth.Role'
grails.plugin.springsecurity.requestMap.className = 'com.org.auth.Requestmap'
grails.plugin.springsecurity.securityConfigType = 'Requestmap'
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
    [pattern: '/',               access: ['permitAll']],
    [pattern: '/error',          access: ['permitAll']],
    [pattern: '/index',          access: ['permitAll']],
    [pattern: '/index.gsp',      access: ['permitAll']],
    [pattern: '/shutdown',       access: ['permitAll']],
    [pattern: '/assets/**',      access: ['permitAll']],
    [pattern: '/**/js/**',       access: ['permitAll']],
    [pattern: '/**/css/**',      access: ['permitAll']],
    [pattern: '/**/images/**',   access: ['permitAll']],
    [pattern: '/**/favicon.ico', access: ['permitAll']]
]

grails.plugin.springsecurity.filterChain.chainMap = [
    [pattern: '/assets/**',      filters: 'none'],
    [pattern: '/**/js/**',       filters: 'none'],
    [pattern: '/**/css/**',      filters: 'none'],
    [pattern: '/**/images/**',   filters: 'none'],
    [pattern: '/**/favicon.ico', filters: 'none'],
    [pattern: '/**',             filters: 'JOINED_FILTERS']
]

grails.plugin.springsecurity.logout.postOnly = false    // just for test

怎么办?!!

8ehkhllq

8ehkhllq1#

我通过这个stackoverflow.com链接找到了一个锻炼方法:configure in application.groovy
我不得不在application.groovy文件中添加这一行:
grails.plugin.springsecurity.adh.errorPage = null

相关问题