我的應用程序這個URL映射:Grails的春季安全RequestMap不匹配/
"/"(controller: 'app', action: 'index')
而且我使用域類來存儲RequestMap在數據庫實例。 對app/index的訪問僅限於某些角色,所以當用戶點擊/或/ app/index時,會顯示登錄表單。
當某個用戶有權查看/或/ app/index登錄時,該應用顯示一條消息:「對不起,您無權查看此頁面。」,所以由於某種原因,Spring Security不考慮我的RequestMaps。
我嘗試了很多組合,也許我錯過了一些東西。我現在所擁有的是(BootStrap.groovy中):
new RequestMap(url: '/', configAttribute: 'ROLE_ADMIN').save()
new RequestMap(url: '/app/index', configAttribute: 'ROLE_ADMIN').save()
new RequestMap(url: '/**', configAttribute: 'ROLE_ADMIN').save()
我使用的登錄已ROLE_ADMIN分配的用戶,這是在登錄控制檯日誌:
userDetails [email protected]:
Username: admin; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true;
credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN
auth [email protected]:
Principal: [email protected]:
Username: admin; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true;
credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN;
Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_ADMIN
僅供參考,我的定製登錄使用的用戶+傳球+組織,這就是爲什麼有一個UserPassOrgAuthToken而不是標準的UsernamePasswordAuthenticationToken
編輯
我也有rejectIfNoRule =真實defaultTargetUrl =「/應用/索引」,不知道這是什麼影響:
grails.plugin.springsecurity.rejectIfNoRule = true
grails.plugin.springsecurity.successHandler.defaultTargetUrl = '/app/index' // "/" is mapped to "/app/index"