ContentAccessManager { @Transactional public Owner updateOwnerContentAccess(Owner owner, String updatedList, String updatedMode) { if (owner == null) { throw new IllegalArgumentException("owner is null"); } boolean listUpdated = false; boolean modeUpdated = false; this.ownerCurator.lock(owner); final String defaultMode = ContentAccessMode.getDefault().toDatabaseValue(); String currentList = this.resolveContentAccessValue(owner.getContentAccessModeList(), true); String currentMode = this.resolveContentAccessValue(owner.getContentAccessMode(), true); updatedList = this.resolveContentAccessValue(updatedList, false); updatedMode = this.resolveContentAccessValue(updatedMode, false); if (updatedList != null) { String[] modes = updatedList.split(","); for (String mode : modes) { ContentAccessMode.resolveModeName(mode); } listUpdated = !updatedList.equals(currentList); currentList = updatedList; if (updatedMode == null) { if (!ArrayUtils.contains(modes, currentMode)) { updatedMode = ArrayUtils.contains(modes, defaultMode) ? defaultMode : modes[0]; } } } if (updatedMode != null) { String[] modes = currentList.split(","); if (!ArrayUtils.contains(modes, updatedMode)) { throw new IllegalArgumentException( "Content access mode is not present in the owner's access mode list"); } modeUpdated = !(StringUtils.isEmpty(currentMode) ? ContentAccessMode.getDefault().matches(updatedMode) : currentMode.equals(updatedMode)); } if (listUpdated) { owner.setContentAccessModeList(updatedList); } if (modeUpdated) { owner.setContentAccessMode(updatedMode); owner = this.ownerCurator.merge(owner); ownerCurator.flush(); this.refreshOwnerForContentAccess(owner); this.eventSink.emitOwnerContentAccessModeChanged(owner); } else if (listUpdated) { owner = ownerCurator.merge(owner); ownerCurator.flush(); } if (listUpdated) { int culled = this.consumerCurator.cullInvalidConsumerContentAccess(owner, updatedList.split(",")); log.debug("Corrected {} consumers with content access modes which are no longer valid", culled); } return owner; } @Inject  ContentAccessManager(
        Configuration config,
        PKIUtility pki,
        X509V3ExtensionUtil v3extensionUtil,
        ContentAccessCertificateCurator contentAccessCertificateCurator,
        KeyPairCurator keyPairCurator,
        CertificateSerialCurator serialCurator,
        OwnerCurator ownerCurator,
        OwnerEnvContentAccessCurator ownerEnvContentAccessCurator,
        ConsumerCurator consumerCurator,
        ConsumerTypeCurator consumerTypeCurator,
        EnvironmentCurator environmentCurator,
        ContentAccessCertificateCurator contentAccessCertCurator,
        OwnerProductCurator ownerProductCurator,
        EventSink eventSink); @Transactional ContentAccessCertificate getCertificate(Consumer consumer); boolean hasCertChangedSince(Consumer consumer, Date date); @Transactional void removeContentAccessCert(Consumer consumer); @Transactional Owner updateOwnerContentAccess(Owner owner, String updatedList, String updatedMode); @Transactional void refreshOwnerForContentAccess(Owner owner);  }
