summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--EssentialsGroupBridge/src/org/anjocaido/groupmanager/permissions/NijikoPermissionsProxy.java4
-rw-r--r--EssentialsGroupManager/src/Changelog.txt3
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java415
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java9
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java7
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java136
6 files changed, 298 insertions, 276 deletions
diff --git a/EssentialsGroupBridge/src/org/anjocaido/groupmanager/permissions/NijikoPermissionsProxy.java b/EssentialsGroupBridge/src/org/anjocaido/groupmanager/permissions/NijikoPermissionsProxy.java
index e72666cf7..da40fc172 100644
--- a/EssentialsGroupBridge/src/org/anjocaido/groupmanager/permissions/NijikoPermissionsProxy.java
+++ b/EssentialsGroupBridge/src/org/anjocaido/groupmanager/permissions/NijikoPermissionsProxy.java
@@ -521,10 +521,10 @@ public class NijikoPermissionsProxy extends PermissionHandler {
@Override
public boolean has(String world, String playerName, String permission) {
- if (permission == null || permission.equals("")) {
+ if (permission == null || permission.isEmpty()) {
return false;
}
- if (playerName == null || playerName == "") {
+ if (playerName == null || playerName.isEmpty()) {
GroupManager.logger.severe("A plugin is asking permission '" + permission + "' for a null player... Which plugin does that? Bastards!");
return false;
}
diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt
index d942a470e..7b9a99bb7 100644
--- a/EssentialsGroupManager/src/Changelog.txt
+++ b/EssentialsGroupManager/src/Changelog.txt
@@ -77,4 +77,5 @@ v 1.6:
- Prevent Group.equals tests throwing a NullPointerException for GlobalGroups.
- Stop throwing errors on an empty users file.
- Optimize sorting to speedup permission tests.
- - Fix superperms to pass all tests http://dev.bukkit.org/server-mods/superpermstest/ \ No newline at end of file
+ - Fix superperms to pass all tests http://dev.bukkit.org/server-mods/superpermstest/
+ - Optimizations include changing the return of comparePermissionString. \ No newline at end of file
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java
index 6c4cdbcf2..eea488ab2 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java
@@ -10,209 +10,232 @@ import java.util.ArrayList;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
import java.util.Map;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
/**
- *
+ *
* @author gabrielcouto
*/
public class User extends DataUnit implements Cloneable {
- /**
- *
- */
- private String group = null;
- private ArrayList<String> subGroups = new ArrayList<String>();
- /**
- *This one holds the fields in INFO node.
- * like prefix = 'c'
- * or build = false
- */
- private UserVariables variables = new UserVariables(this);
-
- /**
+ /**
*
- * @param name
*/
- public User(WorldDataHolder source, String name) {
- super(source, name);
- this.group = source.getDefaultGroup().getName();
- }
+ private String group = null;
+ private ArrayList<String> subGroups = new ArrayList<String>();
+ /**
+ * This one holds the fields in INFO node. like prefix = 'c' or build =
+ * false
+ */
+ private UserVariables variables = new UserVariables(this);
+ private transient Player bukkitPlayer = null;
+
+ /**
+ *
+ * @param name
+ */
+ public User(WorldDataHolder source, String name) {
+ super(source, name);
+ this.group = source.getDefaultGroup().getName();
+ }
+
+ /**
+ *
+ * @return User clone
+ */
+ @Override
+ public User clone() {
+ User clone = new User(getDataSource(), this.getName());
+ clone.group = this.group;
+ for (String perm : this.getPermissionList()) {
+ clone.addPermission(perm);
+ }
+ // clone.variables = this.variables.clone();
+ // clone.flagAsChanged();
+ return clone;
+ }
+
+ /**
+ * Use this to deliver a user from one WorldDataHolder to another
+ *
+ * @param dataSource
+ * @return null if given dataSource already contains the same user
+ */
+ public User clone(WorldDataHolder dataSource) {
+ if (dataSource.isUserDeclared(this.getName())) {
+ return null;
+ }
+ User clone = dataSource.createUser(this.getName());
+ if (dataSource.getGroup(group) == null) {
+ clone.setGroup(dataSource.getDefaultGroup());
+ } else {
+ clone.setGroup(dataSource.getGroup(this.getGroupName()));
+ }
+ for (String perm : this.getPermissionList()) {
+ clone.addPermission(perm);
+ }
+ // clone.variables = this.variables.clone();
+ clone.flagAsChanged();
+ return clone;
+ }
+
+ public Group getGroup() {
+ Group result = getDataSource().getGroup(group);
+ if (result == null) {
+ this.setGroup(getDataSource().getDefaultGroup());
+ result = getDataSource().getDefaultGroup();
+ }
+ return result;
+ }
+
+ /**
+ * @return the group
+ */
+ public String getGroupName() {
+ Group result = getDataSource().getGroup(group);
+ if (result == null) {
+ group = getDataSource().getDefaultGroup().getName();
+ }
+ return group;
+ }
+
+ /**
+ * @param group
+ * the group to set
+ */
+ @Deprecated
+ public void setGroup(String group) {
+ this.group = group;
+ flagAsChanged();
+ if (GroupManager.isLoaded())
+ if (GroupManager.BukkitPermissions.player_join = false)
+ GroupManager.BukkitPermissions.updateAllPlayers();
+ }
+
+ /**
+ * @param group
+ * the group to set
+ */
+ public void setGroup(Group group) {
+ if (!this.getDataSource().groupExists(group.getName())) {
+ getDataSource().addGroup(group);
+ }
+ group = getDataSource().getGroup(group.getName());
+ String oldGroup = this.group;
+ this.group = group.getName();
+ flagAsChanged();
+ if (GroupManager.isLoaded()) {
+ if (GroupManager.BukkitPermissions.player_join = false)
+ GroupManager.BukkitPermissions.updateAllPlayers();
+
+ // Do we notify of the group change?
+ String defaultGroupName = getDataSource().getDefaultGroup().getName();
+ // if we were not in the default group
+ // or we were in the default group and the move is to a different
+ // group.
+ boolean notify = (!oldGroup.equalsIgnoreCase(defaultGroupName)) || ((oldGroup.equalsIgnoreCase(defaultGroupName)) && (!this.group.equalsIgnoreCase(defaultGroupName)));
+
+ if (notify)
+ GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName()));
+ }
+ }
+
+ public void addSubGroup(Group subGroup) {
+ if (this.group.equalsIgnoreCase(subGroup.getName())) {
+ return;
+ }
+ if (!this.getDataSource().groupExists(subGroup.getName())) {
+ getDataSource().addGroup(subGroup);
+ }
+ subGroup = getDataSource().getGroup(subGroup.getName());
+ removeSubGroup(subGroup);
+ subGroups.add(subGroup.getName());
+ flagAsChanged();
+ if (GroupManager.isLoaded())
+ if (GroupManager.BukkitPermissions.player_join = false)
+ GroupManager.BukkitPermissions.updateAllPlayers();
+ }
+
+ public int subGroupsSize() {
+ return subGroups.size();
+ }
+
+ public boolean isSubGroupsEmpty() {
+ return subGroups.isEmpty();
+ }
+
+ public boolean containsSubGroup(Group subGroup) {
+ return subGroups.contains(subGroup.getName());
+ }
+
+ public boolean removeSubGroup(Group subGroup) {
+ try {
+ if (subGroups.remove(subGroup.getName())) {
+ flagAsChanged();
+ if (GroupManager.isLoaded())
+ if (GroupManager.BukkitPermissions.player_join = false)
+ GroupManager.BukkitPermissions.updateAllPlayers();
+ return true;
+ }
+ } catch (Exception e) {
+ }
+ return false;
+ }
+
+ public ArrayList<Group> subGroupListCopy() {
+ ArrayList<Group> val = new ArrayList<Group>();
+ for (String gstr : subGroups) {
+ Group g = getDataSource().getGroup(gstr);
+ if (g == null) {
+ removeSubGroup(g);
+ continue;
+ }
+ val.add(g);
+ }
+ return val;
+ }
+
+ public ArrayList<String> subGroupListStringCopy() {
+ return new ArrayList<String>(subGroups);
+ }
+
+ /**
+ * @return the variables
+ */
+ public UserVariables getVariables() {
+ return variables;
+ }
+
+ /**
+ *
+ * @param varList
+ */
+ public void setVariables(Map<String, Object> varList) {
+ UserVariables temp = new UserVariables(this, varList);
+ variables.clearVars();
+ for (String key : temp.getVarKeyList()) {
+ variables.addVar(key, temp.getVarObject(key));
+ }
+ flagAsChanged();
+ if (GroupManager.isLoaded())
+ if (GroupManager.BukkitPermissions.player_join = false)
+ GroupManager.BukkitPermissions.updateAllPlayers();
+ }
+
+ public User updatePlayer(Player player) {
+ if (player != null) {
+ bukkitPlayer = player;
+ }
+ return this;
+ }
+
+ public Player getBukkitPlayer() {
+ if (bukkitPlayer == null) {
+ bukkitPlayer = Bukkit.getPlayer(this.getName());
+ }
+ return bukkitPlayer;
+ }
- /**
- *
- * @return User clone
- */
- @Override
- public User clone() {
- User clone = new User(getDataSource(), this.getName());
- clone.group = this.group;
- for (String perm : this.getPermissionList()) {
- clone.addPermission(perm);
- }
- //clone.variables = this.variables.clone();
- //clone.flagAsChanged();
- return clone;
- }
-
- /**
- * Use this to deliver a user from one WorldDataHolder to another
- * @param dataSource
- * @return null if given dataSource already contains the same user
- */
- public User clone(WorldDataHolder dataSource) {
- if (dataSource.isUserDeclared(this.getName())) {
- return null;
- }
- User clone = dataSource.createUser(this.getName());
- if (dataSource.getGroup(group) == null) {
- clone.setGroup(dataSource.getDefaultGroup());
- } else {
- clone.setGroup(dataSource.getGroup(this.getGroupName()));
- }
- for (String perm : this.getPermissionList()) {
- clone.addPermission(perm);
- }
- //clone.variables = this.variables.clone();
- clone.flagAsChanged();
- return clone;
- }
-
- public Group getGroup() {
- Group result = getDataSource().getGroup(group);
- if (result == null) {
- this.setGroup(getDataSource().getDefaultGroup());
- result = getDataSource().getDefaultGroup();
- }
- return result;
- }
-
- /**
- * @return the group
- */
- public String getGroupName() {
- Group result = getDataSource().getGroup(group);
- if (result == null) {
- group = getDataSource().getDefaultGroup().getName();
- }
- return group;
- }
-
- /**
- * @param group the group to set
- */
- @Deprecated
- public void setGroup(String group) {
- this.group = group;
- flagAsChanged();
- if (GroupManager.isLoaded())
- if(GroupManager.BukkitPermissions.player_join = false)
- GroupManager.BukkitPermissions.updateAllPlayers();
- }
-
- /**
- * @param group the group to set
- */
- public void setGroup(Group group) {
- if (!this.getDataSource().groupExists(group.getName())) {
- getDataSource().addGroup(group);
- }
- group = getDataSource().getGroup(group.getName());
- String oldGroup = this.group;
- this.group = group.getName();
- flagAsChanged();
- if (GroupManager.isLoaded()) {
- if (GroupManager.BukkitPermissions.player_join = false)
- GroupManager.BukkitPermissions.updateAllPlayers();
-
- // Do we notify of the group change?
- String defaultGroupName = getDataSource().getDefaultGroup().getName();
- // if we were not in the default group
- // or we were in the default group and the move is to a different group.
- boolean notify = (!oldGroup.equalsIgnoreCase(defaultGroupName)) || ((oldGroup.equalsIgnoreCase(defaultGroupName)) && (!this.group.equalsIgnoreCase(defaultGroupName))) ;
-
- if (notify) GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName()));
- }
- }
-
- public void addSubGroup(Group subGroup) {
- if (this.group.equalsIgnoreCase(subGroup.getName())) {
- return;
- }
- if (!this.getDataSource().groupExists(subGroup.getName())) {
- getDataSource().addGroup(subGroup);
- }
- subGroup = getDataSource().getGroup(subGroup.getName());
- removeSubGroup(subGroup);
- subGroups.add(subGroup.getName());
- flagAsChanged();
- if (GroupManager.isLoaded())
- if (GroupManager.BukkitPermissions.player_join = false)
- GroupManager.BukkitPermissions.updateAllPlayers();
- }
-
- public int subGroupsSize() {
- return subGroups.size();
- }
-
- public boolean isSubGroupsEmpty() {
- return subGroups.isEmpty();
- }
-
- public boolean containsSubGroup(Group subGroup) {
- return subGroups.contains(subGroup.getName());
- }
-
- public boolean removeSubGroup(Group subGroup) {
- try {
- if (subGroups.remove(subGroup.getName())) {
- flagAsChanged();
- if (GroupManager.isLoaded())
- if (GroupManager.BukkitPermissions.player_join = false)
- GroupManager.BukkitPermissions.updateAllPlayers();
- return true;
- }
- } catch (Exception e) {
- }
- return false;
- }
-
- public ArrayList<Group> subGroupListCopy() {
- ArrayList<Group> val = new ArrayList<Group>();
- for (String gstr : subGroups) {
- Group g = getDataSource().getGroup(gstr);
- if (g == null) {
- removeSubGroup(g);
- continue;
- }
- val.add(g);
- }
- return val;
- }
-
- public ArrayList<String> subGroupListStringCopy() {
- return new ArrayList<String>(subGroups);
- }
-
- /**
- * @return the variables
- */
- public UserVariables getVariables() {
- return variables;
- }
-
- /**
- *
- * @param varList
- */
- public void setVariables(Map<String, Object> varList) {
- UserVariables temp = new UserVariables(this, varList);
- variables.clearVars();
- for (String key : temp.getVarKeyList()) {
- variables.addVar(key, temp.getVarObject(key));
- }
- flagAsChanged();
- if (GroupManager.isLoaded())
- if (GroupManager.BukkitPermissions.player_join = false)
- GroupManager.BukkitPermissions.updateAllPlayers();
- }
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java
index e7fa81627..8e2df5d10 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java
@@ -44,12 +44,13 @@ public class OverloadedWorldHolder extends WorldDataHolder {
@Override
public User getUser(String userName) {
//OVERLOADED CODE
- if (overloadedUsers.containsKey(userName.toLowerCase())) {
- return overloadedUsers.get(userName.toLowerCase());
+ String userNameLowered = userName.toLowerCase();
+ if (overloadedUsers.containsKey(userNameLowered)) {
+ return overloadedUsers.get(userNameLowered);
}
//END CODE
- if (users.containsKey(userName.toLowerCase())) {
- return users.get(userName.toLowerCase());
+ if (users.containsKey(userNameLowered)) {
+ return users.get(userNameLowered);
}
User newUser = createUser(userName);
haveUsersChanged = true;
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java
index 6544bb1cc..25eaf8526 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java
@@ -268,9 +268,10 @@ public class WorldsHolder {
* @return OverloadedWorldHolder
*/
public OverloadedWorldHolder getWorldData(String worldName) {
- OverloadedWorldHolder data = worldsData.get(worldName.toLowerCase());
- if (mirrors.containsKey(worldName.toLowerCase())) {
- String realOne = mirrors.get(worldName.toLowerCase());
+ String worldNameLowered = worldName.toLowerCase();
+ OverloadedWorldHolder data = worldsData.get(worldNameLowered);
+ if (mirrors.containsKey(worldNameLowered)) {
+ String realOne = mirrors.get(worldNameLowered);
data = worldsData.get(realOne.toLowerCase());
}
if (data == null) {
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
index 91c73b5c2..6e18bf3f8 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
@@ -17,6 +17,7 @@ import org.anjocaido.groupmanager.utils.PermissionCheckResult;
import org.anjocaido.groupmanager.utils.PermissionCheckResult.Type;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
+import org.bukkit.permissions.Permission;
/**
* Everything here maintains the model created by Nijikokun
@@ -62,7 +63,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
*/
@Override
public boolean permission(Player player, String permission) {
- return checkUserPermission(ph.getUser(player.getName()), permission);
+ return checkUserPermission(ph.getUser(player.getName()).updatePlayer(player), permission);
}
/**
@@ -98,13 +99,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
public List<String> getAllPlayersPermissions(String userName) {
List<String> playerPermArray = new ArrayList<String>();
-
+
for (String perm : ph.getUser(userName).getPermissionList()) {
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
playerPermArray.add(perm);
-
+
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
-
+
if (children != null) {
for (String child : children.keySet()) {
if (children.get(child))
@@ -135,7 +136,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
for (String perm : ph.getGroup(group).getPermissionList()) {
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
playerPermArray.add(perm);
-
+
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
if (children != null) {
for (String child : children.keySet()) {
@@ -149,7 +150,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
}
}
}
- //Collections.sort(playerPermArray, StringPermissionComparator.getInstance());
+ // Collections.sort(playerPermArray,
+ // StringPermissionComparator.getInstance());
return playerPermArray;
}
@@ -243,7 +245,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/**
* Check if user can build. Checks inheritance and subgroups.
*
- * @param userName Player's name
+ * @param userName
+ * Player's name
* @return true if the user can build
*/
public boolean canUserBuild(String userName) {
@@ -283,8 +286,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
}
/**
- * Checks the specified group for the Info Build node.
- * Does NOT check inheritance
+ * Checks the specified group for the Info Build node. Does NOT check
+ * inheritance
*
* @param groupName
* @return true if can build
@@ -615,15 +618,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
result.askedPermission = permission;
result.owner = user;
for (String access : user.getPermissionList()) {
- if (comparePermissionString(access, permission)) {
- result.accessLevel = access;
- if (access.charAt(0) == '-') {
- result.resultType = PermissionCheckResult.Type.NEGATION;
- } else if (access.charAt(0) == '+') {
- result.resultType = PermissionCheckResult.Type.EXCEPTION;
- } else {
- result.resultType = PermissionCheckResult.Type.FOUND;
- }
+ result.resultType = comparePermissionString(access, permission);
+ if (result.resultType != PermissionCheckResult.Type.NOTFOUND) {
return result;
}
}
@@ -645,15 +641,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
result.owner = group;
result.askedPermission = permission;
for (String access : group.getPermissionList()) {
- if (comparePermissionString(access, permission)) {
- result.accessLevel = access;
- if (access.charAt(0) == '-') {
- result.resultType = PermissionCheckResult.Type.NEGATION;
- } else if (access.charAt(0) == '+') {
- result.resultType = PermissionCheckResult.Type.EXCEPTION;
- } else {
- result.resultType = PermissionCheckResult.Type.FOUND;
- }
+ result.resultType = comparePermissionString(access, permission);
+ if (result.resultType != PermissionCheckResult.Type.NOTFOUND) {
return result;
}
}
@@ -670,7 +659,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
*/
public boolean checkUserPermission(User user, String permission) {
PermissionCheckResult result = checkFullGMPermission(user, permission, true);
- if (result.resultType.equals(PermissionCheckResult.Type.EXCEPTION) || result.resultType.equals(PermissionCheckResult.Type.FOUND)) {
+ if (result.resultType == PermissionCheckResult.Type.EXCEPTION || result.resultType == PermissionCheckResult.Type.FOUND) {
return true;
}
@@ -686,13 +675,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
* @return PermissionCheckResult
*/
public PermissionCheckResult checkFullUserPermission(User user, String targetPermission) {
-
+
return checkFullGMPermission(user, targetPermission, true);
}
-
+
/**
- * Check user and groups with inheritance and Bukkit if bukkit = true
- * return a PermissionCheckResult.
+ * Check user and groups with inheritance and Bukkit if bukkit = true return
+ * a PermissionCheckResult.
*
* @param user
* @param targetPermission
@@ -708,31 +697,33 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
return result;
}
- if (checkBukkit == true) {
- // Check Bukkit perms to support plugins which add perms via code (Heroes).
- final Player player = Bukkit.getPlayer(user.getName());
- if ((player != null) && (player.hasPermission(targetPermission))) {
- result.resultType = PermissionCheckResult.Type.FOUND;
+ if (checkBukkit) {
+ // Check Bukkit perms to support plugins which add perms via code
+ // (Heroes).
+ final Player player = user.getBukkitPlayer();
+ final Permission bukkitPerm = Bukkit.getPluginManager().getPermission(targetPermission);
+ if (player != null && bukkitPerm != null) {
+ result.resultType = player.hasPermission(bukkitPerm) ? PermissionCheckResult.Type.FOUND : PermissionCheckResult.Type.NEGATION;
result.owner = user;
return result;
}
}
-
+
PermissionCheckResult resultUser = checkUserOnlyPermission(user, targetPermission);
- if (!resultUser.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ if (resultUser.resultType != PermissionCheckResult.Type.NOTFOUND) {
return resultUser;
}
// IT ONLY CHECKS GROUPS PERMISSIONS IF RESULT FOR USER IS NOT FOUND
PermissionCheckResult resultGroup = checkGroupPermissionWithInheritance(user.getGroup(), targetPermission);
- if (!resultGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ if (resultGroup.resultType != PermissionCheckResult.Type.NOTFOUND) {
return resultGroup;
}
// SUBGROUPS CHECK
for (Group subGroup : user.subGroupListCopy()) {
PermissionCheckResult resultSubGroup = checkGroupPermissionWithInheritance(subGroup, targetPermission);
- if (!resultSubGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ if (resultSubGroup.resultType != PermissionCheckResult.Type.NOTFOUND) {
return resultSubGroup;
}
}
@@ -994,37 +985,42 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
*
* @param userAccessLevel
* @param fullPermissionName
- * @return true if found a matching token. false if not.
+ * @return PermissionCheckResult.Type
*/
- public boolean comparePermissionString(String userAccessLevel, String fullPermissionName) {
- int userAccessLevelLength;
- if (userAccessLevel == null || fullPermissionName == null
- || fullPermissionName.length() == 0 || (userAccessLevelLength = userAccessLevel.length()) == 0) {
- return false;
- }
-
- int userAccessLevelOffset = 0;
- if (userAccessLevel.charAt(0) == '+' || userAccessLevel.charAt(0) == '-') {
- userAccessLevelOffset = 1;
- }
- if ("*".regionMatches(0, userAccessLevel, userAccessLevelOffset, userAccessLevelLength - userAccessLevelOffset)) {
- return true;
- }
- int fullPermissionNameOffset;
- if (fullPermissionName.charAt(0) == '+' || fullPermissionName.charAt(0) == '-') {
- fullPermissionNameOffset = 1;
- } else {
- fullPermissionNameOffset = 0;
- }
-
- if (userAccessLevel.charAt(userAccessLevel.length() - 1) == '*') {
- return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset - 1);
- } else {
- return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset,
- Math.max(userAccessLevelLength - userAccessLevelOffset, fullPermissionName.length() - fullPermissionNameOffset));
- }
- }
+ public PermissionCheckResult.Type comparePermissionString(String userAccessLevel, String fullPermissionName) {
+ int userAccessLevelLength;
+ if (userAccessLevel == null || fullPermissionName == null || fullPermissionName.length() == 0 || (userAccessLevelLength = userAccessLevel.length()) == 0) {
+ return PermissionCheckResult.Type.NOTFOUND;
+ }
+
+ PermissionCheckResult.Type result = PermissionCheckResult.Type.FOUND;
+ int userAccessLevelOffset = 0;
+ if (userAccessLevel.charAt(0) == '+') {
+ userAccessLevelOffset = 1;
+ result = PermissionCheckResult.Type.EXCEPTION;
+ } else if (userAccessLevel.charAt(0) == '-') {
+ userAccessLevelOffset = 1;
+ result = PermissionCheckResult.Type.NEGATION;
+ }
+ if ("*".regionMatches(0, userAccessLevel, userAccessLevelOffset, userAccessLevelLength - userAccessLevelOffset)) {
+ return result;
+ }
+ int fullPermissionNameOffset;
+ if (fullPermissionName.charAt(0) == '+' || fullPermissionName.charAt(0) == '-') {
+ fullPermissionNameOffset = 1;
+ } else {
+ fullPermissionNameOffset = 0;
+ }
+ if (userAccessLevel.charAt(userAccessLevel.length() - 1) == '*') {
+ return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset - 1) ?
+ result : PermissionCheckResult.Type.NOTFOUND;
+ } else {
+ return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset,
+ Math.max(userAccessLevelLength - userAccessLevelOffset, fullPermissionName.length() - fullPermissionNameOffset)) ?
+ result : PermissionCheckResult.Type.NOTFOUND;
+ }
+ }
/**
* Returns a list of all groups.