Search in sources :

Example 11 with AuthorizationAccessException

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

the class FileAccessPolicyProvider method parsePolicies.

private List<AccessPolicy> parsePolicies(final String fingerprint) {
    final List<AccessPolicy> policies = new ArrayList<>();
    final byte[] fingerprintBytes = fingerprint.getBytes(StandardCharsets.UTF_8);
    try (final ByteArrayInputStream in = new ByteArrayInputStream(fingerprintBytes)) {
        final DocumentBuilder docBuilder = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
        final Document document = docBuilder.parse(in);
        final Element rootElement = document.getDocumentElement();
        // parse all the policies and add them to the current access policy provider
        NodeList policyNodes = rootElement.getElementsByTagName(POLICY_ELEMENT);
        for (int i = 0; i < policyNodes.getLength(); i++) {
            Node policyNode = policyNodes.item(i);
            policies.add(parsePolicy((Element) policyNode));
        }
    } catch (SAXException | ParserConfigurationException | IOException e) {
        throw new AuthorizationAccessException("Unable to parse fingerprint", e);
    }
    return policies;
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) AccessPolicy(org.apache.nifi.registry.security.authorization.AccessPolicy) SAXException(org.xml.sax.SAXException) AuthorizationAccessException(org.apache.nifi.registry.security.authorization.exception.AuthorizationAccessException) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 12 with AuthorizationAccessException

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

the class FileUserGroupProvider method parseUsersAndGroups.

private UsersAndGroups parseUsersAndGroups(final String fingerprint) {
    final List<User> users = new ArrayList<>();
    final List<Group> groups = new ArrayList<>();
    final byte[] fingerprintBytes = fingerprint.getBytes(StandardCharsets.UTF_8);
    try (final ByteArrayInputStream in = new ByteArrayInputStream(fingerprintBytes)) {
        final DocumentBuilder docBuilder = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
        final Document document = docBuilder.parse(in);
        final Element rootElement = document.getDocumentElement();
        // parse all the users and add them to the current user group provider
        NodeList userNodes = rootElement.getElementsByTagName(USER_ELEMENT);
        for (int i = 0; i < userNodes.getLength(); i++) {
            Node userNode = userNodes.item(i);
            users.add(parseUser((Element) userNode));
        }
        // parse all the groups and add them to the current user group provider
        NodeList groupNodes = rootElement.getElementsByTagName(GROUP_ELEMENT);
        for (int i = 0; i < groupNodes.getLength(); i++) {
            Node groupNode = groupNodes.item(i);
            groups.add(parseGroup((Element) groupNode));
        }
    } catch (SAXException | ParserConfigurationException | IOException e) {
        throw new AuthorizationAccessException("Unable to parse fingerprint", e);
    }
    return new UsersAndGroups(users, groups);
}
Also used : Group(org.apache.nifi.registry.security.authorization.Group) User(org.apache.nifi.registry.security.authorization.User) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) AuthorizationAccessException(org.apache.nifi.registry.security.authorization.exception.AuthorizationAccessException) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 13 with AuthorizationAccessException

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

the class FileUserGroupProvider method getFingerprint.

@Override
public String getFingerprint() throws AuthorizationAccessException {
    final UserGroupHolder usersAndGroups = userGroupHolder.get();
    final List<User> users = new ArrayList<>(usersAndGroups.getAllUsers());
    Collections.sort(users, Comparator.comparing(User::getIdentifier));
    final List<Group> groups = new ArrayList<>(usersAndGroups.getAllGroups());
    Collections.sort(groups, Comparator.comparing(Group::getIdentifier));
    XMLStreamWriter writer = null;
    final StringWriter out = new StringWriter();
    try {
        writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
        writer.writeStartDocument();
        writer.writeStartElement("tenants");
        for (User user : users) {
            writeUser(writer, user);
        }
        for (Group group : groups) {
            writeGroup(writer, group);
        }
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
    } catch (XMLStreamException e) {
        throw new AuthorizationAccessException("Unable to generate fingerprint", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (XMLStreamException e) {
            // nothing to do here
            }
        }
    }
    return out.toString();
}
Also used : Group(org.apache.nifi.registry.security.authorization.Group) AuthorizationAccessException(org.apache.nifi.registry.security.authorization.exception.AuthorizationAccessException) User(org.apache.nifi.registry.security.authorization.User) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ArrayList(java.util.ArrayList)

Aggregations

AuthorizationAccessException (org.apache.nifi.registry.security.authorization.exception.AuthorizationAccessException)13 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringWriter (java.io.StringWriter)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 Node (org.w3c.dom.Node)3 NodeList (org.w3c.dom.NodeList)3 SAXException (org.xml.sax.SAXException)3 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertificateException (java.security.cert.CertificateException)2 HashMap (java.util.HashMap)2