在一个基于SpringMVC的框架中,如何去控制某一个页面中具体Button的权限?求具体思路?
总体的思路已经有了,大概就是基于RBAC的设计思路。
现在要求具体一点的思路,比如:
当用户以具体角色登录时,角色所属资源列表是否一次性读入内存?存储何种数据结构中?为什么?
具体页面中按钮的权限如何控制?
主要能把思路讲清楚就好,能附一小部分代码那就是最好了。
周五下班前(19:00)结贴。
期待高人答复!!
在一个基于SpringMVC的框架中,如何去控制某一个页面中具体Button的权限?求具体思路?
总体的思路已经有了,大概就是基于RBAC的设计思路。
现在要求具体一点的思路,比如:
当用户以具体角色登录时,角色所属资源列表是否一次性读入内存?存储何种数据结构中?为什么?
具体页面中按钮的权限如何控制?
主要能把思路讲清楚就好,能附一小部分代码那就是最好了。
周五下班前(19:00)结贴。
期待高人答复!!
楼上各位说的都对,比较可靠和流行做法是用shiro,完全可以做到控制到按钮,还有一种思路提供给你:
这个也不用引入其他的库,就是在jsp中用自定义标签,有这个权限就显示按钮,没有就不显示。
下面是shiro的一段代码,将权限添加到系统中
// 在这个授权方法中添加系统已有权限,依据权限添加的不同的操作操作权限
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
/* 这里编写授权代码 */
String currentUserName=null;
//获取当前用户名
try {
currentUserName = (String) super.getAvailablePrincipal(principals);
} catch (Exception e1) {
logger.error("获取当前用户名发生异常", e1);
}
//获取当期用户基本
User user = null;
try {
user = loginService.findUserInfo(currentUserName.trim());
} catch (Exception e2) {
logger.error("授权发生异常", e2);
}
Set<String> permissions = new HashSet<String>();
Set<String> roleNames = new HashSet<String>();
//获取角色列表
try {
List<RoleWrapper> roleList = userRoleService.listUserAndRole(user.getId().trim());
for(Iterator<RoleWrapper> it=roleList.iterator();it.hasNext();)
{
RoleWrapper role = (RoleWrapper)it.next();
roleNames.add(role.getName());
Set<String> permissionTemp = rolePermissionService.SetRoleAndPermission(role.getId());
permissions.addAll(permissionTemp);
}
} catch (Exception e3) {
logger.error("获取角色与权限发生异常", e3);
}
SimpleAuthorizationInfo info = null;
info = new SimpleAuthorizationInfo(roleNames);
info.setStringPermissions(permissions);
return info;
}
在页面中引入shiro标签<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
下面就可以使用标签来限制按钮了
辅助决策
/shiro:hasPermission
第二种自定义标签其实思路跟这个是一样的,将权限存于session中,然后再页面中可以通过自定义标签取出来进行比较。
http://blog.csdn.net/tim_zhang8888/article/details/3960822
归根结底,权限就是字符串比较