PrincipalPolicyImporter implements ProtectedNodeImporter, ProtectedPropertyImporter, Constants { @Override public boolean handlePropInfo(@NotNull Tree parent, @NotNull PropInfo protectedPropInfo, @NotNull PropertyDefinition def) throws RepositoryException { checkState(initialized); if (!Utils.isPrincipalPolicyTree(parent) || !isValidPrincipalProperty(protectedPropInfo, def)) { return false; } String accessControlledPath = PathUtils.getParentPath(parent.getPath()); if (!filterProvider.handlesPath(accessControlledPath)) { log.debug("Unable to import principal policy. Access controlled path '{}' outside of path supported by FilterProvider.", accessControlledPath); return false; } String principalName = protectedPropInfo.getTextValue().getString(); Principal principal = filter.getValidPrincipal(accessControlledPath); if (principal == null) { log.debug("Unable to lookup principal by path = {}. Creating by name {}.", accessControlledPath, principalName); principal = new PrincipalImpl(principalName); } else if (!principalName.equals(principal.getName())) { log.error("Principal name mismatch expected '{}' but was '{}'.", principalName, principal.getName()); throw new ConstraintViolationException("Principal name mismatch."); } if (!Utils.canHandle(principal, filter, importBehavior)) { log.debug("Cannot handle principal {} with name = {}", principal, principalName); return false; } session.checkPermission(accessControlledPath, Permissions.getString(Permissions.READ_ACCESS_CONTROL)); policy = new PrincipalPolicyImpl(principal, accessControlledPath, mgrProvider); return true; } PrincipalPolicyImporter(@NotNull FilterProvider filterProvider, @NotNull MgrProvider mgrProvider); @Override boolean init(@NotNull Session session, @NotNull Root root, @NotNull NamePathMapper namePathMapper, boolean isWorkspaceImport, int uuidBehavior, @NotNull ReferenceChangeTracker referenceTracker, @NotNull SecurityProvider securityProvider); @Override void processReferences(); @Override boolean handlePropInfo(@NotNull Tree parent, @NotNull PropInfo protectedPropInfo, @NotNull PropertyDefinition def); @Override void propertiesCompleted(@NotNull Tree protectedParent); @Override boolean start(@NotNull Tree protectedParent); @Override void end(@NotNull Tree protectedParent); @Override void startChildInfo(@NotNull NodeInfo childInfo, @NotNull List<PropInfo> propInfos); @Override void endChildInfo();  }
@Test(expected = IllegalStateException.class) public void testHandlePropInfoNotInitialized() throws Exception { importer.handlePropInfo(mock(Tree.class), mock(PropInfo.class), mock(PropertyDefinition.class)); }