Search in sources :

Example 36 with StandardPropertyValue

use of org.apache.nifi.attribute.expression.language.StandardPropertyValue in project nifi by apache.

the class FileAccessPolicyProviderTest method testOnConfiguredWhenInitialAdminProvided.

@Test
public void testOnConfiguredWhenInitialAdminProvided() throws Exception {
    final String adminIdentity = "admin-user";
    when(configurationContext.getProperty(eq(FileAccessPolicyProvider.PROP_INITIAL_ADMIN_IDENTITY))).thenReturn(new StandardPropertyValue(adminIdentity, null));
    writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE);
    writeFile(primaryTenants, EMPTY_TENANTS_CONCISE);
    userGroupProvider.onConfigured(configurationContext);
    accessPolicyProvider.onConfigured(configurationContext);
    final Set<User> users = userGroupProvider.getUsers();
    final User adminUser = users.iterator().next();
    assertEquals(adminIdentity, adminUser.getIdentity());
    final Set<AccessPolicy> policies = accessPolicyProvider.getAccessPolicies();
    assertEquals(12, policies.size());
    final String rootGroupResource = ResourceType.ProcessGroup.getValue() + "/" + ROOT_GROUP_ID;
    boolean foundRootGroupPolicy = false;
    for (AccessPolicy policy : policies) {
        if (policy.getResource().equals(rootGroupResource)) {
            foundRootGroupPolicy = true;
            break;
        }
    }
    assertTrue(foundRootGroupPolicy);
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 37 with StandardPropertyValue

use of org.apache.nifi.attribute.expression.language.StandardPropertyValue in project nifi by apache.

the class FileAccessPolicyProviderTest method testOnConfiguredWhenNodeIdentitiesProvided.

@Test
public void testOnConfiguredWhenNodeIdentitiesProvided() throws Exception {
    final String adminIdentity = "admin-user";
    final String nodeIdentity1 = "node1";
    final String nodeIdentity2 = "node2";
    when(configurationContext.getProperty(eq(FileAccessPolicyProvider.PROP_INITIAL_ADMIN_IDENTITY))).thenReturn(new StandardPropertyValue(adminIdentity, null));
    when(configurationContext.getProperty(eq(FileAccessPolicyProvider.PROP_NODE_IDENTITY_PREFIX + "1"))).thenReturn(new StandardPropertyValue(nodeIdentity1, null));
    when(configurationContext.getProperty(eq(FileAccessPolicyProvider.PROP_NODE_IDENTITY_PREFIX + "2"))).thenReturn(new StandardPropertyValue(nodeIdentity2, null));
    when(configurationContext.getProperty(eq(FileUserGroupProvider.PROP_INITIAL_USER_IDENTITY_PREFIX + "1"))).thenReturn(new StandardPropertyValue(adminIdentity, null));
    when(configurationContext.getProperty(eq(FileUserGroupProvider.PROP_INITIAL_USER_IDENTITY_PREFIX + "2"))).thenReturn(new StandardPropertyValue(nodeIdentity1, null));
    when(configurationContext.getProperty(eq(FileUserGroupProvider.PROP_INITIAL_USER_IDENTITY_PREFIX + "3"))).thenReturn(new StandardPropertyValue(nodeIdentity2, null));
    writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE);
    writeFile(primaryTenants, EMPTY_TENANTS_CONCISE);
    userGroupProvider.onConfigured(configurationContext);
    accessPolicyProvider.onConfigured(configurationContext);
    User nodeUser1 = userGroupProvider.getUserByIdentity(nodeIdentity1);
    User nodeUser2 = userGroupProvider.getUserByIdentity(nodeIdentity2);
    AccessPolicy proxyWritePolicy = accessPolicyProvider.getAccessPolicy(ResourceType.Proxy.getValue(), RequestAction.WRITE);
    assertNotNull(proxyWritePolicy);
    assertTrue(proxyWritePolicy.getUsers().contains(nodeUser1.getIdentifier()));
    assertTrue(proxyWritePolicy.getUsers().contains(nodeUser2.getIdentifier()));
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 38 with StandardPropertyValue

use of org.apache.nifi.attribute.expression.language.StandardPropertyValue in project nifi by apache.

the class FileAuthorizerTest method testOnConfiguredWhenLegacyUsersFileProvidedWithOverlappingRoles.

@Test
public void testOnConfiguredWhenLegacyUsersFileProvidedWithOverlappingRoles() throws Exception {
    when(configurationContext.getProperty(Mockito.eq(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE))).thenReturn(new StandardPropertyValue("src/test/resources/authorized-users-multirole.xml", null));
    writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE);
    writeFile(primaryTenants, EMPTY_TENANTS_CONCISE);
    authorizer.onConfigured(configurationContext);
    final Set<User> users = authorizer.getUsers();
    assertEquals(1, users.size());
    UsersAndAccessPolicies usersAndAccessPolicies = authorizer.getUsersAndAccessPolicies();
    assertNotNull(usersAndAccessPolicies.getAccessPolicy(ResourceType.Flow.getValue(), RequestAction.READ));
    assertNotNull(usersAndAccessPolicies.getAccessPolicy(ResourceType.Controller.getValue(), RequestAction.READ));
    assertNotNull(usersAndAccessPolicies.getAccessPolicy(ResourceType.Controller.getValue(), RequestAction.WRITE));
    assertNotNull(usersAndAccessPolicies.getAccessPolicy(ResourceType.System.getValue(), RequestAction.READ));
    assertNotNull(usersAndAccessPolicies.getAccessPolicy(ResourceType.ProcessGroup.getValue() + "/" + ROOT_GROUP_ID, RequestAction.READ));
    assertNotNull(usersAndAccessPolicies.getAccessPolicy(ResourceType.ProcessGroup.getValue() + "/" + ROOT_GROUP_ID, RequestAction.WRITE));
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Test(org.junit.Test)

