try {
toBeAdded.add((T) obj);
} catch (ClassCastException e) {
+ logger.debug("Attempt to add a resource with invalid type");
allAdded = false;
}
}
new Status(StatusCode.SUCCESS, "One or more resources couldn't be added"));
}
- public Status addResourceToGroup(String groupName, T resource) {
+ @SuppressWarnings("unchecked")
+ @Override
+ public Status addResourceToGroup(String groupName, Object resource) {
if (groupName == null || groupName.trim().isEmpty()) {
return new Status(StatusCode.BADREQUEST, "Invalid group name");
}
+ if (resource == null) {
+ return new Status(StatusCode.BADREQUEST, "Null resource");
+ }
+
+ T castedResource = null;
+ try {
+ castedResource = (T) resource;
+ } catch (ClassCastException e) {
+ logger.debug("Attempt to add a resource with invalid type");
+ return new Status(StatusCode.BADREQUEST, "Incompatible resource");
+ }
+
Set<T> group = resourceGroups.get(groupName);
- if (group != null && resource != null) {
- group.add(resource);
- // Update cluster
- resourceGroups.put(groupName, group);
- return new Status(StatusCode.SUCCESS, "Resource added successfully");
+ if (group == null) {
+ return new Status(StatusCode.NOTFOUND, "Group not found");
}
- return new Status(StatusCode.NOTFOUND, "Group not found or incompatible resource");
+ return addResourceToGroupInternal(groupName, castedResource);
+ }
+
+ /*
+ * Method child classes can overload if they need application specific
+ * checks on the resource
+ */
+ protected Status addResourceToGroupInternal(String groupName, T resource) {
+ Set<T> group = resourceGroups.get(groupName);
+ // Update group and cluster
+ group.add(resource);
+ resourceGroups.put(groupName, group);
+
+ return new Status(StatusCode.SUCCESS, "Resource added successfully");
+
}
- public Status removeRoleResourceGroupMapping(String groupName) {
+ private Status removeRoleResourceGroupMapping(String groupName) {
List<String> affectedRoles = new ArrayList<String>();
Status result;
for (Entry<String, Set<ResourceGroup>> pairs : groupsAuthorizations.entrySet()) {
}
- public Status removeResourceFromGroup(String groupName, T resource) {
+ @Override
+ public Status removeResourceFromGroup(String groupName, Object resource) {
if (groupName == null || groupName.trim().isEmpty()) {
return new Status(StatusCode.BADREQUEST, "Invalid group name");
}
return roles.containsKey(roleName);
}
+ @Override
+ public boolean isApplicationUser(String userName) {
+ IUserManager userManager = (IUserManager) ServiceHelper
+ .getGlobalInstance(IUserManager.class, this);
+ if (userManager == null) {
+ return false;
+ }
+ List<String> roles = userManager.getUserRoles(userName);
+ if (roles != null && !roles.isEmpty()) {
+ for (String role : roles) {
+ if (isApplicationRole(role)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
@Override
public AppRoleLevel getApplicationRoleLevel(String roleName) {
if (roleName == null || roleName.trim().isEmpty()) {