Search in sources :

Example 16 with AuthorizerConfigurationContext

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

the class LdapUserGroupProviderTest method getBaseConfiguration.

private AuthorizerConfigurationContext getBaseConfiguration(final String userSearchBase, final String groupSearchBase) {
    final AuthorizerConfigurationContext configurationContext = mock(AuthorizerConfigurationContext.class);
    when(configurationContext.getProperty(PROP_URL)).thenReturn(new StandardPropertyValue("ldap://127.0.0.1:" + getLdapServer().getPort()));
    when(configurationContext.getProperty(PROP_CONNECT_TIMEOUT)).thenReturn(new StandardPropertyValue("30 secs"));
    when(configurationContext.getProperty(PROP_READ_TIMEOUT)).thenReturn(new StandardPropertyValue("30 secs"));
    when(configurationContext.getProperty(PROP_REFERRAL_STRATEGY)).thenReturn(new StandardPropertyValue(ReferralStrategy.FOLLOW.name()));
    when(configurationContext.getProperty(PROP_PAGE_SIZE)).thenReturn(new StandardPropertyValue(null));
    when(configurationContext.getProperty(PROP_SYNC_INTERVAL)).thenReturn(new StandardPropertyValue("30 mins"));
    when(configurationContext.getProperty(PROP_AUTHENTICATION_STRATEGY)).thenReturn(new StandardPropertyValue(LdapAuthenticationStrategy.SIMPLE.name()));
    when(configurationContext.getProperty(PROP_MANAGER_DN)).thenReturn(new StandardPropertyValue("uid=admin,ou=system"));
    when(configurationContext.getProperty(PROP_MANAGER_PASSWORD)).thenReturn(new StandardPropertyValue("secret"));
    when(configurationContext.getProperty(PROP_USER_SEARCH_BASE)).thenReturn(new StandardPropertyValue(userSearchBase));
    when(configurationContext.getProperty(PROP_USER_OBJECT_CLASS)).thenReturn(new StandardPropertyValue("person"));
    when(configurationContext.getProperty(PROP_USER_SEARCH_SCOPE)).thenReturn(new StandardPropertyValue(SearchScope.ONE_LEVEL.name()));
    when(configurationContext.getProperty(PROP_USER_SEARCH_FILTER)).thenReturn(new StandardPropertyValue(null));
    when(configurationContext.getProperty(PROP_USER_IDENTITY_ATTRIBUTE)).thenReturn(new StandardPropertyValue(null));
    when(configurationContext.getProperty(PROP_USER_GROUP_ATTRIBUTE)).thenReturn(new StandardPropertyValue(null));
    when(configurationContext.getProperty(PROP_USER_GROUP_REFERENCED_GROUP_ATTRIBUTE)).thenReturn(new StandardPropertyValue(null));
    when(configurationContext.getProperty(PROP_GROUP_SEARCH_BASE)).thenReturn(new StandardPropertyValue(groupSearchBase));
    when(configurationContext.getProperty(PROP_GROUP_OBJECT_CLASS)).thenReturn(new StandardPropertyValue("groupOfNames"));
    when(configurationContext.getProperty(PROP_GROUP_SEARCH_SCOPE)).thenReturn(new StandardPropertyValue(SearchScope.ONE_LEVEL.name()));
    when(configurationContext.getProperty(PROP_GROUP_SEARCH_FILTER)).thenReturn(new StandardPropertyValue(null));
    when(configurationContext.getProperty(PROP_GROUP_NAME_ATTRIBUTE)).thenReturn(new StandardPropertyValue(null));
    when(configurationContext.getProperty(PROP_GROUP_MEMBER_ATTRIBUTE)).thenReturn(new StandardPropertyValue(null));
    when(configurationContext.getProperty(PROP_GROUP_MEMBER_REFERENCED_USER_ATTRIBUTE)).thenReturn(new StandardPropertyValue(null));
    return configurationContext;
}
Also used : StandardPropertyValue(org.apache.nifi.registry.util.StandardPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext)

Example 17 with AuthorizerConfigurationContext