Example 39 with StandardPropertyValue

use of org.apache.nifi.attribute.expression.language.StandardPropertyValue in project nifi by apache.

the class FileAuthorizerTest method testOnConfiguredWhenNodeIdentitiesProvidedWithIdentityMappings.

@Test
public void testOnConfiguredWhenNodeIdentitiesProvidedWithIdentityMappings() throws Exception {
    final Properties props = new Properties();
    props.setProperty("nifi.security.identity.mapping.pattern.dn1", "^CN=(.*?), OU=(.*?), O=(.*?), L=(.*?), ST=(.*?), C=(.*?)$");
    props.setProperty("nifi.security.identity.mapping.value.dn1", "$1");
    properties = getNiFiProperties(props);
    when(properties.getRestoreDirectory()).thenReturn(restoreAuthorizations.getParentFile());
    when(properties.getFlowConfigurationFile()).thenReturn(flow);
    authorizer.setNiFiProperties(properties);
    final String adminIdentity = "CN=user1, OU=Apache NiFi, O=Apache, L=Santa Monica, ST=CA, C=US";
    final String nodeIdentity1 = "CN=node1, OU=Apache NiFi, O=Apache, L=Santa Monica, ST=CA, C=US";
    final String nodeIdentity2 = "CN=node2, OU=Apache NiFi, O=Apache, L=Santa Monica, ST=CA, C=US";
    when(configurationContext.getProperty(Mockito.eq(FileAccessPolicyProvider.PROP_INITIAL_ADMIN_IDENTITY))).thenReturn(new StandardPropertyValue(adminIdentity, null));
    when(configurationContext.getProperty(Mockito.eq(FileAccessPolicyProvider.PROP_NODE_IDENTITY_PREFIX + "1"))).thenReturn(new StandardPropertyValue(nodeIdentity1, null));
    when(configurationContext.getProperty(Mockito.eq(FileAccessPolicyProvider.PROP_NODE_IDENTITY_PREFIX + "2"))).thenReturn(new StandardPropertyValue(nodeIdentity2, null));
    writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE);
    writeFile(primaryTenants, EMPTY_TENANTS_CONCISE);
    authorizer.onConfigured(configurationContext);
    User adminUser = authorizer.getUserByIdentity("user1");
    assertNotNull(adminUser);
    User nodeUser1 = authorizer.getUserByIdentity("node1");
    assertNotNull(nodeUser1);
    User nodeUser2 = authorizer.getUserByIdentity("node2");
    assertNotNull(nodeUser2);
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) Test(org.junit.Test)

Example 40 with StandardPropertyValue

use of org.apache.nifi.attribute.expression.language.StandardPropertyValue in project nifi by apache.

the class FileAuthorizerTest method testOnConfiguredWhenBadLegacyUsersFileProvided.

@Test(expected = AuthorizerCreationException.class)
public void testOnConfiguredWhenBadLegacyUsersFileProvided() throws Exception {
    when(configurationContext.getProperty(Mockito.eq(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE))).thenReturn(new StandardPropertyValue("src/test/resources/does-not-exist.xml", null));
    writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE);
    writeFile(primaryTenants, EMPTY_TENANTS_CONCISE);
    authorizer.onConfigured(configurationContext);
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Test(org.junit.Test)

Aggregations

StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)91 Test (org.junit.Test)78 AuthorizerConfigurationContext (org.apache.nifi.authorization.AuthorizerConfigurationContext)33 Matchers.anyString (org.mockito.Matchers.anyString)30 NiFiProperties (org.apache.nifi.util.NiFiProperties)24 PropertyValue (org.apache.nifi.components.PropertyValue)17 HashMap (java.util.HashMap)16 Properties (java.util.Properties)15 Group (org.apache.nifi.authorization.Group)12 Before (org.junit.Before)12 Set (java.util.Set)10 UserAndGroups (org.apache.nifi.authorization.UserAndGroups)10 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)9 CreateLdapServer (org.apache.directory.server.annotations.CreateLdapServer)8 CreateTransport (org.apache.directory.server.annotations.CreateTransport)8 ApplyLdifFiles (org.apache.directory.server.core.annotations.ApplyLdifFiles)8 CreateDS (org.apache.directory.server.core.annotations.CreateDS)8 CreatePartition (org.apache.directory.server.core.annotations.CreatePartition)8 AbstractLdapTestUnit (org.apache.directory.server.core.integ.AbstractLdapTestUnit)8 FrameworkRunner (org.apache.directory.server.core.integ.FrameworkRunner)8