Search in sources :

Example 1 with ConfigurableUserGroupProvider

use of org.apache.nifi.authorization.ConfigurableUserGroupProvider in project nifi by apache.

the class ManagedRangerAuthorizer method getFingerprint.

@Override
public String getFingerprint() throws AuthorizationAccessException {
    final StringWriter out = new StringWriter();
    try {
        // create the document
        final DocumentBuilder documentBuilder = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
        final Document document = documentBuilder.newDocument();
        // create the root element
        final Element managedRangerAuthorizationsElement = document.createElement("managedRangerAuthorizations");
        document.appendChild(managedRangerAuthorizationsElement);
        // create the user group provider element
        final Element userGroupProviderElement = document.createElement(USER_GROUP_PROVIDER_ELEMENT);
        managedRangerAuthorizationsElement.appendChild(userGroupProviderElement);
        // append fingerprint if the provider is configurable
        if (userGroupProvider instanceof ConfigurableUserGroupProvider) {
            userGroupProviderElement.appendChild(document.createTextNode(((ConfigurableUserGroupProvider) userGroupProvider).getFingerprint()));
        }
        final Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.transform(new DOMSource(document), new StreamResult(out));
    } catch (ParserConfigurationException | TransformerException e) {
        throw new AuthorizationAccessException("Unable to generate fingerprint", e);
    }
    return out.toString();
}
Also used : AuthorizationAccessException(org.apache.nifi.authorization.exception.AuthorizationAccessException) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) ConfigurableUserGroupProvider(org.apache.nifi.authorization.ConfigurableUserGroupProvider) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException)

Example 2 with ConfigurableUserGroupProvider

use of org.apache.nifi.authorization.ConfigurableUserGroupProvider in project nifi by apache.

the class ManagedRangerAuthorizerTest method testCheckInheritEmptyFingerprint.

@Test
public void testCheckInheritEmptyFingerprint() throws Exception {
    final ConfigurableUserGroupProvider userGroupProvider = mock(ConfigurableUserGroupProvider.class);
    final ManagedRangerAuthorizer managedRangerAuthorizer = getStandardManagedAuthorizer(userGroupProvider);
    managedRangerAuthorizer.checkInheritability(EMPTY_FINGERPRINT);
    verify(userGroupProvider, times(0)).inheritFingerprint(anyString());
}
Also used : ConfigurableUserGroupProvider(org.apache.nifi.authorization.ConfigurableUserGroupProvider) Test(org.junit.Test)

Example 3 with ConfigurableUserGroupProvider

use of org.apache.nifi.authorization.ConfigurableUserGroupProvider in project nifi by apache.

the class ManagedRangerAuthorizerTest method testCheckInheritNonEmptyFingerprint.

@Test
public void testCheckInheritNonEmptyFingerprint() throws Exception {
    final ConfigurableUserGroupProvider userGroupProvider = mock(ConfigurableUserGroupProvider.class);
    final ManagedRangerAuthorizer managedRangerAuthorizer = getStandardManagedAuthorizer(userGroupProvider);
    managedRangerAuthorizer.checkInheritability(NON_EMPTY_FINGERPRINT);
    verify(userGroupProvider, times(1)).checkInheritability(TENANT_FINGERPRINT);
}
Also used : ConfigurableUserGroupProvider(org.apache.nifi.authorization.ConfigurableUserGroupProvider) Test(org.junit.Test)

Example 4 with ConfigurableUserGroupProvider

use of org.apache.nifi.authorization.ConfigurableUserGroupProvider in project nifi by apache.

the class ManagedRangerAuthorizerTest method testInheritNonEmptyFingerprint.

@Test
public void testInheritNonEmptyFingerprint() throws Exception {
    final ConfigurableUserGroupProvider userGroupProvider = mock(ConfigurableUserGroupProvider.class);
    final ManagedRangerAuthorizer managedRangerAuthorizer = getStandardManagedAuthorizer(userGroupProvider);
    managedRangerAuthorizer.inheritFingerprint(NON_EMPTY_FINGERPRINT);
    verify(userGroupProvider, times(1)).inheritFingerprint(TENANT_FINGERPRINT);
}
Also used : ConfigurableUserGroupProvider(org.apache.nifi.authorization.ConfigurableUserGroupProvider) Test(org.junit.Test)

Example 5 with ConfigurableUserGroupProvider

use of org.apache.nifi.authorization.ConfigurableUserGroupProvider in project nifi by apache.

the class ManagedRangerAuthorizerTest method testConfigurableEmptyFingerPrint.

@Test
public void testConfigurableEmptyFingerPrint() throws Exception {
    final ConfigurableUserGroupProvider userGroupProvider = mock(ConfigurableUserGroupProvider.class);
    when(userGroupProvider.getFingerprint()).thenReturn("");
    final ManagedRangerAuthorizer managedRangerAuthorizer = getStandardManagedAuthorizer(userGroupProvider);
    Assert.assertEquals(EMPTY_FINGERPRINT, managedRangerAuthorizer.getFingerprint());
}
Also used : ConfigurableUserGroupProvider(org.apache.nifi.authorization.ConfigurableUserGroupProvider) Test(org.junit.Test)

Aggregations

ConfigurableUserGroupProvider (org.apache.nifi.authorization.ConfigurableUserGroupProvider)11 Test (org.junit.Test)8 AccessPolicy (org.apache.nifi.authorization.AccessPolicy)2 ConfigurableAccessPolicyProvider (org.apache.nifi.authorization.ConfigurableAccessPolicyProvider)2 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)2 StringWriter (java.io.StringWriter)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Group (org.apache.nifi.authorization.Group)1 User (org.apache.nifi.authorization.User)1 AuthorizationAccessException (org.apache.nifi.authorization.exception.AuthorizationAccessException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1