2017-07-28 42 views
0

Iam在我的grails 3.2.7應用程序中使用spring-security-core 3.1.1。我只是想訪問我projectconfiguration.gsp,爲了這個,我添加了以下映射urlMapping中在grails中的URL訪問被拒絕spring-security

"/confproject"(view: '/project/projectconfiguration') 

但它顯示爲您無權訪問此頁面

我知道這事因爲我沒有爲這個URL指定任何訪問規則。所以我在application.groovy中添加了以下行:

grails.plugin.springsecurity.controllerAnnotations.staticRules = [ [pattern: '/confproject', access: ['ROLE_ADMIN']] ] 

但是仍然面臨未經授權的訪問消息。

爲什麼上面的訪問規則是註釋工作?

我知道如果我通過控制器訪問GSP,並給該控制器添加@Secured註釋將可以正常工作。

但這是唯一的方法嗎?

注意:我不想使用interceptUrlMap方法。

+0

首先,你必須在靜態映射語法錯誤 - 你缺少等號 - 使用它像grails.plugin.springsecurity。 controllerAnnotations.staticRules = [] - 並確保您使用的用戶具有ADMIN角色。還要確保在/ confproject之前沒有另外的安全規則/ **它也會覆蓋/ confproject –

+0

抱歉失蹤=符號是一個錯字,我更新了這個問題。我正在使用具有ADMIN角色的用戶,並且在我的規則之上沒有//confproject之類的規則,例如/ **。 –

+0

嘗試'/ confproject/**',作爲你的模式 –

回答

0

這是爲我工作。

UrlMappings.groovy

"/newsletter"(view: "/pages/newsletter") 

application.groovy

grails.plugin.springsecurity.controllerAnnotations.staticRules = [ 
    ... 
    [pattern: '/pages/**', access: ['permitAll']], 
    ... 
]