2016-08-01 54 views
0

我寫了一個簡單的hello世界項目使用彈簧安全核心。基本上我有一個安全註釋的控制器。該項目沒有建立...找不到類... org.springframework.security.core.GrantedAuthority

package springsecuritytest 

import grails.plugin.springsecurity.annotation.Secured 


@Secured(['ROLE_ADMIN']) 
class HelloController { 

    def index() { 

     render "this is public"  

    } 


    def logout(){ 


    } 

} 

因此,該應用程序符合並正常工作。當我嘗試訪問索引頁時,它會要求我登錄,只有當我有管理員角色時,我才允許訪問該頁面。

現在,我增加對註銷一個simpe代碼,我碰到下面的錯誤

package springsecuritytest 

import grails.plugin.springsecurity.annotation.Secured 

import grails.plugin.springsecurity.SpringSecurityUtils 


@Secured(['ROLE_ADMIN']) 
class HelloController { 

    def index() { 

     render "this is public"  

    } 


    def logout(){ 

     redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl 

    } 

} 

我得到的錯誤如下:

The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.security.core.GrantedAuthority. Fix the build path then try building this project 

我明白任何幫助!謝謝!

回答

1

你只需要添加下面兩行的Config.groovy中

grails.plugin.springsecurity.logout.postOnly = false 
grails.plugin.springsecurity.logout.afterLogoutUrl = "/login/auth" 

和「../logout」附加鏈接註銷按鈕類似下面

<a href="../logout">Sign out</a> 

這將做招。您不必爲註銷處理創建任何操作。

請編譯,清理並運行您的項目。