RM-2197 Replace "No Clearance" with "Unclassified" in list of levels.

Created a notion of clearance level distinct from (but related to)
classification level. A clearance level references the highest
classification level it has access to. A SecurityClearance now contains a
ClearanceLevel, which in turn contains a ClassificationLevel.

Created a ClearanceLevelManager and initialise it at the same time as the
ClassificationLevelManager.

+review RM

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@103929 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tom Page
2015-05-11 08:16:03 +00:00
parent 960a3da39e
commit d60071421e
15 changed files with 348 additions and 41 deletions

View File

@@ -35,7 +35,7 @@ public final class ClassificationLevel implements Serializable
{
/** serial version uid */
private static final long serialVersionUID = -3375064867090476422L;
private final String id;
private final String displayLabelKey;
@@ -50,6 +50,9 @@ public final class ClassificationLevel implements Serializable
/** Returns the unique identifier for this classification level. */
public String getId() { return this.id; }
/** Returns the key for the display label. */
public String getDisplayLabelKey() { return displayLabelKey; }
/**
* Returns the localised (current locale) display label for this classification level. If no translation is found
* then return the key instead.

View File

@@ -32,17 +32,20 @@ import org.springframework.extensions.surf.util.AbstractLifecycleBean;
*/
public class ClassificationServiceBootstrap extends AbstractLifecycleBean
{
private final AuthenticationUtil authenticationUtil;
private final ClassificationServiceImpl classificationServiceImpl;
private final TransactionService transactionService;
private final AuthenticationUtil authenticationUtil;
private final ClassificationServiceImpl classificationServiceImpl;
private final SecurityClearanceServiceImpl securityClearanceServiceImpl;
private final TransactionService transactionService;
public ClassificationServiceBootstrap(AuthenticationUtil authUtil,
ClassificationServiceImpl cService,
SecurityClearanceServiceImpl securityClearanceServiceImpl,
TransactionService txService)
{
this.authenticationUtil = authUtil;
this.classificationServiceImpl = cService;
this.transactionService = txService;
this.authenticationUtil = authUtil;
this.classificationServiceImpl = cService;
this.securityClearanceServiceImpl = securityClearanceServiceImpl;
this.transactionService = txService;
}
@Override protected void onBootstrap(ApplicationEvent event)
@@ -55,8 +58,8 @@ public class ClassificationServiceBootstrap extends AbstractLifecycleBean
{
public Void execute()
{
classificationServiceImpl.initConfiguredClassificationLevels();
classificationServiceImpl.initConfiguredClassificationReasons();
classificationServiceImpl.initialise();
securityClearanceServiceImpl.initialise();
return null;
}
};

View File

@@ -74,7 +74,13 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
/** Set the object from which configuration options will be read. */
public void setClassificationServiceDAO(ClassificationServiceDAO classificationServiceDao) { this.classificationServiceDao = classificationServiceDao; }
void initConfiguredClassificationLevels()
void initialise()
{
initConfiguredClassificationLevels();
initConfiguredClassificationReasons();
}
protected void initConfiguredClassificationLevels()
{
final List<ClassificationLevel> allPersistedLevels = getPersistedLevels();
final List<ClassificationLevel> configurationLevels = getConfigurationLevels();
@@ -98,7 +104,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
}
}
void initConfiguredClassificationReasons()
protected void initConfiguredClassificationReasons()
{
final List<ClassificationReason> persistedReasons = getPersistedReasons();
final List<ClassificationReason> classpathReasons = getConfigurationReasons();

View File

@@ -0,0 +1,87 @@
/*
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.classification;
import static org.apache.commons.lang.StringUtils.isNotBlank;
import org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck;
import org.alfresco.util.ParameterCheck;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* A POJO to represent a security clearance level. This wraps a {@link ClassificationLevel} and will often have the same
* display text as well. The main exception is that the clearance level corresponding to "Unclassified" is "No Clearance".
*
* @author tpage
*/
public class ClearanceLevel
{
/** The highest classification level that can be accessed by users with this clearance. */
private final ClassificationLevel highestClassificationLevel;
/** The key for the display label of this security clearance. */
private final String displayLabelKey;
/**
* Constructor.
*
* @param highestClassificationLevel The highest classification level that can be accessed by users with this clearance.
* @param displayLabelKey The key for the display label of this security clearance.
*/
public ClearanceLevel(ClassificationLevel highestClassificationLevel, String displayLabelKey)
{
ParameterCheck.mandatory("highestClassificationLevel", highestClassificationLevel);
RMParameterCheck.checkNotBlank("displayLabelKey", displayLabelKey);
this.highestClassificationLevel = highestClassificationLevel;
this.displayLabelKey = displayLabelKey;
}
/** Return the highest classification level that can be accessed by users with this clearance. */
public ClassificationLevel getHighestClassificationLevel() { return this.highestClassificationLevel; }
/**
* Returns the localised (current locale) display label for this clearance level. If no translation is found
* then return the key instead.
*/
public String getDisplayLabel()
{
String message = I18NUtil.getMessage(displayLabelKey);
return (isNotBlank(message) ? message : displayLabelKey);
}
@Override public String toString()
{
StringBuilder msg = new StringBuilder();
msg.append(ClassificationLevel.class.getSimpleName())
.append(":").append(highestClassificationLevel.getId());
return msg.toString();
}
@Override public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClearanceLevel that = (ClearanceLevel) o;
return this.highestClassificationLevel.equals(that.highestClassificationLevel);
}
@Override public int hashCode() { return highestClassificationLevel.hashCode(); }
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.classification;
import java.util.List;
import com.google.common.collect.ImmutableList;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.LevelIdNotFound;
/**
* Container for the configured {@link ClearanceLevel} objects.
*
* @author tpage
*/
public class ClearanceLevelManager
{
/** An immutable list of clearance levels ordered from most to least secure. */
private ImmutableList<ClearanceLevel> clearanceLevels;
/**
* Constructor that stores an immutable copy of the given levels.
*
* @param clearanceLevels A list of clearance levels ordered from most to least secure.
*/
public ClearanceLevelManager(List<ClearanceLevel> clearanceLevels)
{
this.clearanceLevels = ImmutableList.copyOf(clearanceLevels);
}
/** @return An immutable list of clearance levels ordered from most to least secure. */
public ImmutableList<ClearanceLevel> getClearanceLevels()
{
return clearanceLevels;
}
/**
* Get a <code>ClearanceLevel</code> using its id.
*
* @param classificationLevelId The id of the highest classification level accessible by a clearance level.
* @return The clearance level.
* @throws LevelIdNotFound If the clearance level cannot be found.
*/
public ClearanceLevel findLevelByClassificationLevelId(String classificationLevelId) throws LevelIdNotFound
{
for (ClearanceLevel clearanceLevel : clearanceLevels)
{
if (clearanceLevel.getHighestClassificationLevel().getId().equals(classificationLevelId))
{
return clearanceLevel;
}
}
throw new LevelIdNotFound(classificationLevelId);
}
}

View File

@@ -18,11 +18,11 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification;
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
import java.io.Serializable;
import java.util.Objects;
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
/**
* A simple data type for a single user's security clearance.
*
@@ -34,10 +34,10 @@ public final class SecurityClearance implements Serializable
/** Serial version uid */
private static final long serialVersionUID = 8410664575120817707L;
private final PersonInfo personInfo;
private final ClassificationLevel clearanceLevel;
private final PersonInfo personInfo;
private final ClearanceLevel clearanceLevel;
public SecurityClearance(final PersonInfo personInfo, final ClassificationLevel clearanceLevel)
public SecurityClearance(final PersonInfo personInfo, final ClearanceLevel clearanceLevel)
{
Objects.requireNonNull(personInfo);
Objects.requireNonNull(clearanceLevel);
@@ -49,8 +49,8 @@ public final class SecurityClearance implements Serializable
/** Returns the {@link PersonInfo} for this security clearance. */
public PersonInfo getPersonInfo() { return this.personInfo; }
/** Returns the {@link ClassificationLevel} for this security clearance. */
public ClassificationLevel getClearanceLevel() { return this.clearanceLevel; }
/** Returns the {@link ClearanceLevel} for this security clearance. */
public ClearanceLevel getClearanceLevel() { return this.clearanceLevel; }
@Override public String toString()
{

View File

@@ -39,11 +39,39 @@ import org.alfresco.util.ParameterCheck;
*/
public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements SecurityClearanceService
{
/** The clearance levels currently configured in this server. */
private ClearanceLevelManager clearanceManager;
private ClassificationService classificationService;
private PersonService personService;
public void setClearanceManager(ClearanceLevelManager clearanceManager) { this.clearanceManager = clearanceManager; }
public void setClassificationService(ClassificationService service) { this.classificationService = service; }
public void setPersonService (PersonService service) { this.personService = service; }
public void setPersonService(PersonService service) { this.personService = service; }
/**
* Initialise and create a {@link ClearanceLevelManager}. This assumes that the {@link ClassificationService} has
* already been initialised.
*/
void initialise()
{
ArrayList<ClearanceLevel> clearanceLevels = new ArrayList<ClearanceLevel>();
List<ClassificationLevel> classificationLevels = classificationService.getClassificationLevels();
ClassificationLevel unclassified = classificationLevels.get(classificationLevels.size() - 1);
for (ClassificationLevel classificationLevel : classificationLevels)
{
String displayLabelKey = classificationLevel.getDisplayLabelKey();
if (classificationLevel.equals(unclassified))
{
displayLabelKey = "rm.classification.noClearance";
}
clearanceLevels.add(new ClearanceLevel(classificationLevel, displayLabelKey));
}
this.clearanceManager = new ClearanceLevelManager(clearanceLevels);
}
/** Get the clearance manager (for use in unit testing). */
protected ClearanceLevelManager getClearanceManager() { return clearanceManager; }
@Override
public SecurityClearance getUserSecurityClearance()
@@ -70,7 +98,8 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
}
else { classificationLevel = classificationService.getDefaultClassificationLevel(); }
return new SecurityClearance(personInfo, classificationLevel);
ClearanceLevel clearanceLevel = clearanceManager.findLevelByClassificationLevelId(classificationLevel.getId());
return new SecurityClearance(personInfo, clearanceLevel);
}
@Override