@Test(expected = AuthorizerCreationException.class) public void testOnConfiguredWhenPrimaryDoesNotExist() throws Exception { writeFile(restoreAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE); userGroupProvider.onConfigured(configurationContext); accessPolicyProvider.onConfigured(configurationContext); }
@Override public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { try { final PropertyValue userGroupProviderIdentifier = configurationContext.getProperty(PROP_USER_GROUP_PROVIDER); if (!userGroupProviderIdentifier.isSet()) { throw new AuthorizerCreationException("The user group provider must be specified."); } userGroupProvider = userGroupProviderLookup.getUserGroupProvider(userGroupProviderIdentifier.getValue()); if (userGroupProvider == null) { throw new AuthorizerCreationException("Unable to locate user group provider with identifier " + userGroupProviderIdentifier.getValue()); } final PropertyValue authorizationsPath = configurationContext.getProperty(PROP_AUTHORIZATIONS_FILE); if (StringUtils.isBlank(authorizationsPath.getValue())) { throw new AuthorizerCreationException("The authorizations file must be specified."); } authorizationsFile = new File(authorizationsPath.getValue()); if (!authorizationsFile.exists()) { logger.info("Creating new authorizations file at {}", new Object[] {authorizationsFile.getAbsolutePath()}); saveAuthorizations(new Authorizations()); } final File authorizationsFileDirectory = authorizationsFile.getAbsoluteFile().getParentFile(); final File restoreDirectory = properties.getRestoreDirectory(); if (restoreDirectory != null) { FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory); if (authorizationsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) { throw new AuthorizerCreationException(String.format("Authorizations file directory '%s' is the same as restore directory '%s' ", authorizationsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath())); } restoreAuthorizationsFile = new File(restoreDirectory, authorizationsFile.getName()); try { FileUtils.syncWithRestore(authorizationsFile, restoreAuthorizationsFile, logger); } catch (final IOException | IllegalStateException ioe) { throw new AuthorizerCreationException(ioe); } } identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties)); groupMappings = Collections.unmodifiableList(IdentityMappingUtil.getGroupMappings(properties)); final PropertyValue initialAdminIdentityProp = configurationContext.getProperty(PROP_INITIAL_ADMIN_IDENTITY); initialAdminIdentity = initialAdminIdentityProp.isSet() ? IdentityMappingUtil.mapIdentity(initialAdminIdentityProp.getValue(), identityMappings) : null; NiFiUserUtils.setAdminIdentity(initialAdminIdentity); final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE); legacyAuthorizedUsersFile = legacyAuthorizedUsersProp.isSet() ? legacyAuthorizedUsersProp.getValue() : null; nodeIdentities = new HashSet<>(); for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) { Matcher matcher = NODE_IDENTITY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) { nodeIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings)); } } load(); if (restoreAuthorizationsFile != null) { FileUtils.copyFile(authorizationsFile, restoreAuthorizationsFile, false, false, logger); } logger.info(String.format("Authorizations file loaded at %s", new Date().toString())); } catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) { throw new AuthorizerCreationException(e); } }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { try { final PropertyValue userGroupProviderIdentifier = configurationContext.getProperty(PROP_USER_GROUP_PROVIDER); if (!userGroupProviderIdentifier.isSet()) { throw new AuthorizerCreationException("The user group provider must be specified."); } userGroupProvider = userGroupProviderLookup.getUserGroupProvider(userGroupProviderIdentifier.getValue()); if (userGroupProvider == null) { throw new AuthorizerCreationException("Unable to locate user group provider with identifier " + userGroupProviderIdentifier.getValue()); } final PropertyValue authorizationsPath = configurationContext.getProperty(PROP_AUTHORIZATIONS_FILE); if (StringUtils.isBlank(authorizationsPath.getValue())) { throw new AuthorizerCreationException("The authorizations file must be specified."); } authorizationsFile = new File(authorizationsPath.getValue()); if (!authorizationsFile.exists()) { logger.info("Creating new authorizations file at {}", new Object[] {authorizationsFile.getAbsolutePath()}); saveAuthorizations(new Authorizations()); } final File authorizationsFileDirectory = authorizationsFile.getAbsoluteFile().getParentFile(); final File restoreDirectory = properties.getRestoreDirectory(); if (restoreDirectory != null) { FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory); if (authorizationsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) { throw new AuthorizerCreationException(String.format("Authorizations file directory '%s' is the same as restore directory '%s' ", authorizationsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath())); } restoreAuthorizationsFile = new File(restoreDirectory, authorizationsFile.getName()); try { FileUtils.syncWithRestore(authorizationsFile, restoreAuthorizationsFile, logger); } catch (final IOException | IllegalStateException ioe) { throw new AuthorizerCreationException(ioe); } } identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties)); groupMappings = Collections.unmodifiableList(IdentityMappingUtil.getGroupMappings(properties)); final PropertyValue initialAdminIdentityProp = configurationContext.getProperty(PROP_INITIAL_ADMIN_IDENTITY); initialAdminIdentity = initialAdminIdentityProp.isSet() ? IdentityMappingUtil.mapIdentity(initialAdminIdentityProp.getValue(), identityMappings) : null; NiFiUserUtils.setAdminIdentity(initialAdminIdentity); final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE); legacyAuthorizedUsersFile = legacyAuthorizedUsersProp.isSet() ? legacyAuthorizedUsersProp.getValue() : null; nodeIdentities = new HashSet<>(); for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) { Matcher matcher = NODE_IDENTITY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) { nodeIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings)); } } load(); if (restoreAuthorizationsFile != null) { FileUtils.copyFile(authorizationsFile, restoreAuthorizationsFile, false, false, logger); } logger.info(String.format("Authorizations file loaded at %s", new Date().toString())); } catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) { throw new AuthorizerCreationException(e); } } }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { try { final PropertyValue userGroupProviderIdentifier = configurationContext.getProperty(PROP_USER_GROUP_PROVIDER); if (!userGroupProviderIdentifier.isSet()) { throw new AuthorizerCreationException("The user group provider must be specified."); } userGroupProvider = userGroupProviderLookup.getUserGroupProvider(userGroupProviderIdentifier.getValue()); if (userGroupProvider == null) { throw new AuthorizerCreationException("Unable to locate user group provider with identifier " + userGroupProviderIdentifier.getValue()); } final PropertyValue authorizationsPath = configurationContext.getProperty(PROP_AUTHORIZATIONS_FILE); if (StringUtils.isBlank(authorizationsPath.getValue())) { throw new AuthorizerCreationException("The authorizations file must be specified."); } authorizationsFile = new File(authorizationsPath.getValue()); if (!authorizationsFile.exists()) { logger.info("Creating new authorizations file at {}", new Object[] {authorizationsFile.getAbsolutePath()}); saveAuthorizations(new Authorizations()); } final File authorizationsFileDirectory = authorizationsFile.getAbsoluteFile().getParentFile(); final File restoreDirectory = properties.getRestoreDirectory(); if (restoreDirectory != null) { FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory); if (authorizationsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) { throw new AuthorizerCreationException(String.format("Authorizations file directory '%s' is the same as restore directory '%s' ", authorizationsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath())); } restoreAuthorizationsFile = new File(restoreDirectory, authorizationsFile.getName()); try { FileUtils.syncWithRestore(authorizationsFile, restoreAuthorizationsFile, logger); } catch (final IOException | IllegalStateException ioe) { throw new AuthorizerCreationException(ioe); } } identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties)); groupMappings = Collections.unmodifiableList(IdentityMappingUtil.getGroupMappings(properties)); final PropertyValue initialAdminIdentityProp = configurationContext.getProperty(PROP_INITIAL_ADMIN_IDENTITY); initialAdminIdentity = initialAdminIdentityProp.isSet() ? IdentityMappingUtil.mapIdentity(initialAdminIdentityProp.getValue(), identityMappings) : null; NiFiUserUtils.setAdminIdentity(initialAdminIdentity); final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE); legacyAuthorizedUsersFile = legacyAuthorizedUsersProp.isSet() ? legacyAuthorizedUsersProp.getValue() : null; nodeIdentities = new HashSet<>(); for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) { Matcher matcher = NODE_IDENTITY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) { nodeIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings)); } } load(); if (restoreAuthorizationsFile != null) { FileUtils.copyFile(authorizationsFile, restoreAuthorizationsFile, false, false, logger); } logger.info(String.format("Authorizations file loaded at %s", new Date().toString())); } catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) { throw new AuthorizerCreationException(e); } }  }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { try { final PropertyValue userGroupProviderIdentifier = configurationContext.getProperty(PROP_USER_GROUP_PROVIDER); if (!userGroupProviderIdentifier.isSet()) { throw new AuthorizerCreationException("The user group provider must be specified."); } userGroupProvider = userGroupProviderLookup.getUserGroupProvider(userGroupProviderIdentifier.getValue()); if (userGroupProvider == null) { throw new AuthorizerCreationException("Unable to locate user group provider with identifier " + userGroupProviderIdentifier.getValue()); } final PropertyValue authorizationsPath = configurationContext.getProperty(PROP_AUTHORIZATIONS_FILE); if (StringUtils.isBlank(authorizationsPath.getValue())) { throw new AuthorizerCreationException("The authorizations file must be specified."); } authorizationsFile = new File(authorizationsPath.getValue()); if (!authorizationsFile.exists()) { logger.info("Creating new authorizations file at {}", new Object[] {authorizationsFile.getAbsolutePath()}); saveAuthorizations(new Authorizations()); } final File authorizationsFileDirectory = authorizationsFile.getAbsoluteFile().getParentFile(); final File restoreDirectory = properties.getRestoreDirectory(); if (restoreDirectory != null) { FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory); if (authorizationsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) { throw new AuthorizerCreationException(String.format("Authorizations file directory '%s' is the same as restore directory '%s' ", authorizationsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath())); } restoreAuthorizationsFile = new File(restoreDirectory, authorizationsFile.getName()); try { FileUtils.syncWithRestore(authorizationsFile, restoreAuthorizationsFile, logger); } catch (final IOException | IllegalStateException ioe) { throw new AuthorizerCreationException(ioe); } } identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties)); groupMappings = Collections.unmodifiableList(IdentityMappingUtil.getGroupMappings(properties)); final PropertyValue initialAdminIdentityProp = configurationContext.getProperty(PROP_INITIAL_ADMIN_IDENTITY); initialAdminIdentity = initialAdminIdentityProp.isSet() ? IdentityMappingUtil.mapIdentity(initialAdminIdentityProp.getValue(), identityMappings) : null; NiFiUserUtils.setAdminIdentity(initialAdminIdentity); final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE); legacyAuthorizedUsersFile = legacyAuthorizedUsersProp.isSet() ? legacyAuthorizedUsersProp.getValue() : null; nodeIdentities = new HashSet<>(); for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) { Matcher matcher = NODE_IDENTITY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) { nodeIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings)); } } load(); if (restoreAuthorizationsFile != null) { FileUtils.copyFile(authorizationsFile, restoreAuthorizationsFile, false, false, logger); } logger.info(String.format("Authorizations file loaded at %s", new Date().toString())); } catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) { throw new AuthorizerCreationException(e); } }  @Override void initialize(AccessPolicyProviderInitializationContext initializationContext); @Override void onConfigured(AuthorizerConfigurationContext configurationContext); @Override UserGroupProvider getUserGroupProvider(); @Override Set<AccessPolicy> getAccessPolicies(); @Override synchronized AccessPolicy addAccessPolicy(AccessPolicy accessPolicy); @Override AccessPolicy getAccessPolicy(String identifier); @Override AccessPolicy getAccessPolicy(String resourceIdentifier, RequestAction action); @Override synchronized AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy); @Override synchronized AccessPolicy deleteAccessPolicy(AccessPolicy accessPolicy); @AuthorizerContext void setNiFiProperties(NiFiProperties properties); @Override synchronized void inheritFingerprint(String fingerprint); @Override void checkInheritability(String proposedFingerprint); @Override String getFingerprint(); @Override void preDestruction(); @Override void setUserDefaultAccesPilicy(User user); }
FileAccessPolicyProvider implements ConfigurableAccessPolicyProvider { @Override public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException { try { final PropertyValue userGroupProviderIdentifier = configurationContext.getProperty(PROP_USER_GROUP_PROVIDER); if (!userGroupProviderIdentifier.isSet()) { throw new AuthorizerCreationException("The user group provider must be specified."); } userGroupProvider = userGroupProviderLookup.getUserGroupProvider(userGroupProviderIdentifier.getValue()); if (userGroupProvider == null) { throw new AuthorizerCreationException("Unable to locate user group provider with identifier " + userGroupProviderIdentifier.getValue()); } final PropertyValue authorizationsPath = configurationContext.getProperty(PROP_AUTHORIZATIONS_FILE); if (StringUtils.isBlank(authorizationsPath.getValue())) { throw new AuthorizerCreationException("The authorizations file must be specified."); } authorizationsFile = new File(authorizationsPath.getValue()); if (!authorizationsFile.exists()) { logger.info("Creating new authorizations file at {}", new Object[] {authorizationsFile.getAbsolutePath()}); saveAuthorizations(new Authorizations()); } final File authorizationsFileDirectory = authorizationsFile.getAbsoluteFile().getParentFile(); final File restoreDirectory = properties.getRestoreDirectory(); if (restoreDirectory != null) { FileUtils.ensureDirectoryExistAndCanAccess(restoreDirectory); if (authorizationsFileDirectory.getAbsolutePath().equals(restoreDirectory.getAbsolutePath())) { throw new AuthorizerCreationException(String.format("Authorizations file directory '%s' is the same as restore directory '%s' ", authorizationsFileDirectory.getAbsolutePath(), restoreDirectory.getAbsolutePath())); } restoreAuthorizationsFile = new File(restoreDirectory, authorizationsFile.getName()); try { FileUtils.syncWithRestore(authorizationsFile, restoreAuthorizationsFile, logger); } catch (final IOException | IllegalStateException ioe) { throw new AuthorizerCreationException(ioe); } } identityMappings = Collections.unmodifiableList(IdentityMappingUtil.getIdentityMappings(properties)); groupMappings = Collections.unmodifiableList(IdentityMappingUtil.getGroupMappings(properties)); final PropertyValue initialAdminIdentityProp = configurationContext.getProperty(PROP_INITIAL_ADMIN_IDENTITY); initialAdminIdentity = initialAdminIdentityProp.isSet() ? IdentityMappingUtil.mapIdentity(initialAdminIdentityProp.getValue(), identityMappings) : null; NiFiUserUtils.setAdminIdentity(initialAdminIdentity); final PropertyValue legacyAuthorizedUsersProp = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE); legacyAuthorizedUsersFile = legacyAuthorizedUsersProp.isSet() ? legacyAuthorizedUsersProp.getValue() : null; nodeIdentities = new HashSet<>(); for (Map.Entry<String,String> entry : configurationContext.getProperties().entrySet()) { Matcher matcher = NODE_IDENTITY_PATTERN.matcher(entry.getKey()); if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) { nodeIdentities.add(IdentityMappingUtil.mapIdentity(entry.getValue(), identityMappings)); } } load(); if (restoreAuthorizationsFile != null) { FileUtils.copyFile(authorizationsFile, restoreAuthorizationsFile, false, false, logger); } logger.info(String.format("Authorizations file loaded at %s", new Date().toString())); } catch (IOException | AuthorizerCreationException | JAXBException | IllegalStateException | SAXException e) { throw new AuthorizerCreationException(e); } }  @Override void initialize(AccessPolicyProviderInitializationContext initializationContext); @Override void onConfigured(AuthorizerConfigurationContext configurationContext); @Override UserGroupProvider getUserGroupProvider(); @Override Set<AccessPolicy> getAccessPolicies(); @Override synchronized AccessPolicy addAccessPolicy(AccessPolicy accessPolicy); @Override AccessPolicy getAccessPolicy(String identifier); @Override AccessPolicy getAccessPolicy(String resourceIdentifier, RequestAction action); @Override synchronized AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy); @Override synchronized AccessPolicy deleteAccessPolicy(AccessPolicy accessPolicy); @AuthorizerContext void setNiFiProperties(NiFiProperties properties); @Override synchronized void inheritFingerprint(String fingerprint); @Override void checkInheritability(String proposedFingerprint); @Override String getFingerprint(); @Override void preDestruction(); @Override void setUserDefaultAccesPilicy(User user);  }