Author: tmortagne
Date: 2007-10-26 16:09:02 +0200 (Fri, 26 Oct 2007)
New Revision: 5519
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
Log:
XWIKI-1826: Remove useless isLevelAllowedForGroup and isLevelAllowedForUser
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
2007-10-26 14:08:50 UTC (rev 5518)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
2007-10-26 14:09:02 UTC (rev 5519)
@@ -128,11 +128,6 @@
private static final String RIGHTSLISTFIELD_JOIN = "|";
/**
- * Full name of the xwiki.cfg super administrator.
- */
- private static final String SUPER_ADMIN_NAME = "XWiki.superadmin";
-
- /**
* Symbol use in HQL "like" command that means "all characters".
*/
private static final String HQLLIKE_ALL_SYMBOL = "%";
@@ -1181,195 +1176,4 @@
return found;
}
-
- /**
- * Browse a right object to find provided user or group.
- *
- * @param rightEntry the object containing rights preferences.
- * @param userOrGroupName the name of the user or groups to find.
- * @param user indicate if it is a user or a group.
- * @param groupCacheIn a map containing a set a group and its
corresponding members already
- * retrieved.
- * @param context the XWiki context.
- * @return true if the member has been found, false otherwise.
- * @throws XWikiException error when browsing right object.
- */
- public boolean rightEntryContainsUserOrGroup(BaseObject rightEntry, String
userOrGroupName,
- boolean user, Map groupCacheIn, XWikiContext context) throws
XWikiException
- {
- boolean found = false;
-
- String userOrGroupField = user ? RIGHTSFIELD_USERS :
RIGHTSFIELD_GROUPS;
-
- List userOrGroupList =
-
ListClass.getListFromString(rightEntry.getStringValue(userOrGroupField),
- RIGHTSLISTFIELD_SEP, false);
-
- if (userOrGroupList.contains(userOrGroupName)) {
- found = true;
- } else {
- List groupList =
- !user ? userOrGroupList :
ListClass.getListFromString(rightEntry
- .getStringValue(RIGHTSFIELD_GROUPS), RIGHTSLISTFIELD_SEP,
false);
-
- Map groupCache = groupCacheIn;
- if (groupCache == null) {
- groupCache = new Hashtable();
- }
-
- for (Iterator it = groupList.iterator(); it.hasNext();) {
- String groupName = (String) it.next();
-
- if (groupContainsMember(groupName, userOrGroupName,
groupCache, context)) {
- found = true;
- break;
- }
- }
- }
-
- return found;
- }
-
- /**
- * Indicate if provided user is super administrator.
- *
- * @param userName the name of the user.
- * @param context the XWiki context.
- * @return true is provided user is super administrator, false otherwise.
- */
- public boolean isSuperAdmin(String userName, XWikiContext context)
- {
- boolean isSuperAdmin = false;
-
- // Check if use is xwiki.cfg configured super administrator.
- if (userName.equals(SUPER_ADMIN_NAME)
- || userName.endsWith(WIKIFULLNAME_SEP + SUPER_ADMIN_NAME)) {
- isSuperAdmin = true;
- } else {
- // In case of a sub wiki-check if the user is the sub-wiki owner
- if (context.isVirtual()
- &&
!context.getDatabase().equalsIgnoreCase(context.getMainXWiki())) {
- String wikiOwner = context.getWikiOwner();
-
- if (wikiOwner.equals(userName)) {
- isSuperAdmin = true;
- }
- }
- }
-
- return isSuperAdmin;
- }
-
- /**
- * Indicate which rights provided user or group has on provided right
level on provided right
- * object.
- *
- * @param rightEntry the object containing rights preferences.
- * @param levelName the name of the level right to check.
- * @param userOrGroupName the name of the user or group.
- * @param user indicate if it is a user or a group.
- * @param groupCache a map containing a set a group and its corresponding
members already
- * retrieved.
- * @param context the XWiki context.
- * @return [EMAIL PROTECTED] Boolean#TRUE} if user has provided right
level, [EMAIL PROTECTED] Boolean#FALSE} if it is
- * denied on provided right level. Can be null if no "allow" or
"deny" rights.
- * @throws XWikiException error when browsing rights.
- */
- private Boolean isRightEntryAllowed(BaseObject rightEntry, String
levelName,
- String userOrGroupName, boolean user, Map groupCache, XWikiContext
context)
- throws XWikiException
- {
- Boolean allow = null;
-
- if (rightEntry != null) {
- List levels =
-
ListClass.getListFromString(rightEntry.getStringValue(RIGHTSFIELD_LEVELS),
- RIGHTSLISTFIELD_SEP, false);
-
- if (levels.contains(levelName)) {
- if (rightEntryContainsUserOrGroup(rightEntry, userOrGroupName,
user, groupCache,
- context)) {
- allow =
Boolean.valueOf(rightEntry.getIntValue(RIGHTSFIELD_ALLOW) == 1);
- } else {
- allow = Boolean.FALSE;
- }
- }
- }
-
- return allow;
- }
-
- /**
- * Indicate if provided user or group has provided rights level on
provided space or page.
- *
- * @param preferences the document containing rights preferences.
- * @param global indicate it is global rights (wiki or space) or document
rights.
- * @param levelName the name of the level right to check ("view", "edit",
etc.).
- * @param userOrGroupName the name of the user or group.
- * @param user indicate if it is a user or a group.
- * @param context the XWiki context.
- * @return true if user has provided rights, false otherwise.
- * @throws XWikiException error when browsing rights.
- */
- public boolean isLevelAllowed(XWikiDocument preferences, boolean global,
String levelName,
- String userOrGroupName, boolean user, XWikiContext context) throws
XWikiException
- {
- if (user && isSuperAdmin(userOrGroupName, context)) {
- return true;
- }
-
- String rightsClass = global ? GLOBAL_RIGHTS_CLASS : RIGHTS_CLASS;
-
- // boolean founded = false;
- Boolean allow = null;
-
- List rightVector = preferences.getObjects(rightsClass);
- if (rightVector != null) {
- Map groupCache = new Hashtable();
-
- for (Iterator it = rightVector.iterator(); it.hasNext();) {
- BaseObject rightEntry = (BaseObject) it.next();
-
- allow =
- isRightEntryAllowed(rightEntry, levelName,
userOrGroupName, user, groupCache,
- context);
- }
- }
-
- // If nothing was found try inheritance
- if (allow == null) {
- // Get document containing inherited rights
- XWikiDocument parentPreferences = getParentPreference(preferences,
global, context);
-
- if (parentPreferences != null) {
- allow =
- Boolean.valueOf(isLevelAllowed(parentPreferences, true,
levelName,
- userOrGroupName, user, context));
- }
- }
-
- return allow != null && allow.booleanValue();
- }
-
- /**
- * Indicate if provided user or group has provided rights level on
provided space or page.
- *
- * @param spaceOrPage the space or page for which to check rights. If null
check current wiki
- * rights.
- * @param levelName the name of the level right to check ("view", "edit",
etc.).
- * @param userOrGroupName the name of the user or group.
- * @param user indicate if it is a user or a group.
- * @param context the XWiki context.
- * @return true if user has provided rights, false otherwise.
- * @throws XWikiException error when browsing rights.
- */
- public boolean isLevelAllowed(String spaceOrPage, String levelName, String
userOrGroupName,
- boolean user, XWikiContext context) throws XWikiException
- {
- XWikiDocument preferences = getXWikiPreferencesDoc(spaceOrPage,
context);
-
- boolean global = isGlobal(preferences, spaceOrPage);
-
- return isLevelAllowed(preferences, global, levelName, userOrGroupName,
user, context);
- }
}
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
2007-10-26 14:08:50 UTC (rev 5518)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
2007-10-26 14:09:02 UTC (rev 5519)
@@ -1938,58 +1938,4 @@
return userList;
}
-
- // Rights management
-
- /**
- * Indicate if provided user has provided rigts level on provided space or
page.
- *
- * @param spaceOrPage the space or page for which to check rights. If null
check current wiki
- * rights.
- * @param level the name of the level right to check ("view", "edit",
etc.).
- * @param userName the name of the user.
- * @return true if user has provided rights, false otherwise.
- * @throws XWikiException error when browsing rights.
- */
- public boolean isLevelAllowedForUser(String spaceOrPage, String level,
String userName)
- throws XWikiException
- {
- boolean allow = false;
-
- try {
- allow =
- RightsManager.getInstance().isLevelAllowed(spaceOrPage, level,
userName, true,
- context);
- } catch (RightsManagerException e) {
- logError("Try to check if user has rights " + QUOTE + level +
QUOTE, e);
- }
-
- return allow;
- }
-
- /**
- * Indicate if provided group has provided rigts level on provided space
or page.
- *
- * @param spaceOrPage the space or page for which to check rights. If null
check current wiki
- * rights.
- * @param level the name of the level right to check ("view", "edit",
etc.).
- * @param groupName the name of the group.
- * @return true if user has provided rights, false otherwise.
- * @throws XWikiException error when browsing rights.
- */
- public boolean isLevelAllowedForGroup(String spaceOrPage, String level,
String groupName)
- throws XWikiException
- {
- boolean allow = false;
-
- try {
- allow =
- RightsManager.getInstance().isLevelAllowed(spaceOrPage, level,
groupName, false,
- context);
- } catch (RightsManagerException e) {
- logError("Try to check if group has rights " + QUOTE + level +
QUOTE, e);
- }
-
- return allow;
- }
}
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications