Search in sources :

Example 6 with AccessPolicy

use of org.apache.nifi.registry.security.authorization.AccessPolicy in project nifi-registry by apache.

the class FileAccessPolicyProvider method createJAXBPolicy.

private Policy createJAXBPolicy(final AccessPolicy accessPolicy) {
    final Policy policy = new Policy();
    policy.setIdentifier(accessPolicy.getIdentifier());
    policy.setResource(accessPolicy.getResource());
    switch(accessPolicy.getAction()) {
        case READ:
            policy.setAction(READ_CODE);
            break;
        case WRITE:
            policy.setAction(WRITE_CODE);
            break;
        case DELETE:
            policy.setAction(DELETE_CODE);
            break;
        default:
            break;
    }
    transferUsersAndGroups(accessPolicy, policy);
    return policy;
}
Also used : AccessPolicy(org.apache.nifi.registry.security.authorization.AccessPolicy) Policy(org.apache.nifi.registry.security.authorization.file.generated.Policy)

Example 7 with AccessPolicy

use of org.apache.nifi.registry.security.authorization.AccessPolicy in project nifi-registry by apache.

the class FileAccessPolicyProvider method deleteAccessPolicy.

@Override
public synchronized AccessPolicy deleteAccessPolicy(String accessPolicyIdentifer) throws AuthorizationAccessException {
    if (accessPolicyIdentifer == null) {
        throw new IllegalArgumentException("Access policy identifier cannot be null");
    }
    final AuthorizationsHolder holder = this.authorizationsHolder.get();
    AccessPolicy deletedPolicy = holder.getPoliciesById().get(accessPolicyIdentifer);
    if (deletedPolicy == null) {
        return null;
    }
    // find the matching Policy and remove it
    final Authorizations authorizations = holder.getAuthorizations();
    Iterator<Policy> policyIter = authorizations.getPolicies().getPolicy().iterator();
    while (policyIter.hasNext()) {
        final Policy policy = policyIter.next();
        if (policy.getIdentifier().equals(accessPolicyIdentifer)) {
            policyIter.remove();
            break;
        }
    }
    saveAndRefreshHolder(authorizations);
    return deletedPolicy;
}
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) AccessPolicy(org.apache.nifi.registry.security.authorization.AccessPolicy)

Example 8 with AccessPolicy

use of org.apache.nifi.registry.security.authorization.AccessPolicy in project nifi-registry by apache.

the class FileAccessPolicyProvider method parsePolicy.

private AccessPolicy parsePolicy(final Element element) {
    final AccessPolicy.Builder builder = new AccessPolicy.Builder().identifier(element.getAttribute(IDENTIFIER_ATTR)).resource(element.getAttribute(RESOURCE_ATTR));
    final String actions = element.getAttribute(ACTIONS_ATTR);
    if (actions.equals(RequestAction.READ.name())) {
        builder.action(RequestAction.READ);
    } else if (actions.equals(RequestAction.WRITE.name())) {
        builder.action(RequestAction.WRITE);
    } else if (actions.equals(RequestAction.DELETE.name())) {
        builder.action(RequestAction.DELETE);
    } else {
        throw new IllegalStateException("Unknown Policy Action: " + actions);
    }
    NodeList policyUsers = element.getElementsByTagName(POLICY_USER_ELEMENT);
    for (int i = 0; i < policyUsers.getLength(); i++) {
        Element policyUserNode = (Element) policyUsers.item(i);
        builder.addUser(policyUserNode.getAttribute(IDENTIFIER_ATTR));
    }
    NodeList policyGroups = element.getElementsByTagName(POLICY_GROUP_ELEMENT);
    for (int i = 0; i < policyGroups.getLength(); i++) {
        Element policyGroupNode = (Element) policyGroups.item(i);
        builder.addGroup(policyGroupNode.getAttribute(IDENTIFIER_ATTR));
    }
    return builder.build();
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) AccessPolicy(org.apache.nifi.registry.security.authorization.AccessPolicy)

Example 9 with AccessPolicy

use of org.apache.nifi.registry.security.authorization.AccessPolicy 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

AccessPolicy (org.apache.nifi.registry.security.authorization.AccessPolicy)9 Policy (org.apache.nifi.registry.security.authorization.file.generated.Policy)5 Authorizations (org.apache.nifi.registry.security.authorization.file.generated.Authorizations)3 ArrayList (java.util.ArrayList)2 JAXBElement (javax.xml.bind.JAXBElement)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 AuthorizationAccessException (org.apache.nifi.registry.security.authorization.exception.AuthorizationAccessException)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 User (org.apache.nifi.registry.security.authorization.User)1 Document (org.w3c.dom.Document)1