Package org.apache.nifi.authorization
Class FileAccessPolicyProvider
java.lang.Object
org.apache.nifi.authorization.FileAccessPolicyProvider
- All Implemented Interfaces:
AccessPolicyProvider,ConfigurableAccessPolicyProvider
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate Fileprivate final AtomicReference<AuthorizationsHolder> private Schemaprivate static final Stringprivate Stringprivate static final jakarta.xml.bind.JAXBContextprivate static final Stringprivate static final org.slf4j.Logger(package private) static final Patternprivate Stringprivate static final Stringprivate static final Stringprivate static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final Stringprivate NiFiProperties(package private) static final Stringprivate static final Stringprivate Fileprivate Stringprivate UserGroupProviderprivate UserGroupProviderLookup(package private) static final Stringprivate static final XMLOutputFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddAccessPolicies(List<AccessPolicy> accessPolicies) addAccessPolicy(AccessPolicy accessPolicy) private voidaddGroupToAccessPolicy(Authorizations authorizations, String resource, String groupIdentifier, String action) Creates and adds an access policy for the given resource, group identity, and actions to the specified authorizations.private voidaddUserToAccessPolicy(Authorizations authorizations, String resource, String userIdentifier, String action) Creates and adds an access policy for the given resource, identity, and actions to the specified authorizations.voidvoidcheckInheritability(String proposedFingerprint) private PolicycreateJAXBPolicy(AccessPolicy accessPolicy) deleteAccessPolicy(AccessPolicy accessPolicy) voidforciblyInheritFingerprint(String fingerprint) getAccessPolicy(String identifier) getAccessPolicy(String resourceIdentifier, RequestAction action) (package private) AuthorizationsHolderprivate voidinheritAccessPolicies(List<AccessPolicy> accessPolicies) voidinheritFingerprint(String fingerprint) voidinitialize(AccessPolicyProviderInitializationContext initializationContext) private static jakarta.xml.bind.JAXBContextLoad the JAXBContext.private booleanprivate voidload()Loads the authorizations file and populates the AuthorizationsHolder, only called during start-up.voidonConfigured(AuthorizerConfigurationContext configurationContext) private voidTry to parse the flow configuration file to extract the root group id and port information.private List<AccessPolicy> parsePolicies(String fingerprint) private AccessPolicyparsePolicy(Element element) private voidpopulateInitialAdmin(Authorizations authorizations) Creates the initial admin user and policies for access the flow and managing users and policies.private voidpopulateNodes(Authorizations authorizations) Creates a user for each node and gives the nodes write permission to /proxy.voidvoidpurgePolicies(boolean save) private voidsaveAndRefreshHolder(Authorizations authorizations) Saves the Authorizations instance by marshalling to a file, then re-populates the in-memory data structures and sets the new holder.private voidsaveAuthorizations(Authorizations authorizations) private voidsaveAuthorizations(Authorizations authorizations, File destinationFile) voidsetNiFiProperties(NiFiProperties properties) private voidtransferUsersAndGroups(AccessPolicy accessPolicy, Policy policy) Sets the given Policy to the state of the provided AccessPolicy.private AuthorizationsupdateAccessPolicy(AccessPolicy accessPolicy) private voidwritePolicy(XMLStreamWriter writer, AccessPolicy policy) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.nifi.authorization.ConfigurableAccessPolicyProvider
isConfigurable
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
AUTHORIZATIONS_XSD
- See Also:
-
JAXB_AUTHORIZATIONS_PATH
- See Also:
-
JAXB_AUTHORIZATIONS_CONTEXT
private static final jakarta.xml.bind.JAXBContext JAXB_AUTHORIZATIONS_CONTEXT -
XML_OUTPUT_FACTORY
-
POLICY_ELEMENT
- See Also:
-
POLICY_USER_ELEMENT
- See Also:
-
POLICY_GROUP_ELEMENT
- See Also:
-
IDENTIFIER_ATTR
- See Also:
-
RESOURCE_ATTR
- See Also:
-
ACTIONS_ATTR
- See Also:
-
READ_CODE
- See Also:
-
WRITE_CODE
- See Also:
-
PROP_NODE_IDENTITY_PREFIX
- See Also:
-
PROP_NODE_GROUP_NAME
- See Also:
-
PROP_USER_GROUP_PROVIDER
- See Also:
-
PROP_AUTHORIZATIONS_FILE
- See Also:
-
PROP_INITIAL_ADMIN_IDENTITY
- See Also:
-
NODE_IDENTITY_PATTERN
-
authorizationsSchema
-
properties
-
authorizationsFile
-
restoreAuthorizationsFile
-
rootGroupId
-
initialAdminIdentity
-
nodeIdentities
-
nodeGroupIdentifier
-
userGroupProvider
-
userGroupProviderLookup
-
authorizationsHolder
-
-
Constructor Details
-
FileAccessPolicyProvider
public FileAccessPolicyProvider()
-
-
Method Details
-
initializeJaxbContext
private static jakarta.xml.bind.JAXBContext initializeJaxbContext()Load the JAXBContext. -
initialize
public void initialize(AccessPolicyProviderInitializationContext initializationContext) throws AuthorizerCreationException - Specified by:
initializein interfaceAccessPolicyProvider- Throws:
AuthorizerCreationException
-
onConfigured
public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException - Specified by:
onConfiguredin interfaceAccessPolicyProvider- Throws:
AuthorizerCreationException
-
getUserGroupProvider
- Specified by:
getUserGroupProviderin interfaceAccessPolicyProvider
-
getAccessPolicies
- Specified by:
getAccessPoliciesin interfaceAccessPolicyProvider- Throws:
AuthorizationAccessException
-
addAccessPolicy
- Specified by:
addAccessPolicyin interfaceConfigurableAccessPolicyProvider- Throws:
AuthorizationAccessException
-
addAccessPolicies
private void addAccessPolicies(List<AccessPolicy> accessPolicies) throws AuthorizationAccessException - Throws:
AuthorizationAccessException
-
purgePolicies
public void purgePolicies(boolean save) -
backupPolicies
public void backupPolicies() throws jakarta.xml.bind.JAXBException- Throws:
jakarta.xml.bind.JAXBException
-
getAccessPolicy
- Specified by:
getAccessPolicyin interfaceAccessPolicyProvider- Throws:
AuthorizationAccessException
-
getAccessPolicy
public AccessPolicy getAccessPolicy(String resourceIdentifier, RequestAction action) throws AuthorizationAccessException - Specified by:
getAccessPolicyin interfaceAccessPolicyProvider- Throws:
AuthorizationAccessException
-
updateAccessPolicy
public AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException - Specified by:
updateAccessPolicyin interfaceConfigurableAccessPolicyProvider- Throws:
AuthorizationAccessException
-
deleteAccessPolicy
public AccessPolicy deleteAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException - Specified by:
deleteAccessPolicyin interfaceConfigurableAccessPolicyProvider- Throws:
AuthorizationAccessException
-
getAuthorizationsHolder
AuthorizationsHolder getAuthorizationsHolder() -
setNiFiProperties
-
inheritFingerprint
- Specified by:
inheritFingerprintin interfaceConfigurableAccessPolicyProvider- Throws:
AuthorizationAccessException
-
inheritAccessPolicies
-
forciblyInheritFingerprint
- Specified by:
forciblyInheritFingerprintin interfaceConfigurableAccessPolicyProvider- Throws:
AuthorizationAccessException
-
checkInheritability
public void checkInheritability(String proposedFingerprint) throws AuthorizationAccessException, UninheritableAuthorizationsException - Specified by:
checkInheritabilityin interfaceConfigurableAccessPolicyProvider- Throws:
AuthorizationAccessExceptionUninheritableAuthorizationsException
-
isInheritable
private boolean isInheritable() -
getFingerprint
- Specified by:
getFingerprintin interfaceConfigurableAccessPolicyProvider- Throws:
AuthorizationAccessException
-
parsePolicies
-
parsePolicy
-
writePolicy
- Throws:
XMLStreamException
-
load
private void load() throws jakarta.xml.bind.JAXBException, IOException, IllegalStateException, SAXExceptionLoads the authorizations file and populates the AuthorizationsHolder, only called during start-up.- Throws:
jakarta.xml.bind.JAXBException- Unable to reload the authorized users fileIOException- Unable to sync file with restoreIllegalStateException- Unable to sync file with restoreSAXException
-
saveAuthorizations
private void saveAuthorizations(Authorizations authorizations) throws jakarta.xml.bind.JAXBException - Throws:
jakarta.xml.bind.JAXBException
-
saveAuthorizations
private void saveAuthorizations(Authorizations authorizations, File destinationFile) throws jakarta.xml.bind.JAXBException - Throws:
jakarta.xml.bind.JAXBException
-
unmarshallAuthorizations
- Throws:
jakarta.xml.bind.JAXBException
-
parseFlow
private void parseFlow()Try to parse the flow configuration file to extract the root group id and port information. -
populateInitialAdmin
Creates the initial admin user and policies for access the flow and managing users and policies. -
populateNodes
Creates a user for each node and gives the nodes write permission to /proxy.- Parameters:
authorizations- the overall authorizations
-
addUserToAccessPolicy
private void addUserToAccessPolicy(Authorizations authorizations, String resource, String userIdentifier, String action) Creates and adds an access policy for the given resource, identity, and actions to the specified authorizations.- Parameters:
authorizations- the Authorizations instance to add the policy toresource- the resource for the policyuserIdentifier- the identifier for the user to add to the policyaction- the action for the policy
-
addGroupToAccessPolicy
private void addGroupToAccessPolicy(Authorizations authorizations, String resource, String groupIdentifier, String action) Creates and adds an access policy for the given resource, group identity, and actions to the specified authorizations.- Parameters:
authorizations- the Authorizations instance to add the policy toresource- the resource for the policygroupIdentifier- the identifier for the group to add to the policyaction- the action for the policy
-
createJAXBPolicy
-
transferUsersAndGroups
Sets the given Policy to the state of the provided AccessPolicy. Users and Groups will be cleared and set to match the AccessPolicy, the resource and action will be set to match the AccessPolicy. Does not set the identifier.- Parameters:
accessPolicy- the AccessPolicy to transfer state frompolicy- the Policy to transfer state to
-
saveAndRefreshHolder
private void saveAndRefreshHolder(Authorizations authorizations) throws AuthorizationAccessException Saves the Authorizations instance by marshalling to a file, then re-populates the in-memory data structures and sets the new holder. Synchronized to ensure only one thread writes the file at a time.- Parameters:
authorizations- the authorizations to save and populate from- Throws:
AuthorizationAccessException- if an error occurs saving the authorizations
-
preDestruction
- Specified by:
preDestructionin interfaceAccessPolicyProvider- Throws:
AuthorizerDestructionException
-