@Test public void testUpdateOwnerContentAccessSetEmpty() { Owner owner = new Owner(); String contentAccessModeList = ""; String contentAccessMode = ""; ContentAccessManager manager = this.createManager(); manager.updateOwnerContentAccess(owner, contentAccessModeList, contentAccessMode); assertEquals(owner.getContentAccessModeList(), ContentAccessMode.getDefault().toDatabaseValue()); assertEquals(owner.getContentAccessMode(), ContentAccessMode.getDefault().toDatabaseValue()); }
@Test public void testUpdateOwnerContentAccessSetNull() { Owner owner = new Owner(); String initialAccessModeList = owner.getContentAccessModeList(); String initialAccessMode = owner.getContentAccessMode(); String contentAccessModeList = null; String contentAccessMode = null; ContentAccessManager manager = this.createManager(); manager.updateOwnerContentAccess(owner, contentAccessModeList, contentAccessMode); assertEquals(initialAccessModeList, owner.getContentAccessModeList()); assertEquals(initialAccessMode, owner.getContentAccessMode()); }
@Test public void testUpdateOwnerContentAccessSetNullRemainsUnchanged() { String initialAccessModeList = entitlementMode + "," + orgEnvironmentMode; String initialAccessMode = entitlementMode; Owner owner = new Owner() .setContentAccessModeList(initialAccessModeList) .setContentAccessMode(initialAccessMode); String updatedAccessModeList = null; String updatedAccessMode = null; ContentAccessManager manager = this.createManager(); manager.updateOwnerContentAccess(owner, updatedAccessModeList, updatedAccessMode); assertEquals(initialAccessModeList, owner.getContentAccessModeList()); assertEquals(initialAccessMode, owner.getContentAccessMode()); }
@Test public void testUpdateOwnerContentAccessUpdateListValidExistingMode() { String initialAccessModeList = entitlementMode + "," + orgEnvironmentMode; String initialAccessMode = orgEnvironmentMode; Owner owner = new Owner("test_owner", "test_owner") .setContentAccessModeList(initialAccessModeList) .setContentAccessMode(initialAccessMode); String updatedAccessModeList = orgEnvironmentMode; String updatedAccessMode = null; ContentAccessManager manager = this.createManager(); manager.updateOwnerContentAccess(owner, updatedAccessModeList, updatedAccessMode); assertEquals(updatedAccessModeList, owner.getContentAccessModeList()); assertEquals(orgEnvironmentMode, owner.getContentAccessMode()); }
@Test public void testUpdateOwnerContentAccessModeNotOnList() { Owner owner = new Owner("test_owner", "test_owner"); String updatedAccessModeList = entitlementMode; String updatedAccessMode = orgEnvironmentMode; ContentAccessManager manager = this.createManager(); assertThrows(IllegalArgumentException.class, () -> manager.updateOwnerContentAccess(owner, updatedAccessModeList, updatedAccessMode)); }
@Test public void testUpdateOwnerContentAccessExistingModeNotInUpdatedListDefaultPresent() { String initialAccessModeList = entitlementMode + "," + orgEnvironmentMode; String initialAccessMode = orgEnvironmentMode; Owner owner = new Owner("test_owner", "test_owner") .setContentAccessModeList(initialAccessModeList) .setContentAccessMode(initialAccessMode); String updatedAccessModeList = entitlementMode; String updatedAccessMode = null; ContentAccessManager manager = this.createManager(); manager.updateOwnerContentAccess(owner, updatedAccessModeList, updatedAccessMode); assertEquals(updatedAccessModeList, owner.getContentAccessModeList()); assertEquals(entitlementMode, owner.getContentAccessMode()); }
@Test public void testUpdateOwnerContentAccessExistingModeNotInUpdatedList() { String initialAccessModeList = entitlementMode + "," + orgEnvironmentMode; String initialAccessMode = entitlementMode; Owner owner = new Owner("test_owner", "test_owner") .setContentAccessModeList(initialAccessModeList) .setContentAccessMode(initialAccessMode); String updatedAccessModeList = orgEnvironmentMode; String updatedAccessMode = null; ContentAccessManager manager = this.createManager(); manager.updateOwnerContentAccess(owner, updatedAccessModeList, updatedAccessMode); assertEquals(updatedAccessModeList, owner.getContentAccessModeList()); assertEquals(orgEnvironmentMode, owner.getContentAccessMode()); }
@Test public void testUpdateOwnerContentAccessUpdatedModeNotInUpdatedList() { String initialAccessModeList = entitlementMode + "," + orgEnvironmentMode; String initialAccessMode = orgEnvironmentMode; Owner owner = new Owner("test_owner", "test_owner") .setContentAccessModeList(initialAccessModeList) .setContentAccessMode(initialAccessMode); String updatedAccessModeList = orgEnvironmentMode; String updatedAccessMode = entitlementMode; ContentAccessManager manager = this.createManager(); assertThrows(IllegalArgumentException.class, () -> manager.updateOwnerContentAccess(owner, updatedAccessModeList, updatedAccessMode)); }
@Test public void testUpdateOwnerContentAccessDefaultModeNotInUpdatedList() { String initialAccessModeList = entitlementMode + "," + orgEnvironmentMode; String initialAccessMode = orgEnvironmentMode; Owner owner = new Owner("test_owner", "test_owner") .setContentAccessModeList(initialAccessModeList) .setContentAccessMode(initialAccessMode); String updatedAccessModeList = orgEnvironmentMode; String updatedAccessMode = ""; ContentAccessManager manager = this.createManager(); assertThrows(IllegalArgumentException.class, () -> manager.updateOwnerContentAccess(owner, updatedAccessModeList, updatedAccessMode)); }
@Test public void testUpdateOwnerContentAccessModeNoList() { Owner owner = new Owner("test_owner", "test_owner"); String contentAccessModeList = ""; String contentAccessMode = orgEnvironmentMode; ContentAccessManager manager = this.createManager(); assertThrows(IllegalArgumentException.class, () -> manager.updateOwnerContentAccess(owner, contentAccessModeList, contentAccessMode)); }
@Test public void testUpdateOwnerContentAccessModeChanged() { Owner owner = new Owner(); String contentAccessModeList = entitlementMode + "," + orgEnvironmentMode; String contentAccessMode = orgEnvironmentMode; ContentAccessManager manager = this.createManager(); manager.updateOwnerContentAccess(owner, contentAccessModeList, contentAccessMode); assertEquals(owner.getContentAccessModeList(), contentAccessModeList); assertEquals(owner.getContentAccessMode(), contentAccessMode); }