()
+ {
+ public Void doWork()
+ {
+ AuthorityDAO authDao = (AuthorityDAO)applicationContext.getBean("authorityDAO");
+ if (!authDao.authorityExists(AuthenticationUtil.getSystemUserName()))
+ {
+ createPerson(AuthenticationUtil.getSystemUserName(), false);
+ }
+ assertTrue("No person object for System available.", authDao.authorityExists(AuthenticationUtil.getSystemUserName()));
+
+ siteId = GUID.generate();
+ siteService.createSite(
+ "rm-site-dashboard",
+ siteId,
+ "title",
+ "descrition",
+ SiteVisibility.PUBLIC,
+ RecordsManagementModel.TYPE_RM_SITE);
+
+ filePlan = siteService.getContainer(siteId, RmSiteType.COMPONENT_DOCUMENT_LIBRARY);
+ assertNotNull("Site document library container was not created successfully.", filePlan);
+
+ // Create RM container
+ rmContainer = filePlanService.createRecordCategory(filePlan, "rmContainer");
+ assertNotNull("Could not create rm container", rmContainer);
+
+ // Create RM folder
+ rmFolder = recordFolderService.createRecordFolder(rmContainer, "rmFolder");
+ assertNotNull("Could not create rm folder", rmFolder);
+
+ return null;
+ }
+ });
+ }
+
+ /**
+ * Mid-level user further downgrading a downgraded record.
+ *
+ * RM-2502
+ * Given I have "level2" clearance
+ * And a record has an initial classification of "level1"
+ * And the record has a current classification of "level2"
+ * When I try to downgrade the record to "level3"
+ * Then I am successful.
+ *
+ */
+ @Test
+ public void testInitialClassificationConstraint()
+ {
+ // Given I set up some test data (admin at level 1, midLevelUser at level 2 and a new record).
+ final String midLevelUser = GUID.generate();
+ final NodeRef record = AuthenticationUtil.runAsSystem(new RunAsWork()
+ {
+ public NodeRef doWork()
+ {
+ // Ensure admin is level 1 cleared.
+ securityClearanceService.setUserSecurityClearance(AuthenticationUtil.getAdminUserName(), "level1");
+ // Create user with level 2 clearance.
+ createPerson(midLevelUser, true);
+ filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_RECORDS_MANAGER, midLevelUser);
+ filePlanPermissionService.setPermission(rmContainer, midLevelUser, FILING);
+ securityClearanceService.setUserSecurityClearance(midLevelUser, "level2");
+ // Create a record to be classified during the test.
+ return utils.createRecord(rmFolder, RECORD_NAME);
+ }
+ });
+
+ // And admin creates a downgraded record.
+ AuthenticationUtil.runAs(new RunAsWork()
+ {
+ public Void doWork()
+ {
+ // Create a level 1 record and downgrade it to level 2.
+ classifyAs(record, "level1");
+ classifyAs(record, "level2");
+
+ assertTrue("Record should have been classified.",
+ nodeService.hasAspect(record, ClassifiedContentModel.ASPECT_CLASSIFIED));
+ assertEquals("Record have initial classification of 'level1'.", "level1",
+ nodeService.getProperty(record, ClassifiedContentModel.PROP_INITIAL_CLASSIFICATION));
+ assertEquals("Record should be 'level2' classified.", "level2",
+ nodeService.getProperty(record, ClassifiedContentModel.PROP_CURRENT_CLASSIFICATION));
+ return null;
+ }
+ }, AuthenticationUtil.getAdminUserName());
+
+ // When the mid-level user downgrades the record to level 3.
+ AuthenticationUtil.runAs(new RunAsWork()
+ {
+ public Void doWork()
+ {
+ // Check that the mid-clearance user can further downgrade the classification (even though the initial
+ // classification was above their clearance).
+ classifyAs(record, "level3");
+ return null;
+ }
+ }, midLevelUser);
+
+ // Then the record is classified at level 3 (with initial classification level 1).
+ AuthenticationUtil.runAs(new RunAsWork()
+ {
+ public Void doWork()
+ {
+ assertTrue("Record should still be classified.",
+ nodeService.hasAspect(record, ClassifiedContentModel.ASPECT_CLASSIFIED));
+ assertEquals("Record have initial classification of 'level1'.", "level1",
+ nodeService.getProperty(record, ClassifiedContentModel.PROP_INITIAL_CLASSIFICATION));
+ assertEquals("Record should be 'level3' classified.", "level3",
+ nodeService.getProperty(record, ClassifiedContentModel.PROP_CURRENT_CLASSIFICATION));
+ return null;
+ }
+ }, AuthenticationUtil.getAdminUserName());
+ }
+
+ /**
+ * Util method to create a person.
+ *
+ * @param userName user name
+ * @param createAuth Whether to give the user a password or not.
+ * @return NodeRef user node reference
+ */
+ private NodeRef createPerson(String userName, boolean createAuth)
+ {
+ if (createAuth)
+ {
+ authenticationService.createAuthentication(userName, "password".toCharArray());
+ }
+ Map properties = new HashMap();
+ properties.put(ContentModel.PROP_USERNAME, userName);
+ return personService.createPerson(properties);
+ }
+
+ /**
+ * Classify the given node.
+ *
+ * @param node The node to classify.
+ * @param level The id of the classification level to use.
+ */
+ private void classifyAs(final NodeRef node, final String level)
+ {
+ ClassificationAspectProperties propertiesDTO = new ClassificationAspectProperties();
+ propertiesDTO.setClassificationLevelId(level);
+ propertiesDTO.setClassifiedBy(CLASSIFIED_BY);
+ propertiesDTO.setClassificationReasonIds(Collections.singleton(CLASSIFICATION_REASON));
+ contentClassificationService.editClassifiedContent(propertiesDTO, node);
+ }
+}