标签:
这两天接触的一个项目的权限控制思路,控制页面权限、action权限、页面内容权限
1用户
2角色
3权限组
4权限
5菜单
权限控制的5个基本模块:
if (menuUrl.equals(auth.getUrl()) || (user!=null && user.getId().equals(1L))) { //或者为超级用户的话也显示 menuJson.setIsHidden(false);// 有权限,显示
1 <auth:showhtml url="#hpgg"> 2 <%--自定义标签..需要根据权限显示隐藏的内容--%> 3 </auth:showhtml>
<interceptor name="authInterceptor" class="*************.AuthInterceptor" />
拦截器代码:
1 @SuppressWarnings("serial") 2 public class AuthInterceptor extends MethodFilterInterceptor { 3 4 @SuppressWarnings("unchecked") 5 @Override 6 protected String doIntercept(ActionInvocation invocation) throws Exception { 7 String url = invocation.getProxy().getActionName().trim() + "!" 8 + invocation.getProxy().getMethod().trim(); 9 10 Map map = invocation.getInvocationContext().getSession(); 11 12 User_info user = (User_info) map.get("user"); 13 14 boolean i = false; 15 Set<Role> roles = user.getRoles(); 16 if (roles == null || roles.size() == 0) { // 无角色不能访问 17 18 return "noAuth"; 19 } 20 21 for (Role role : roles) { 22 23 for (Auth auth : role.getAuths()) { 24 if (url.equals(auth.getUrl())) { 25 i = true; 26 break; 27 } 28 } 29 if (i == true) { 30 break; 31 } 32 33 } 34 35 if (i) { 36 return invocation.invoke(); 37 } else { 38 return "noAuth"; 39 } 40 41 } 42 43 }
标签:
原文地址:http://www.cnblogs.com/xulisha123/p/java.html