CommunityServer 2.0中Files 与 Reader 项目的授权机制

CommunityServer 2.0 出来已经有几天了,开放了部分的源代码。其中新增加的CommunityServer.Files、CommunityServer.Reader两个项目是不开源的。并且在free版本里有一些限制。

那么CommunityServer 2.0 中是进行相关的控制呢:
借助一些工具,我们很容易查看到CommunityServer.Files、与CommunityServer.Reader 的元数据。我分别在两个类下发现了授权的方法:
CommunityServer.Files 项目对应Entries类、CommunityServer.Reader项目对应Feeds类。
在Entries类下有一个方法如下描述:
public static bool ValidateCreateEntryAccess()
        
{
            
bool flag1;
            
object obj1 = CSCache.Get("CreateEntryAccess");
            
if (obj1 != null)
            
{
                
return (bool) obj1;
            }

            
if (CommunityServer.FileGalleryLimit == 0x7fffffff)
            
{
                flag1 
= true;
            }

            
else
            
{
                
int num1 = 0;
                
foreach (Folder folder1 in Folders.GetFolders(CSContext.Current.UserID, truetruetrue))
                
{
                    num1 
+= folder1.TotalThreads;
                }

                flag1 
= num1 < CommunityServer.FileGalleryLimit;
            }

            CSCache.Insert(
"CreateEntryAccess", flag1, CSCache.HourFactor);
            
return flag1;
        }


从以上类我们可以知道 File的最大数量是0x7fffffff,这个是十六进制的表示,换算成十进制为:2147483647。
如果不是最大授权,那么就要判断所有文件夹下有多少文件,如果文件数量超过了授权的FileGalleryLimit就返回一个false。当然这种验证很有比较消耗系统资源,所有CS在这里做了一个缓存机制,缓存时间为一个小时。这里就会出现一点点小问题:也就是说,如果你在一个小时前做的一次验证如果没有超过授权的文件数量,在之后的一个小时里,你可以随意上传你想要的文件数量,而CS是不会监控的。但是过了缓存时间后,CS又会判断。嘿嘿,如果你想多上传点文件就算好那个小时,疯狂一点...

如果你超过了授权的数量,那么由什么方法处理,结果又是如何,看看下面的代码就明白:
 public static void CreateEntryAccessCheck()
        
{
            
if (!Entries.ValidateCreateEntryAccess())
            
{
                
throw new CSException(CSExceptionType.InvalidLicense, "You have exceeded the maximum number of uploads allowed by your current license.");
            }

        }
整个授权机制,就这一个入口点,如果授权没有通过,抛出一个异常:显示:You have exceeded the maximum number of uploads allowed by your current license.

CommunityServer.Reader项目的授权机制在Feeds类下,我们可以看到类似代码,如下:
public static bool ValidateUserAccess()
        
{
            
if (CommunityServer.FeedReaderLimit != 0x7fffffff)
            
{
                ArrayList list1 
= Feeds.GetUsers();
                
if (list1.Count >= CommunityServer.FeedReaderLimit)
                
{
                    
return Feeds.CheckUserInList(CSContext.Current.User, list1);
                }

            }

            
return true;
        }
首先判断是不是最大的授权值,如果不是,就Feeds.GetUsers()取得使用 Reader的所有用户,再如果使用的Reaser的人数操作了FeedReaderLimit的授权值,这个时候还需要进行一次判断,看是否当前登录的用户是Reader的使用者,如果是才会返回false。
整个授权也有一个唯一的入口:
 public static void UserAccessCheck()
        
{
            
if (!Feeds.ValidateUserAccess())
            
{
                
throw new CSException(CSExceptionType.InvalidLicense, "You have exceeded the maximum number of users allowed by your current license.");
            }

        }


如果发挥得是false,就抛出You have exceeded the maximum number of users allowed by your current license.的异常信息。

其实如何进行FeedReaderLimit与FileGalleryLimit 数量限制的,这些是在一个叫Telligent.Registration.dll 的类库下完成的,由于该类进行了混淆,所以分析起来有困难。

本次Blog着落于此,CS2.0 更多的文章我会陆续奉上。

posted on 2006-02-24 10:16  彭斌  阅读(3678)  评论(6编辑  收藏  举报

导航