Search in sources :

Example 66 with StandardPropertyValue

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

the class FileUserGroupProviderTest method testOnConfiguredWhenInitialUsersProvided.

@Test
public void testOnConfiguredWhenInitialUsersProvided() throws Exception {
    final String adminIdentity = "admin-user";
    final String nodeIdentity1 = "node-identity-1";
    final String nodeIdentity2 = "node-identity-2";
    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(primaryTenants, EMPTY_TENANTS_CONCISE);
    userGroupProvider.onConfigured(configurationContext);
    final Set<User> users = userGroupProvider.getUsers();
    assertEquals(3, users.size());
    assertTrue(users.contains(new User.Builder().identifierGenerateFromSeed(adminIdentity).identity(adminIdentity).build()));
    assertTrue(users.contains(new User.Builder().identifierGenerateFromSeed(nodeIdentity1).identity(nodeIdentity1).build()));
    assertTrue(users.contains(new User.Builder().identifierGenerateFromSeed(nodeIdentity2).identity(nodeIdentity2).build()));
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 67 with StandardPropertyValue

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

the class FileUserGroupProviderTest method testOnConfiguredWhenBadLegacyUsersFileProvided.

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

Example 68 with StandardPropertyValue

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

the class CompositeConfigurableUserGroupProviderTest method testDuplicateProviders.

@Test(expected = AuthorizerCreationException.class)
public void testDuplicateProviders() throws Exception {
    // Mock UserGroupProviderLookup
    UserGroupProvider configurableUserGroupProvider = getConfigurableUserGroupProvider();
    final UserGroupProviderLookup ugpLookup = mock(UserGroupProviderLookup.class);
    when(ugpLookup.getUserGroupProvider(eq(CONFIGURABLE_USER_GROUP_PROVIDER))).thenReturn(configurableUserGroupProvider);
    // Mock AuthorizerInitializationContext
    final AuthorizerInitializationContext initializationContext = mock(AuthorizerInitializationContext.class);
    when(initializationContext.getUserGroupProviderLookup()).thenReturn(ugpLookup);
    // Mock AuthorizerConfigurationContext to introduce the duplicate provider ids
    final AuthorizerConfigurationContext configurationContext = mock(AuthorizerConfigurationContext.class);
    when(configurationContext.getProperty(PROP_CONFIGURABLE_USER_GROUP_PROVIDER)).thenReturn(new StandardPropertyValue(CONFIGURABLE_USER_GROUP_PROVIDER, null));
    Map<String, String> configurationContextProperties = new HashMap<>();
    configurationContextProperties.put(PROP_USER_GROUP_PROVIDER_PREFIX + "1", CONFIGURABLE_USER_GROUP_PROVIDER);
    configurationContextProperties.put(PROP_USER_GROUP_PROVIDER_PREFIX + "2", NOT_CONFIGURABLE_USER_GROUP_PROVIDER);
    when(configurationContext.getProperties()).thenReturn(configurationContextProperties);
    // configure (should throw exception)
    CompositeConfigurableUserGroupProvider provider = new CompositeConfigurableUserGroupProvider();
    provider.initialize(initializationContext);
    provider.onConfigured(configurationContext);
}
Also used : HashMap(java.util.HashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Test(org.junit.Test)

Example 69 with StandardPropertyValue

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

the class CompositeConfigurableUserGroupProviderTest method testConfigurableUserGroupProviderOnly.

@Test
public void testConfigurableUserGroupProviderOnly() throws Exception {
    final UserGroupProvider userGroupProvider = initCompositeUserGroupProvider(new CompositeConfigurableUserGroupProvider(), lookup -> {
        when(lookup.getUserGroupProvider(eq(CONFIGURABLE_USER_GROUP_PROVIDER))).thenReturn(getConfigurableUserGroupProvider());
    }, configurationContext -> {
        when(configurationContext.getProperty(PROP_CONFIGURABLE_USER_GROUP_PROVIDER)).thenReturn(new StandardPropertyValue(CONFIGURABLE_USER_GROUP_PROVIDER, null));
    });
    // users and groups
    assertEquals(2, userGroupProvider.getUsers().size());
    assertEquals(1, userGroupProvider.getGroups().size());
    // unknown
    assertNull(userGroupProvider.getUser(NOT_A_REAL_USER_IDENTIFIER));
    assertNull(userGroupProvider.getUserByIdentity(NOT_A_REAL_USER_IDENTITY));
    final UserAndGroups unknownUserAndGroups = userGroupProvider.getUserAndGroups(NOT_A_REAL_USER_IDENTITY);
    assertNotNull(unknownUserAndGroups);
    assertNull(unknownUserAndGroups.getUser());
    assertNull(unknownUserAndGroups.getGroups());
    // providers
    testConfigurableUserGroupProvider(userGroupProvider);
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Test(org.junit.Test)

Example 70 with StandardPropertyValue

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

the class CompositeConfigurableUserGroupProviderTest method testConfigurableUserGroupProviderWithCollaboratingUserGroupProvider.

@Test
public void testConfigurableUserGroupProviderWithCollaboratingUserGroupProvider() throws Exception {
    final UserGroupProvider userGroupProvider = initCompositeUserGroupProvider(new CompositeConfigurableUserGroupProvider(), lookup -> {
        when(lookup.getUserGroupProvider(eq(CONFIGURABLE_USER_GROUP_PROVIDER))).thenReturn(getConfigurableUserGroupProvider());
    }, configurationContext -> {
        when(configurationContext.getProperty(PROP_CONFIGURABLE_USER_GROUP_PROVIDER)).thenReturn(new StandardPropertyValue(CONFIGURABLE_USER_GROUP_PROVIDER, null));
    }, getCollaboratingUserGroupProvider());
    // users and groups
    assertEquals(3, userGroupProvider.getUsers().size());
    assertEquals(2, userGroupProvider.getGroups().size());
    // unknown
    assertNull(userGroupProvider.getUser(NOT_A_REAL_USER_IDENTIFIER));
    assertNull(userGroupProvider.getUserByIdentity(NOT_A_REAL_USER_IDENTITY));
    final UserAndGroups unknownUserAndGroups = userGroupProvider.getUserAndGroups(NOT_A_REAL_USER_IDENTITY);
    assertNotNull(unknownUserAndGroups);
    assertNull(unknownUserAndGroups.getUser());
    assertNull(unknownUserAndGroups.getGroups());
    // providers
    final UserAndGroups user1AndGroups = userGroupProvider.getUserAndGroups(USER_1_IDENTITY);
    assertNotNull(user1AndGroups);
    assertNotNull(user1AndGroups.getUser());
    // from CollaboratingUGP
    assertEquals(2, user1AndGroups.getGroups().size());
}
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