2014-01-06 28 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> 

来源