use of org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext in project nifi-registry 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"));
    when(configurationContext.getProperty(PROP_GROUP_SEARCH_SCOPE)).thenReturn(new StandardPropertyValue(SearchScope.OBJECT.name()));
    ldapUserGroupProvider.onConfigured(configurationContext);
    assertTrue(ldapUserGroupProvider.getUsers().isEmpty());
    assertTrue(ldapUserGroupProvider.getGroups().isEmpty());
}
Also used : StandardPropertyValue(org.apache.nifi.registry.util.StandardPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 18 with AuthorizerConfigurationContext

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

the class LdapUserGroupProviderTest method testSearchGroupsWithoutMemberAttribute.

@Test(expected = SecurityProviderCreationException.class)
public void testSearchGroupsWithoutMemberAttribute() throws Exception {
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration(null, GROUP_SEARCH_BASE);
    ldapUserGroupProvider.onConfigured(configurationContext);
}
Also used : AuthorizerConfigurationContext(org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 19 with AuthorizerConfigurationContext

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

the class LdapUserGroupProviderTest method testReferencedGroupUsingReferencedAttribute.

@Test
public void testReferencedGroupUsingReferencedAttribute() throws Exception {
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration("ou=users-2,o=nifi", "ou=groups-2,o=nifi");
    when(configurationContext.getProperty(PROP_USER_IDENTITY_ATTRIBUTE)).thenReturn(new StandardPropertyValue("uid"));
    // using description in lieu of member
    when(configurationContext.getProperty(PROP_USER_GROUP_ATTRIBUTE)).thenReturn(new StandardPropertyValue("description"));
    when(configurationContext.getProperty(PROP_USER_GROUP_REFERENCED_GROUP_ATTRIBUTE)).thenReturn(new StandardPropertyValue("cn"));
    when(configurationContext.getProperty(PROP_GROUP_NAME_ATTRIBUTE)).thenReturn(new StandardPropertyValue("cn"));
    // using room because groupOfNames requires a member
    when(configurationContext.getProperty(PROP_GROUP_OBJECT_CLASS)).thenReturn(new StandardPropertyValue("room"));
    ldapUserGroupProvider.onConfigured(configurationContext);
    final Set<Group> groups = ldapUserGroupProvider.getGroups();
    assertEquals(1, groups.size());
    final Group team3 = groups.stream().filter(group -> "team3".equals(group.getName())).findFirst().orElse(null);
    assertNotNull(team3);
    assertEquals(1, team3.getUsers().size());
    assertEquals(1, team3.getUsers().stream().map(userIdentifier -> ldapUserGroupProvider.getUser(userIdentifier)).filter(user -> "user9".equals(user.getIdentity())).count());
}
Also used : CreateTransport(org.apache.directory.server.annotations.CreateTransport) PROP_URL(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_URL) PROP_USER_GROUP_ATTRIBUTE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_USER_GROUP_ATTRIBUTE) PROP_USER_IDENTITY_ATTRIBUTE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_USER_IDENTITY_ATTRIBUTE) PROP_CONNECT_TIMEOUT(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_CONNECT_TIMEOUT) PROP_USER_SEARCH_FILTER(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_USER_SEARCH_FILTER) CreateLdapServer(org.apache.directory.server.annotations.CreateLdapServer) CreatePartition(org.apache.directory.server.core.annotations.CreatePartition) Set(java.util.Set) PROP_PAGE_SIZE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_PAGE_SIZE) LdapAuthenticationStrategy(org.apache.nifi.registry.security.ldap.LdapAuthenticationStrategy) PROP_GROUP_SEARCH_SCOPE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_SEARCH_SCOPE) PROP_GROUP_OBJECT_CLASS(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_OBJECT_CLASS) Assert.assertFalse(org.junit.Assert.assertFalse) PROP_GROUP_MEMBER_REFERENCED_USER_ATTRIBUTE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_MEMBER_REFERENCED_USER_ATTRIBUTE) PROP_SYNC_INTERVAL(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_SYNC_INTERVAL) Mockito.mock(org.mockito.Mockito.mock) ReferralStrategy(org.apache.nifi.registry.security.ldap.ReferralStrategy) PROP_GROUP_SEARCH_FILTER(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_SEARCH_FILTER) PROP_USER_SEARCH_SCOPE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_USER_SEARCH_SCOPE) RunWith(org.junit.runner.RunWith) CreateDS(org.apache.directory.server.core.annotations.CreateDS) Matchers.anyString(org.mockito.Matchers.anyString) PROP_GROUP_MEMBER_ATTRIBUTE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_MEMBER_ATTRIBUTE) ApplyLdifFiles(org.apache.directory.server.core.annotations.ApplyLdifFiles) Group(org.apache.nifi.registry.security.authorization.Group) PROP_GROUP_NAME_ATTRIBUTE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_NAME_ATTRIBUTE) PROP_USER_GROUP_REFERENCED_GROUP_ATTRIBUTE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_USER_GROUP_REFERENCED_GROUP_ATTRIBUTE) PROP_USER_SEARCH_BASE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_USER_SEARCH_BASE) UserGroupProviderInitializationContext(org.apache.nifi.registry.security.authorization.UserGroupProviderInitializationContext) NiFiRegistryProperties(org.apache.nifi.registry.properties.NiFiRegistryProperties) UserAndGroups(org.apache.nifi.registry.security.authorization.UserAndGroups) FrameworkRunner(org.apache.directory.server.core.integ.FrameworkRunner) Before(org.junit.Before) PROP_AUTHENTICATION_STRATEGY(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_AUTHENTICATION_STRATEGY) Properties(java.util.Properties) PROP_USER_OBJECT_CLASS(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_USER_OBJECT_CLASS) SecurityProviderCreationException(org.apache.nifi.registry.security.exception.SecurityProviderCreationException) Assert.assertNotNull(org.junit.Assert.assertNotNull) PROP_MANAGER_DN(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_MANAGER_DN) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) StandardPropertyValue(org.apache.nifi.registry.util.StandardPropertyValue) PROP_MANAGER_PASSWORD(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_MANAGER_PASSWORD) Mockito(org.mockito.Mockito) AuthorizerConfigurationContext(org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext) PROP_REFERRAL_STRATEGY(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_REFERRAL_STRATEGY) PROP_READ_TIMEOUT(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_READ_TIMEOUT) AbstractLdapTestUnit(org.apache.directory.server.core.integ.AbstractLdapTestUnit) PROP_GROUP_SEARCH_BASE(org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_GROUP_SEARCH_BASE) Assert.assertEquals(org.junit.Assert.assertEquals) Group(org.apache.nifi.registry.security.authorization.Group) StandardPropertyValue(org.apache.nifi.registry.util.StandardPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 20 with AuthorizerConfigurationContext

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

the class LdapUserGroupProviderTest method testNoSearchBasesSpecified.

@Test(expected = SecurityProviderCreationException.class)
public void testNoSearchBasesSpecified() throws Exception {
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration(null, null);
    ldapUserGroupProvider.onConfigured(configurationContext);
}
Also used : AuthorizerConfigurationContext(org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Aggregations

AuthorizerConfigurationContext (org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext)37 Test (org.junit.Test)36 StandardPropertyValue (org.apache.nifi.registry.util.StandardPropertyValue)33 Group (org.apache.nifi.registry.security.authorization.Group)13 UserAndGroups (org.apache.nifi.registry.security.authorization.UserAndGroups)10 Properties (java.util.Properties)9 NiFiRegistryProperties (org.apache.nifi.registry.properties.NiFiRegistryProperties)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 UserGroupProviderInitializationContext (org.apache.nifi.registry.security.authorization.UserGroupProviderInitializationContext)8 SecurityProviderCreationException (org.apache.nifi.registry.security.exception.SecurityProviderCreationException)8 LdapAuthenticationStrategy (org.apache.nifi.registry.security.ldap.LdapAuthenticationStrategy)8 ReferralStrategy (org.apache.nifi.registry.security.ldap.ReferralStrategy)8 PROP_AUTHENTICATION_STRATEGY (org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.PROP_AUTHENTICATION_STRATEGY)8