Authorization Mechanism for Files and Reader projects in CommunityServer 2.0

Source: Internet
Author: User
CommunityServer 2.0 has been released for several days and some source code is open. The newly added CommunityServer. Files and CommunityServer. Reader projects are not open source. And there are some restrictions in the free version.

In CommunityServer 2.0, related control is implemented:
With some tools, we can easily view the metadata of CommunityServer. Files and CommunityServer. Reader. I found authorization methods in two classes:
The CommunityServer. Files project corresponds to the Entries class, And the CommunityServer. Reader project corresponds to the Feeds class.
In the Entries class, there is a method described as follows: 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, true ))
{
Num1 + = folder1.TotalThreads;
}
Flag1 = num1 <CommunityServer. FileGalleryLimit;
}
CSCache. Insert ("CreateEntryAccess", flag1, CSCache. HourFactor );
Return flag1;
}

From the above class, we can know that the maximum number of files is 0x7fffff, which is a hexadecimal representation and is converted to decimal: 2147483647.
If it is not the maximum authorization, it is necessary to determine the number of files in all folders. If the number of files exceeds the authorized FileGalleryLimit, a false value is returned. Of course, this verification consumes a lot of system resources. All CS have implemented a cache mechanism here, And the cache time is one hour. Here, there will be a small problem: that is to say, if the number of authorized files is not exceeded for one verification performed one hour ago, in the next hour, you can upload the desired file quantity at will, but CS will not monitor it. However, after the cache time expires, CS will judge again. Hey, if you want to upload more files, it will be nice that hour, crazy...

If you exceed the number of authorizations, you can see the following code: 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 .");
}
}

For the entire authorization mechanism, if the authorization fails, an exception is thrown: You have exceeded the maximum number of uploads allowed by your current license.

The authorization mechanism of the CommunityServer. Reader project is in the Feeds class. We can see similar code, as follows: 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;
}

First, determine whether it is the maximum authorization value. If not, Feeds. getUsers () gets all the users who use Reader. If the number of reasers used is used to operate the FeedReaderLimit authorization value, you need to make a judgment, check whether the currently logged-on user is a Reader user. If so, false is returned.
The entire authorization also has a unique entry: 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 .");
}
}

If the value is false, an exception message about You have exceeded the maximum number of users allowed by your current license is thrown.

In fact, how to limit the number of FeedReaderLimit and FileGalleryLimit is completed in a class library called Telligent. Registration. dll. This class is obfuscated, so it is difficult to analyze it.

This Blog is here, and more articles on CS2.0 will be available one after another.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.