2012-02-08 187 views
0

我有一些控制器在我的Grails應用程序: -自定義鏈接

LoginController 
LogoutController 
SearchableController 
cirnele.SearchAllController 
com.ten.cirnelle.domain.CustomerController 
com.ten.cirnelle.domain.ProjectController 
com.ten.cirnelle.domain.PurchaseOrderController 
com.ten.cirnelle.domain.QuotationController 
com.ten.cirnelle.domain.ResourceController 

Config.groovy中,我提供我的CONFIGRATION之一: -

cirnelleControllerExclusions =['Login','Search','Searchable','Resource'] 

和main.gsp中,我使用: -

<g:each var="c" in="${grailsApplication.controllerClasses.sort { it.fullName } }"> 

    <g:if test="${grailsApplication.config.cirnelleControllerExclusions.contains(c.naturalName.split()[0]) == false}"> 

     <li class="controller"><g:link controller="${c.logicalPropertyName}">${c.naturalName.split()[0]}</g:link></li> 
    </g:if> 
</g:each> 

這個碼被用於在每一個視圖頁面的頂部提供狀結構的菜單,它是不包括4 cotroller s,我在Config.groovy中指定要在查看頁面中顯示爲鏈接。 但我有很多用戶都具有不同的角色就像

ROLE_PM 
ROLE_SALES/BDM 
ROLE_TEAMMEMBER 
ROLE_ADMIN 

,我的要求是,如果以管理員角色登錄的用戶,那麼他就可以查看所有的控制器爲紐帶(除4),但如果與用戶PM角色登錄,則他無法查看CustomerController鏈接和QuotationCotroller鏈接。 那麼我如何定製我的main.gsp來顯示基於用戶角色的菜單鏈接。 thnks

回答

1

嘗試使用spring security plugin。有標籤正是你想要做的。

<sec:ifNotLoggedIn> 
    <g:link controller="login" action="auth">Login</g:link> 
</sec:ifNotLoggedIn> 
<sec:ifAllGranted roles="ROLE_USER"> 
    <g:link class="create" controller="post" action="timeline">My Timeline</g:link> 
</sec:ifAllGranted>