2014-01-06 36 views
0

我希望把JavaScript代碼的一部分取決於下面的權限,這是freemarker代碼。我可以使用百里香彈簧安全像jstl

<script type="text/javascript"></br> 
var openAuthorityOperatorData = false; 

$(function() { 
    $('#dlg_operator_auth_search_form').dialog({ 
     autoOpen: false, 
     width: 500<@security.authorize access="hasRole('AUHOA00000')"> + 450</@security.authorize>, 
     height: 550, 
     dialogClass: 'dialog-shadow', 
     modal: false, 
     resizable: false... 
})}); 
</script> 

隨着thymleaf,我只能發現,把權力屬性爲腳本元素像下面的方法。

<script sec:authorize="hasAnyRole('AUCOP0000x','AUUOP0000x')" type="text/javascript"> 
$(function() { 
}); 
</script> 

如果我不能使用類似上面的代碼,我可以使用JSTL與thymeleaf要達到的目標?

回答

2

Thymeleaf需要有效的HTML5/XHTML/XML模板才能工作,所以不可能將它與JSTL結合使用。

但是,您可以在Thymeleaf中使用腳本內聯。 Spring Security extras插件還提供了authorization實用程序對象。

<script th:inline="javascript"> 
    var w = /*[[${#authorization.expression('hasAnyRole(''AUCOP0000x'',''AUUOP0000x'')')} ? ${500} : ${950} ]]*/ 500; 
    ... 
     width: w, 
    ... 
</script> 

來源