Reputation: 1216
I wish to put part of javascript code depends on authorities like below which is freemarker code.
<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>
With thymleaf, I can only find a way that puts authority attribute into script element like below.
<script sec:authorize="hasAnyRole('AUCOP0000x','AUUOP0000x')" type="text/javascript">
$(function() {
});
</script>
If I can not use something like the top code, can I use jstl with thymeleaf to achieve the goal?
Upvotes: 0
Views: 964
Reputation: 15992
Thymeleaf requires valid HTML5/XHTML/XML templates to work, so it is not possible to combine it with JSTL.
However, you can use script inlining in Thymeleaf. The Spring Security extras plugin also provides an authorization
utility object.
<script th:inline="javascript">
var w = /*[[${#authorization.expression('hasAnyRole(''AUCOP0000x'',''AUUOP0000x'')')} ? ${500} : ${950} ]]*/ 500;
...
width: w,
...
</script>
Sources
Upvotes: 2