mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.LevelIdNotFound;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link ClearanceLevelManager}.
|
||||
*
|
||||
* @author tpage
|
||||
*/
|
||||
public class ClearanceLevelManagerTest
|
||||
{
|
||||
static final ClassificationLevel TOP_SECRET = new ClassificationLevel("TS", "Top Secret Classification");
|
||||
static final ClassificationLevel SECRET = new ClassificationLevel("S", "Secret Classification");
|
||||
static final ClassificationLevel UNCLASSIFIED = new ClassificationLevel("U", "Unclassified Classification");
|
||||
|
||||
static final ClearanceLevel TOP_SECRET_CLEARANCE = new ClearanceLevel(TOP_SECRET , "Top Secret Clearance");
|
||||
static final ClearanceLevel SECRET_CLEARANCE = new ClearanceLevel(SECRET, "Secret Clearance");
|
||||
static final ClearanceLevel NO_CLEARANCE = new ClearanceLevel(UNCLASSIFIED, "No Clearance");
|
||||
|
||||
/** The class under test. */
|
||||
ClearanceLevelManager clearanceLevelManager;
|
||||
|
||||
/** Reset the {@code ClearanceLevelManager} with the three clearance levels. */
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
List<ClearanceLevel> clearanceLevels = ImmutableList.of(TOP_SECRET_CLEARANCE, SECRET_CLEARANCE, NO_CLEARANCE);
|
||||
clearanceLevelManager = new ClearanceLevelManager(clearanceLevels);
|
||||
}
|
||||
|
||||
/** Check that the secret clearance can be found from the classification level id "S". */
|
||||
@Test
|
||||
public void findLevelByClassificationLevelId_found()
|
||||
{
|
||||
ClearanceLevel actual = clearanceLevelManager.findLevelByClassificationLevelId("S");
|
||||
|
||||
assertEquals(SECRET_CLEARANCE, actual);
|
||||
}
|
||||
|
||||
/** Check that an exception is thrown when the classification level id is not found. */
|
||||
@Test(expected = LevelIdNotFound.class)
|
||||
public void findLevelByClassificationLevelId_notFound()
|
||||
{
|
||||
clearanceLevelManager.findLevelByClassificationLevelId("UNKNOWN ID");
|
||||
}
|
||||
}
|
@@ -26,6 +26,9 @@ import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.LevelIdNotFound;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
|
||||
@@ -56,6 +59,7 @@ public class SecurityClearanceServiceImplUnitTest
|
||||
@Mock private DictionaryService mockDictionaryService;
|
||||
@Mock private NodeService mockNodeService;
|
||||
@Mock private PersonService mockPersonService;
|
||||
@Mock private ClearanceLevelManager mockClearanceLevelManager;
|
||||
|
||||
@Before public void setUp()
|
||||
{
|
||||
@@ -87,12 +91,14 @@ public class SecurityClearanceServiceImplUnitTest
|
||||
final PersonInfo user1 = createMockPerson("user1", "User", "One", null);
|
||||
MockAuthenticationUtilHelper.setup(mockedAuthenticationUtil, user1.getUserName());
|
||||
|
||||
when(mockClassificationService.getDefaultClassificationLevel())
|
||||
.thenReturn(new ClassificationLevel("default", "default"));
|
||||
ClassificationLevel defaultClassificationLevel = new ClassificationLevel("default", "default");
|
||||
when(mockClassificationService.getDefaultClassificationLevel()).thenReturn(defaultClassificationLevel);
|
||||
ClearanceLevel defaultClearanceLevel = new ClearanceLevel(defaultClassificationLevel, "defaultClearanceMessageKey");
|
||||
when(mockClearanceLevelManager.findLevelByClassificationLevelId("default")).thenReturn(defaultClearanceLevel);
|
||||
|
||||
final SecurityClearance clearance = securityClearanceServiceImpl.getUserSecurityClearance();
|
||||
|
||||
assertEquals("default", clearance.getClearanceLevel().getId());
|
||||
assertEquals(defaultClearanceLevel, clearance.getClearanceLevel());
|
||||
}
|
||||
|
||||
/** Check that a user can have their clearance set. */
|
||||
@@ -111,6 +117,8 @@ public class SecurityClearanceServiceImplUnitTest
|
||||
String clearanceId = "ClearanceId";
|
||||
ClassificationLevel level = new ClassificationLevel(clearanceId, "TopSecretKey");
|
||||
when(mockClassificationService.getClassificationLevelById(clearanceId)).thenReturn(level);
|
||||
ClearanceLevel clearanceLevel = new ClearanceLevel(level, "TopSecretKey");
|
||||
when(mockClearanceLevelManager.findLevelByClassificationLevelId(clearanceId)).thenReturn(clearanceLevel);
|
||||
|
||||
when(mockNodeService.hasAspect(personNode, ASPECT_SECURITY_CLEARANCE)).thenReturn(true);
|
||||
when(mockNodeService.getProperty(personNode, PROP_CLEARANCE_LEVEL)).thenReturn(clearanceId);
|
||||
@@ -120,7 +128,7 @@ public class SecurityClearanceServiceImplUnitTest
|
||||
SecurityClearance securityClearance = securityClearanceServiceImpl.setUserSecurityClearance(userName, clearanceId);
|
||||
|
||||
assertEquals(personInfo, securityClearance.getPersonInfo());
|
||||
assertEquals(level, securityClearance.getClearanceLevel());
|
||||
assertEquals(clearanceLevel, securityClearance.getClearanceLevel());
|
||||
|
||||
verify(mockNodeService).setProperty(personNode, PROP_CLEARANCE_LEVEL, clearanceId);
|
||||
}
|
||||
@@ -141,4 +149,26 @@ public class SecurityClearanceServiceImplUnitTest
|
||||
|
||||
securityClearanceServiceImpl.setUserSecurityClearance(userName, clearanceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the initialise method creates a clearance level corresponding to each classification level and that
|
||||
* the display label for the lowest clearance level is "No Clearance" (rather than "Unclassified").
|
||||
*/
|
||||
@Test public void initialise()
|
||||
{
|
||||
ClassificationLevel topSecret = new ClassificationLevel("1", "TopSecret");
|
||||
ClassificationLevel secret = new ClassificationLevel("2", "Secret");
|
||||
ClassificationLevel unclassified = new ClassificationLevel("3", "Unclassified");
|
||||
List<ClassificationLevel> classificationLevels = Arrays.asList(topSecret, secret, unclassified);
|
||||
when(mockClassificationService.getClassificationLevels()).thenReturn(classificationLevels );
|
||||
|
||||
// Call the method under test.
|
||||
securityClearanceServiceImpl.initialise();
|
||||
|
||||
List<ClearanceLevel> clearanceLevels = securityClearanceServiceImpl.getClearanceManager().getClearanceLevels();
|
||||
assertEquals("There should be one clearance level for each classification level.", classificationLevels.size(), clearanceLevels.size());
|
||||
assertEquals("TopSecret", clearanceLevels.get(0).getDisplayLabel());
|
||||
assertEquals("Secret", clearanceLevels.get(1).getDisplayLabel());
|
||||
assertEquals("rm.classification.noClearance", clearanceLevels.get(2).getDisplayLabel());
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,10 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClearanceLevel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.SecurityClearance;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.SecurityClearanceService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.UserQueryParams;
|
||||
@@ -45,9 +48,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* Test for get user security clearance API
|
||||
*
|
||||
@@ -140,7 +140,7 @@ public class UserSecurityClearanceGetTest extends BaseWebScriptUnitTest
|
||||
assertEquals(firstName, securityClearance.getString("firstName"));
|
||||
assertEquals(lastName, securityClearance.getString("lastName"));
|
||||
assertEquals(classificationLevelId, securityClearance.getString("classificationId"));
|
||||
assertEquals(classificationLevelDisplayLabel, securityClearance.getString("classificationLabel"));
|
||||
assertEquals(classificationLevelDisplayLabel, securityClearance.getString("clearanceLabel"));
|
||||
String fullName = firstName + " " + lastName;
|
||||
assertEquals(fullName, securityClearance.getString("fullName"));
|
||||
assertEquals(fullName + " (" + userName + ")", securityClearance.getString("completeName"));
|
||||
@@ -221,7 +221,7 @@ public class UserSecurityClearanceGetTest extends BaseWebScriptUnitTest
|
||||
"\"lastName\": \"aLastName" + fromIndex + "\"," +
|
||||
"\"completeName\": \"aFirstName" + fromIndex + " aLastName" + fromIndex + " (aUserName" + fromIndex + ")\"," +
|
||||
"\"fullName\": \"aFirstName" + fromIndex + " aLastName" + fromIndex + "\"," +
|
||||
"\"classificationLabel\": \"displayLabel" + fromIndex + "\"," +
|
||||
"\"clearanceLabel\": \"displayLabel" + fromIndex + "\"," +
|
||||
"\"userName\": \"aUserName" + fromIndex + "\"," +
|
||||
"\"classificationId\": \"id" + fromIndex + "\"" +
|
||||
"}";
|
||||
@@ -240,7 +240,8 @@ public class UserSecurityClearanceGetTest extends BaseWebScriptUnitTest
|
||||
{
|
||||
PersonInfo personInfo = new PersonInfo(new NodeRef("a://noderef/" + i), "aUserName" + i, "aFirstName" + i, "aLastName" + i);
|
||||
ClassificationLevel classificationLevel = new ClassificationLevel("id" + i, "displayLabel" + i);
|
||||
SecurityClearance securityClearance = new SecurityClearance(personInfo, classificationLevel);
|
||||
ClearanceLevel clearanceLevel = new ClearanceLevel(classificationLevel, "displayLabel" + i);
|
||||
SecurityClearance securityClearance = new SecurityClearance(personInfo, clearanceLevel);
|
||||
securityClearances.add(securityClearance);
|
||||
}
|
||||
return securityClearances;
|
||||
|
@@ -1,9 +1,16 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.script.classification;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClearanceLevel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.SecurityClearance;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.SecurityClearanceService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest;
|
||||
@@ -16,11 +23,6 @@ import org.mockito.Spy;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class UserSecurityClearancePutTest extends BaseWebScriptUnitTest
|
||||
{
|
||||
/**
|
||||
@@ -74,7 +76,8 @@ public class UserSecurityClearancePutTest extends BaseWebScriptUnitTest
|
||||
String firstName = "Firstname";
|
||||
String lastName = "Lastname";
|
||||
PersonService.PersonInfo personInfo = new PersonService.PersonInfo(generateNodeRef(), username, firstName, lastName);
|
||||
ClassificationLevel clearanceLevel = new ClassificationLevel(clearanceId, clearanceDisplay);
|
||||
ClassificationLevel classificationLevel = new ClassificationLevel(clearanceId, clearanceDisplay);
|
||||
ClearanceLevel clearanceLevel = new ClearanceLevel(classificationLevel, clearanceDisplay);
|
||||
|
||||
SecurityClearance securityClearance = new SecurityClearance(personInfo, clearanceLevel);
|
||||
|
||||
@@ -89,7 +92,7 @@ public class UserSecurityClearancePutTest extends BaseWebScriptUnitTest
|
||||
|
||||
// check the JSON result using Jackson to allow easy equality testing.
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String expectedJSONString = "{\"data\":{\"firstName\":\"Firstname\",\"lastName\":\"Lastname\",\"completeName\":\"Firstname Lastname (user1)\",\"fullName\":\"Firstname Lastname\",\"classificationLabel\":\"Don't tell anyone\",\"userName\":\"user1\",\"classificationId\":\"Top Secret\"}}";
|
||||
String expectedJSONString = "{\"data\":{\"firstName\":\"Firstname\",\"lastName\":\"Lastname\",\"completeName\":\"Firstname Lastname (user1)\",\"fullName\":\"Firstname Lastname\",\"clearanceLabel\":\"Don't tell anyone\",\"userName\":\"user1\",\"classificationId\":\"Top Secret\"}}";
|
||||
JsonNode expected = mapper.readTree(expectedJSONString);
|
||||
assertEquals(expected, mapper.readTree(json.toString()));
|
||||
}
|
||||
|
Reference in New Issue
Block a user