diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClearanceLevelManager.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClearanceLevelManager.java index 6c215658af..c9610dc199 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClearanceLevelManager.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClearanceLevelManager.java @@ -74,4 +74,12 @@ public class ClearanceLevelManager } throw new LevelIdNotFound(classificationLevelId); } + + /** + * @return the highest security clearance level. + */ + public ClearanceLevel getMostSecureLevel() + { + return clearanceLevels.get(0); + } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java index 77bd20f9f3..7599687434 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java @@ -22,10 +22,13 @@ import org.alfresco.query.PagingResults; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.NoSuchPersonException; +import java.util.List; + /** * This service offers access to users' security clearance levels. * * @author Neil Mc Erlean + * @author David Webster * @since 3.0 */ public interface SecurityClearanceService @@ -66,4 +69,13 @@ public interface SecurityClearanceService * @return the user's security clearance */ SecurityClearance setUserSecurityClearance(String userName, String clearanceId); + + /** + * Returns an immutable list of the defined clearance levels. + * + * @return clearance levels in descending order from highest to lowest + * (where fewer users have access to the highest clearance levels + * and therefore access to the most restricted documents). + */ + List getClearanceLevels(); } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java index cd4317e803..899613fe5d 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java @@ -22,6 +22,7 @@ import static org.alfresco.module.org_alfresco_module_rm.classification.model.Cl import static org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel.PROP_CLEARANCE_LEVEL; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl; @@ -35,6 +36,7 @@ import org.alfresco.util.ParameterCheck; /** * @author Neil Mc Erlean + * @author David Webster * @since 3.0 */ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements SecurityClearanceService @@ -195,4 +197,33 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec return getUserSecurityClearance(userName); } + + @Override + public List getClearanceLevels() + { + if (clearanceManager == null) + { + return Collections.emptyList(); + } + // FIXME Currently assume user has highest security clearance, this should be fixed as part of RM-2112. + ClearanceLevel usersLevel = clearanceManager.getMostSecureLevel(); + + return restrictList(clearanceManager.getClearanceLevels(), usersLevel); + } + + /** + * Create a list containing all clearance levels up to and including the supplied level. + * + * @param allLevels The list of all the clearance levels starting with the highest security. + * @param targetLevel The highest security clearance level that should be returned. If this is not found then + * an empty list will be returned. + * @return an immutable list of the levels that a user at the target level can see. + */ + List restrictList(List allLevels, ClearanceLevel targetLevel) + { + int targetIndex = allLevels.indexOf(targetLevel); + if (targetIndex == -1) { return Collections.emptyList(); } + List subList = allLevels.subList(targetIndex, allLevels.size()); + return Collections.unmodifiableList(subList); + } }