@Test(expected = AuthorizerCreationException.class) public void testOnConfiguredWithBadTenantsSchema() throws Exception { writeFile(primaryTenants, BAD_SCHEMA_TENANTS); userGroupProvider.onConfigured(configurationContext); }
@Override public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { try { final PropertyValue tenantsPath = configurationContext.getProperty(PROP_TENANTS_FILE); if (StringUtils.isBlank(tenantsPath.getValue())) { throw new AuthorizerCreationException("The users file must be specified."); } tenantsFile = new File(tenantsPath.getValue()); if (!tenantsFile.exists()) { logger.info("Creating new users file at {}", new Object[] {tenantsFile.getAbsolutePath()}); saveTenants(new Tenants()); } final File tenantsFileDirectory = tenantsFile.getAbsoluteFile().getParentFile(); final File restoreDirectory = properties.getRestoreDirectory(); if (restoreDirectory != null) { FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory); if (tenantsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) { throw new AuthorizerCreationException(String.format("Users file directory '%s' is the same as restore directory '%s' ", tenantsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath())); } restoreTenantsFile = new File(restoreDirectory, tenantsFile.getName()); try { FileUtils.syncWithRestore(tenantsFile, restoreTenantsFile, logger); } catch (final IOException | IllegalStateException ioe) { throw new AuthorizerCreationException(ioe); } } identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties)); groupMappings = Collections.unmodifiableList(IdentityMappingUtil.getGroupMappings(properties)); final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE); legacyAuthorizedUsersFile = legacyAuthorizedUsersProp.isSet() ? legacyAuthorizedUsersProp.getValue() : null; initialUserIdentities = new HashSet<>(); for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) { Matcher matcher = INITIAL_USER_IDENTITY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) { initialUserIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings)); } } load(); if (restoreTenantsFile != null) { FileUtils.copyFile(tenantsFile, restoreTenantsFile, false, false, logger); } logger.info(String.format("Users/Groups file loaded at %s", new Date().toString())); } catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) { throw new AuthorizerCreationException(e); } }
FileUserGroupProvider implements ConfigurableUserGroupProvider { @Override public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { try { final PropertyValue tenantsPath = configurationContext.getProperty(PROP_TENANTS_FILE); if (StringUtils.isBlank(tenantsPath.getValue())) { throw new AuthorizerCreationException("The users file must be specified."); } tenantsFile = new File(tenantsPath.getValue()); if (!tenantsFile.exists()) { logger.info("Creating new users file at {}", new Object[] {tenantsFile.getAbsolutePath()}); saveTenants(new Tenants()); } final File tenantsFileDirectory = tenantsFile.getAbsoluteFile().getParentFile(); final File restoreDirectory = properties.getRestoreDirectory(); if (restoreDirectory != null) { FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory); if (tenantsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) { throw new AuthorizerCreationException(String.format("Users file directory '%s' is the same as restore directory '%s' ", tenantsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath())); } restoreTenantsFile = new File(restoreDirectory, tenantsFile.getName()); try { FileUtils.syncWithRestore(tenantsFile, restoreTenantsFile, logger); } catch (final IOException | IllegalStateException ioe) { throw new AuthorizerCreationException(ioe); } } identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties)); groupMappings = Collections.unmodifiableList(IdentityMappingUtil.getGroupMappings(properties)); final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE); legacyAuthorizedUsersFile = legacyAuthorizedUsersProp.isSet() ? legacyAuthorizedUsersProp.getValue() : null; initialUserIdentities = new HashSet<>(); for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) { Matcher matcher = INITIAL_USER_IDENTITY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) { initialUserIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings)); } } load(); if (restoreTenantsFile != null) { FileUtils.copyFile(tenantsFile, restoreTenantsFile, false, false, logger); } logger.info(String.format("Users/Groups file loaded at %s", new Date().toString())); } catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) { throw new AuthorizerCreationException(e); } } }
FileUserGroupProvider implements ConfigurableUserGroupProvider { @Override public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { try { final PropertyValue tenantsPath = configurationContext.getProperty(PROP_TENANTS_FILE); if (StringUtils.isBlank(tenantsPath.getValue())) { throw new AuthorizerCreationException("The users file must be specified."); } tenantsFile = new File(tenantsPath.getValue()); if (!tenantsFile.exists()) { logger.info("Creating new users file at {}", new Object[] {tenantsFile.getAbsolutePath()}); saveTenants(new Tenants()); } final File tenantsFileDirectory = tenantsFile.getAbsoluteFile().getParentFile(); final File restoreDirectory = properties.getRestoreDirectory(); if (restoreDirectory != null) { FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory); if (tenantsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) { throw new AuthorizerCreationException(String.format("Users file directory '%s' is the same as restore directory '%s' ", tenantsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath())); } restoreTenantsFile = new File(restoreDirectory, tenantsFile.getName()); try { FileUtils.syncWithRestore(tenantsFile, restoreTenantsFile, logger); } catch (final IOException | IllegalStateException ioe) { throw new AuthorizerCreationException(ioe); } } identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties)); groupMappings = Collections.unmodifiableList(IdentityMappingUtil.getGroupMappings(properties)); final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE); legacyAuthorizedUsersFile = legacyAuthorizedUsersProp.isSet() ? legacyAuthorizedUsersProp.getValue() : null; initialUserIdentities = new HashSet<>(); for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) { Matcher matcher = INITIAL_USER_IDENTITY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) { initialUserIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings)); } } load(); if (restoreTenantsFile != null) { FileUtils.copyFile(tenantsFile, restoreTenantsFile, false, false, logger); } logger.info(String.format("Users/Groups file loaded at %s", new Date().toString())); } catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) { throw new AuthorizerCreationException(e); } }  }
FileUserGroupProvider implements ConfigurableUserGroupProvider { @Override public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { try { final PropertyValue tenantsPath = configurationContext.getProperty(PROP_TENANTS_FILE); if (StringUtils.isBlank(tenantsPath.getValue())) { throw new AuthorizerCreationException("The users file must be specified."); } tenantsFile = new File(tenantsPath.getValue()); if (!tenantsFile.exists()) { logger.info("Creating new users file at {}", new Object[] {tenantsFile.getAbsolutePath()}); saveTenants(new Tenants()); } final File tenantsFileDirectory = tenantsFile.getAbsoluteFile().getParentFile(); final File restoreDirectory = properties.getRestoreDirectory(); if (restoreDirectory != null) { FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory); if (tenantsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) { throw new AuthorizerCreationException(String.format("Users file directory '%s' is the same as restore directory '%s' ", tenantsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath())); } restoreTenantsFile = new File(restoreDirectory, tenantsFile.getName()); try { FileUtils.syncWithRestore(tenantsFile, restoreTenantsFile, logger); } catch (final IOException | IllegalStateException ioe) { throw new AuthorizerCreationException(ioe); } } identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties)); groupMappings = Collections.unmodifiableList(IdentityMappingUtil.getGroupMappings(properties)); final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE); legacyAuthorizedUsersFile = legacyAuthorizedUsersProp.isSet() ? legacyAuthorizedUsersProp.getValue() : null; initialUserIdentities = new HashSet<>(); for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) { Matcher matcher = INITIAL_USER_IDENTITY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) { initialUserIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings)); } } load(); if (restoreTenantsFile != null) { FileUtils.copyFile(tenantsFile, restoreTenantsFile, false, false, logger); } logger.info(String.format("Users/Groups file loaded at %s", new Date().toString())); } catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) { throw new AuthorizerCreationException(e); } }  @Override void initialize(UserGroupProviderInitializationContext initializationContext); @Override void onConfigured(AuthorizerConfigurationContext configurationContext); @Override Set<User> getUsers(); @Override synchronized User addUser(User user); @Override User getUser(String identifier); @Override synchronized User updateUser(User user); @Override User getUserByIdentity(String identity); @Override synchronized User deleteUser(User user); @Override Set<Group> getGroups(); @Override synchronized Group addGroup(Group group); @Override Group getGroup(String identifier); @Override UserAndGroups getUserAndGroups(final String identity); @Override synchronized Group updateGroup(Group group); @Override synchronized Group deleteGroup(Group group); @AuthorizerContext void setNiFiProperties(NiFiProperties properties); @Override synchronized void inheritFingerprint(String fingerprint); @Override void checkInheritability(String proposedFingerprint); @Override String getFingerprint(); @Override void preDestruction(); }
FileUserGroupProvider implements ConfigurableUserGroupProvider { @Override public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { try { final PropertyValue tenantsPath = configurationContext.getProperty(PROP_TENANTS_FILE); if (StringUtils.isBlank(tenantsPath.getValue())) { throw new AuthorizerCreationException("The users file must be specified."); } tenantsFile = new File(tenantsPath.getValue()); if (!tenantsFile.exists()) { logger.info("Creating new users file at {}", new Object[] {tenantsFile.getAbsolutePath()}); saveTenants(new Tenants()); } final File tenantsFileDirectory = tenantsFile.getAbsoluteFile().getParentFile(); final File restoreDirectory = properties.getRestoreDirectory(); if (restoreDirectory != null) { FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory); if (tenantsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) { throw new AuthorizerCreationException(String.format("Users file directory '%s' is the same as restore directory '%s' ", tenantsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath())); } restoreTenantsFile = new File(restoreDirectory, tenantsFile.getName()); try { FileUtils.syncWithRestore(tenantsFile, restoreTenantsFile, logger); } catch (final IOException | IllegalStateException ioe) { throw new AuthorizerCreationException(ioe); } } identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties)); groupMappings = Collections.unmodifiableList(IdentityMappingUtil.getGroupMappings(properties)); final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE); legacyAuthorizedUsersFile = legacyAuthorizedUsersProp.isSet() ? legacyAuthorizedUsersProp.getValue() : null; initialUserIdentities = new HashSet<>(); for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) { Matcher matcher = INITIAL_USER_IDENTITY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) { initialUserIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings)); } } load(); if (restoreTenantsFile != null) { FileUtils.copyFile(tenantsFile, restoreTenantsFile, false, false, logger); } logger.info(String.format("Users/Groups file loaded at %s", new Date().toString())); } catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) { throw new AuthorizerCreationException(e); } }  @Override void initialize(UserGroupProviderInitializationContext initializationContext); @Override void onConfigured(AuthorizerConfigurationContext configurationContext); @Override Set<User> getUsers(); @Override synchronized User addUser(User user); @Override User getUser(String identifier); @Override synchronized User updateUser(User user); @Override User getUserByIdentity(String identity); @Override synchronized User deleteUser(User user); @Override Set<Group> getGroups(); @Override synchronized Group addGroup(Group group); @Override Group getGroup(String identifier); @Override UserAndGroups getUserAndGroups(final String identity); @Override synchronized Group updateGroup(Group group); @Override synchronized Group deleteGroup(Group group); @AuthorizerContext void setNiFiProperties(NiFiProperties properties); @Override synchronized void inheritFingerprint(String fingerprint); @Override void checkInheritability(String proposedFingerprint); @Override String getFingerprint(); @Override void preDestruction();  }