Search in sources :

Example 6 with Authorizations

use of org.apache.nifi.registry.security.authorization.file.generated.Authorizations in project nifi-registry by apache.

the class FileAccessPolicyProvider method updateAccessPolicy.

@Override
public synchronized AccessPolicy updateAccessPolicy(AccessPolicy accessPolicy) throws AuthorizationAccessException {
    if (accessPolicy == null) {
        throw new IllegalArgumentException("AccessPolicy cannot be null");
    }
    final AuthorizationsHolder holder = this.authorizationsHolder.get();
    final Authorizations authorizations = holder.getAuthorizations();
    // try to find an existing Authorization that matches the policy id
    Policy updatePolicy = null;
    for (Policy policy : authorizations.getPolicies().getPolicy()) {
        if (policy.getIdentifier().equals(accessPolicy.getIdentifier())) {
            updatePolicy = policy;
            break;
        }
    }
    // no matching Policy so return null
    if (updatePolicy == null) {
        return null;
    }
    // update the Policy, save, reload, and return
    transferUsersAndGroups(accessPolicy, updatePolicy);
    saveAndRefreshHolder(authorizations);
    return this.authorizationsHolder.get().getPoliciesById().get(accessPolicy.getIdentifier());
}
Also used : AccessPolicy(org.apache.nifi.registry.security.authorization.AccessPolicy) Policy(org.apache.nifi.registry.security.authorization.file.generated.Policy) Authorizations(org.apache.nifi.registry.security.authorization.file.generated.Authorizations)

Aggregations

Authorizations (org.apache.nifi.registry.security.authorization.file.generated.Authorizations)6 AccessPolicy (org.apache.nifi.registry.security.authorization.AccessPolicy)3 Policy (org.apache.nifi.registry.security.authorization.file.generated.Policy)3 File (java.io.File)1 Date (java.util.Date)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Policies (org.apache.nifi.registry.security.authorization.file.generated.Policies)1 SecurityProviderCreationException (org.apache.nifi.registry.security.exception.SecurityProviderCreationException)1 PropertyValue (org.apache.nifi.registry.util.PropertyValue)1 SAXException (org.xml.sax.SAXException)1