Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我是否应该从Acegi Security实现一个基于自定义属性文件的授权标记以与authz配合使用?_Security_Jsp_Authorization_Web Applications_Spring Security - Fatal编程技术网

我是否应该从Acegi Security实现一个基于自定义属性文件的授权标记以与authz配合使用?

我是否应该从Acegi Security实现一个基于自定义属性文件的授权标记以与authz配合使用?,security,jsp,authorization,web-applications,spring-security,Security,Jsp,Authorization,Web Applications,Spring Security,我正在寻找处理视图级授权(根据用户角色隐藏标记)的最佳方法 执行此操作的典型方法是使用Acegi Security authz标记,如下所示: <authz:authorize ifAnyGranted="ROLE_FOO, ROLE_BAR, ROLE_BLAH"> <!-- protected content here --> </authz:authorize> com.lingoswap.home.editUserNameButton.ifAny

我正在寻找处理视图级授权(根据用户角色隐藏标记)的最佳方法

执行此操作的典型方法是使用Acegi Security authz标记,如下所示:

<authz:authorize ifAnyGranted="ROLE_FOO, ROLE_BAR, ROLE_BLAH">
  <!-- protected content here -->
</authz:authorize>
com.lingoswap.home.editUserNameButton.ifAnyGranted=ROLE_FOO, ROLE_BAR, ROLE_BLAH
com.lingoswap.home.deleteAccountButton.ifNotGranted=ROLE_NOOB
com.lingoswap.home.deleteAccountButton.ifAnyGranted=ROLE_ADMIN
...
为了保护主页上的内容,我们将使用另一个受保护的标记(该标记大量借用了原始authz,可能是一个子类):


这种方法的优点如下:

  • 易于测试-我们可以编写单元测试来验证用户角色到ui元素的映射(当然,它仍然必须在JSP上使用)
  • 运行时(和测试时)错误检查-如果.properties文件中的用户角色拼写错误,我们可以引发异常
  • 易于调整用户角色-需求团队不断完善用户角色;最好在一个中心位置全部更换
  • 易于理解-我们可以一目了然地查看整个应用程序的用户角色权限
  • 可以直接进行(使用属性Spring占位符对相关角色进行分组,例如,可以在属性文件中使用${readOnlyGroup},而不是实际的角色名称)
  • 缺点似乎是:

  • 中等复杂性
  • 其他
  • 谢谢你的建议

    问候,,
    LES2

    我做了一些类似于第二种方法的事情。因为我希望所有的安全定义都放在一个地方,所以我为过滤器安全接口实现了自己的对象定义源

    <security:protect component="com.lingoswap.home.editUserNameButton">
        <!-- edit user name button -->
    </security:protect>
    
    <security:protect component="com.lingoswap.deleteAccountButton">
       <!-- show the awesome delete account button that's not for nincompoops -->
    </security:protect>