Search in sources :

Example 6 with AuthorizerConfigurationContext

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

the class LdapUserGroupProviderTest method testSearchGroupsWithNoNameAndUserIdentityUidAttribute.

@Test
public void testSearchGroupsWithNoNameAndUserIdentityUidAttribute() throws Exception {
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration(null, GROUP_SEARCH_BASE);
    when(configurationContext.getProperty(PROP_GROUP_MEMBER_ATTRIBUTE)).thenReturn(new StandardPropertyValue("member", null));
    when(configurationContext.getProperty(PROP_USER_IDENTITY_ATTRIBUTE)).thenReturn(new StandardPropertyValue("uid", null));
    ldapUserGroupProvider.onConfigured(configurationContext);
    final Set<Group> groups = ldapUserGroupProvider.getGroups();
    assertEquals(4, groups.size());
    final Group admins = groups.stream().filter(group -> "cn=admins,ou=groups,o=nifi".equals(group.getName())).findFirst().orElse(null);
    assertNotNull(admins);
    assertFalse(admins.getUsers().isEmpty());
    assertEquals(1, admins.getUsers().stream().map(userIdentifier -> ldapUserGroupProvider.getUser(userIdentifier)).filter(user -> "user1".equals(user.getIdentity())).count());
}
Also used : CreateTransport(org.apache.directory.server.annotations.CreateTransport) PROP_GROUP_NAME_ATTRIBUTE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_NAME_ATTRIBUTE) PROP_SYNC_INTERVAL(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_SYNC_INTERVAL) PROP_USER_IDENTITY_ATTRIBUTE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_USER_IDENTITY_ATTRIBUTE) PROP_USER_SEARCH_FILTER(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_USER_SEARCH_FILTER) CreateLdapServer(org.apache.directory.server.annotations.CreateLdapServer) CreatePartition(org.apache.directory.server.core.annotations.CreatePartition) PROP_MANAGER_PASSWORD(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_MANAGER_PASSWORD) PROP_GROUP_SEARCH_BASE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_SEARCH_BASE) AuthorizerCreationException(org.apache.nifi.authorization.exception.AuthorizerCreationException) PROP_USER_GROUP_REFERENCED_GROUP_ATTRIBUTE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_USER_GROUP_REFERENCED_GROUP_ATTRIBUTE) PROP_AUTHENTICATION_STRATEGY(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_AUTHENTICATION_STRATEGY) Set(java.util.Set) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) PROP_GROUP_OBJECT_CLASS(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_OBJECT_CLASS) UserAndGroups(org.apache.nifi.authorization.UserAndGroups) PROP_GROUP_MEMBER_REFERENCED_USER_ATTRIBUTE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_MEMBER_REFERENCED_USER_ATTRIBUTE) Assert.assertFalse(org.junit.Assert.assertFalse) PROP_CONNECT_TIMEOUT(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_CONNECT_TIMEOUT) PROP_GROUP_SEARCH_SCOPE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_SEARCH_SCOPE) Mockito.mock(org.mockito.Mockito.mock) UserGroupProviderInitializationContext(org.apache.nifi.authorization.UserGroupProviderInitializationContext) PROP_USER_SEARCH_BASE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_USER_SEARCH_BASE) RunWith(org.junit.runner.RunWith) CreateDS(org.apache.directory.server.core.annotations.CreateDS) Group(org.apache.nifi.authorization.Group) PROP_PAGE_SIZE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_PAGE_SIZE) PROP_REFERRAL_STRATEGY(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_REFERRAL_STRATEGY) PROP_USER_OBJECT_CLASS(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_USER_OBJECT_CLASS) Matchers.anyString(org.mockito.Matchers.anyString) ApplyLdifFiles(org.apache.directory.server.core.annotations.ApplyLdifFiles) PROP_USER_GROUP_ATTRIBUTE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_USER_GROUP_ATTRIBUTE) FrameworkRunner(org.apache.directory.server.core.integ.FrameworkRunner) PROP_READ_TIMEOUT(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_READ_TIMEOUT) Before(org.junit.Before) PROP_USER_SEARCH_SCOPE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_USER_SEARCH_SCOPE) PROP_GROUP_MEMBER_ATTRIBUTE(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_MEMBER_ATTRIBUTE) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Properties(java.util.Properties) PROP_URL(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_URL) Assert.assertNotNull(org.junit.Assert.assertNotNull) PROP_MANAGER_DN(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_MANAGER_DN) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito(org.mockito.Mockito) ReferralStrategy(org.apache.nifi.ldap.ReferralStrategy) NiFiProperties(org.apache.nifi.util.NiFiProperties) AbstractLdapTestUnit(org.apache.directory.server.core.integ.AbstractLdapTestUnit) LdapAuthenticationStrategy(org.apache.nifi.ldap.LdapAuthenticationStrategy) PROP_GROUP_SEARCH_FILTER(org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_SEARCH_FILTER) Assert.assertEquals(org.junit.Assert.assertEquals) Group(org.apache.nifi.authorization.Group) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 7 with AuthorizerConfigurationContext

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

