javascript内部的springsecurity角色检查
是否可以在JSP中使用java脚本,如下所示javascript内部的springsecurity角色检查,javascript,spring,Javascript,Spring,是否可以在JSP中使用java脚本,如下所示 var f = null; '<sec:authorize access="hasAnyRole(\'c2ladmin\',\'provider\')">' f = function() { alert('hi'); } '</sec:authorize>'; '<sec:authorize access="hasRole(\'teacher\')">' f = functio
var f = null;
'<sec:authorize access="hasAnyRole(\'c2ladmin\',\'provider\')">'
f = function() {
alert('hi');
}
'</sec:authorize>';
'<sec:authorize access="hasRole(\'teacher\')">'
f = function() {
alert('teacher');
}
'</sec:authorize>';
var f=null;
''
f=函数(){
警报(“hi”);
}
'';
''
f=函数(){
警惕(“老师”);
}
'';
注意:需要根据用户角色从Javascript呈现视图。您可以尝试以下操作:
<sec:authorize access="hasAnyRole('admin','superadmin')" var="isAuthorizeAny"></sec:authorize>
<sec:authorize access="hasRole('user')" var="haRoleUser"></sec:authorize>
<script type="text/javascript">
if('${isAuthorizeAny}' == true){
f = function() {
alert('hi Admini');
}
}
if('${haRoleUser}' == true){
f = function() {
alert('hei User');
}
}
</script>
如果(${isAuthorizeAny}==true){
f=函数(){
警报(“hi Admini”);
}
}
if(${haRoleUser}==true){
f=函数(){
警报(“hei用户”);
}
}
这对我很有用
<input id="isRoleExterno" access="hasRole('ROLE_EXTERNO')" type="text" class="hide" value="true"/>
<input id="isRoleExterno" access="!hasRole('ROLE_EXTERNO')" type="text" class="hide" value="false"/>
“合法”是什么意思?您必须了解,Javascript很容易被用户修改以显示某些属性。因此,您必须对用户正在执行的每个后端操作进行双重检查(您应该随时这样做)。只是要小心,你不会以这种方式打开自己的漏洞,你应该会没事的。
var isRoleExterno = $('#isRoleExterno').val();
if(isRoleExterno){var clazz="hide";}else{var clazz="";}