Jive笔记7 -- Jive的硬伤

类别:Java 点击:0 评论:0 推荐:
Jive笔记7 -- Jive的硬伤

(1)Jive2.x权限颗粒度太粗,只是细分到Forum,所以其API无法完成类似 加密贴/需要回复才能看见 这样的功能。当

然,可以通过属性操作,修补jsp来实现,但这不是我们的目标。

(2)Jive2.x权限规则:上级覆盖下级。
举例:有一个Category 1,everyone 可read,其下有forum 1,2,3,.....100个。
现在,我想让forum2只让注册用户访问,则你无法做到!
除非:删除Category1的everyone read权限,分别给forum1,3,4,5....100添加everyone read权限,然后再给forum2设

置registed user read权限。

(3)如果Category/Forum数量成百上千,Jive效率会大大降低。
Jive2.x在设计的时候就没有考虑到这种情况,而权限也只落实到Forum。在代码处理上,看IteratorProxy.java

public IteratorProxy(int type, Iterator iterator, Authorization authorization, ForumPermissions permissions) { this.iterator = iterator; this.authorization = authorization; this.permissions = permissions;   // Load the appropriate proxy factory depending on the type of object // that we're iterating through. Each proxy factory is responsible // for checking that the user has permission to view the object, and // then wrapping it with an appropriate proxy. switch (type) { // CATEGORY case JiveGlobals.FORUM_CATEGORY: // Create a class that wraps forums with proxies. proxyFactory = new ProxyFactory() { public Object createProxy(Object obj, Authorization auth, ForumPermissions perms) { ForumCategory category = (ForumCategory)obj; // Create a new permissions object with the combination // of the permissions of this object and tempPermissions. int parentPerms = perms.toInt(); // Never inherit the show category permission. ForumPermissions newPerms = new ForumPermissions( ForumPermissions.setBit(parentPerms, ForumPermissions.SHOW_CATEGORY, false)); ForumPermissions catPerms = category.getPermissions(auth); newPerms = new ForumPermissions(catPerms, newPerms);   // Return the object if the user has permission. if (newPerms.get(ForumPermissions.READ_FORUM) || newPerms.get(ForumPermissions.SHOW_CATEGORY) || newPerms.get(ForumPermissions.MODERATE_MESSAGES) || newPerms.get(ForumPermissions.MODERATE_THREADS) || newPerms.get(ForumPermissions.FORUM_ADMIN) || newPerms.get(ForumPermissions.CATEGORY_ADMIN) || newPerms.get(ForumPermissions.SYSTEM_ADMIN)) { return new ForumCategoryProxy(category, auth, newPerms); } // Otherwise return null. else { return null; } } }; break;
分析:假设存在Category 1,2,3,4,5,其中Category2只允许注册用户访问。现在是匿名访问。则构造函数中传入
的Iterator包含了全部的Category对象,在匿名类的createProxy()中判断了权限,如果编历到category 2,毫无疑问会
返回null(这样,category2被过滤了)。匿名类的createProxy()将被iteratorProxy的getNextElement()调用,代码如下


public Object getNextElement() { while (iterator.hasNext()) { Object element = proxyFactory.createProxy(iterator.next(), authorization, permissions); if (element != null) { return element; } } return null; }
这里的while()将跳过被过滤的对象(其实是null对象咯),返回当前auth可见的Category对象。

再观察ForumCategory接口,只有categories()方法,而没有categories(ResultFilter),说明没有做分页处理。

如果我们添加分页处理,得注意由于iteratorProxy的过滤,而导致实际得到的Category数目和page size的不一致。
比如:有30个Category,我一个categories(resultFilter)调用返回了15个,经过IteratorProxy的时候,被过滤掉了1个
这样实际上只有14个Category了,这样会让JSP迷惑,觉得ResultFilter.setPageSize()不对了。


附:本来是很长的一篇笔记,花费了一个多小时,想不到提交表单的时候,IE崩溃了!欲哭无泪!查出来罪魁祸首是
superbar.dll,不知道是什么垃圾,全面清剿中。。。。

 

本文地址:http://com.8s8s.com/it/it17762.htm