the class LdapUserGroupProviderTest method testSearchGroupsObjectSearchScope.

@Test
public void testSearchGroupsObjectSearchScope() throws Exception {
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration(null, GROUP_SEARCH_BASE);
    when(configurationContext.getProperty(PROP_GROUP_MEMBER_ATTRIBUTE)).thenReturn(new StandardPropertyValue("member", null));
    when(configurationContext.getProperty(PROP_GROUP_SEARCH_SCOPE)).thenReturn(new StandardPropertyValue(SearchScope.OBJECT.name(), null));
    ldapUserGroupProvider.onConfigured(configurationContext);
    assertTrue(ldapUserGroupProvider.getUsers().isEmpty());
    assertTrue(ldapUserGroupProvider.getGroups().isEmpty());
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 8 with AuthorizerConfigurationContext

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

the class LdapUserGroupProviderTest method testReferencedGroupAttributeWithoutGroupSearchBase.

@Test(expected = AuthorizerCreationException.class)
public void testReferencedGroupAttributeWithoutGroupSearchBase() throws Exception {
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration("ou=users-2,o=nifi", null);
    when(configurationContext.getProperty(PROP_USER_GROUP_REFERENCED_GROUP_ATTRIBUTE)).thenReturn(new StandardPropertyValue("cn", null));
    ldapUserGroupProvider.onConfigured(configurationContext);
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 9 with AuthorizerConfigurationContext

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

the class LdapUserGroupProviderTest method testSearchUsersWithNoIdentityAttribute.

@Test
public void testSearchUsersWithNoIdentityAttribute() throws Exception {
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration(USER_SEARCH_BASE, null);
    ldapUserGroupProvider.onConfigured(configurationContext);
    assertEquals(8, ldapUserGroupProvider.getUsers().size());
    assertNotNull(ldapUserGroupProvider.getUserByIdentity("cn=User 1,ou=users,o=nifi"));
    assertTrue(ldapUserGroupProvider.getGroups().isEmpty());
}
Also used : AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 10 with AuthorizerConfigurationContext

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

the class LdapUserGroupProviderTest method testSearchGroupsWithNoNameAttribute.

@Test
public void testSearchGroupsWithNoNameAttribute() throws Exception {
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration(null, GROUP_SEARCH_BASE);
    when(configurationContext.getProperty(PROP_GROUP_MEMBER_ATTRIBUTE)).thenReturn(new StandardPropertyValue("member", null));
    ldapUserGroupProvider.onConfigured(configurationContext);
    final Set<Group> groups = ldapUserGroupProvider.getGroups();
    assertEquals(4, groups.size());
    assertEquals(1, groups.stream().filter(group -> "cn=admins,ou=groups,o=nifi".equals(group.getName())).count());
}
Also used : Group(org.apache.nifi.authorization.Group) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Aggregations

AuthorizerConfigurationContext (org.apache.nifi.authorization.AuthorizerConfigurationContext)42 Test (org.junit.Test)38 StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)33 Group (org.apache.nifi.authorization.Group)14 UserAndGroups (org.apache.nifi.authorization.UserAndGroups)11 Properties (java.util.Properties)9 UserGroupProviderInitializationContext (org.apache.nifi.authorization.UserGroupProviderInitializationContext)9 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)9 Set (java.util.Set)8 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 LdapAuthenticationStrategy (org.apache.nifi.ldap.LdapAuthenticationStrategy)8 ReferralStrategy (org.apache.nifi.ldap.ReferralStrategy)8 PROP_AUTHENTICATION_STRATEGY (org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_AUTHENTICATION_STRATEGY)8 PROP_CONNECT_TIMEOUT (org.apache.nifi.ldap.tenants.LdapUserGroupProvider.PROP_CONNECT_TIMEOUT)8