Search in sources :

Example 21 with StandardPropertyValue

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

the class LdapUserGroupProviderTest method testUserIdentityMapping.

@Test
public void testUserIdentityMapping() throws Exception {
    final Properties props = new Properties();
    props.setProperty("nifi.security.identity.mapping.pattern.dn1", "^cn=(.*?),o=(.*?)$");
    props.setProperty("nifi.security.identity.mapping.value.dn1", "$1");
    final NiFiProperties properties = getNiFiProperties(props);
    ldapUserGroupProvider.setNiFiProperties(properties);
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration(USER_SEARCH_BASE, null);
    when(configurationContext.getProperty(PROP_USER_SEARCH_FILTER)).thenReturn(new StandardPropertyValue("(uid=user1)", null));
    ldapUserGroupProvider.onConfigured(configurationContext);
    assertEquals(1, ldapUserGroupProvider.getUsers().size());
    assertNotNull(ldapUserGroupProvider.getUserByIdentity("User 1,ou=users"));
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 22 with StandardPropertyValue

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

the class LdapUserGroupProviderTest method testUserSearchBaseSpecifiedButNoGroupSearchScope.

@Test(expected = AuthorizerCreationException.class)
public void testUserSearchBaseSpecifiedButNoGroupSearchScope() 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(null, 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 23 with StandardPropertyValue

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

the class LdapUserGroupProviderTest method testSearchGroupsWithPaging.

@Test
public void testSearchGroupsWithPaging() 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_PAGE_SIZE)).thenReturn(new StandardPropertyValue("1", null));
    ldapUserGroupProvider.onConfigured(configurationContext);
    assertEquals(4, ldapUserGroupProvider.getGroups().size());
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 24 with StandardPropertyValue

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

the class TestSiteToSiteBulletinReportingTask method testUrls.

@Test
public void testUrls() throws IOException {
    final ValidationContext context = Mockito.mock(ValidationContext.class);
    Mockito.when(context.newPropertyValue(Mockito.anyString())).then(new Answer<PropertyValue>() {

        @Override
        public PropertyValue answer(InvocationOnMock invocation) throws Throwable {
            String value = (String) invocation.getArguments()[0];
            return new StandardPropertyValue(value, null);
        }
    });
    assertTrue(new NiFiUrlValidator().validate("url", "http://localhost:8080/nifi", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "http://localhost:8080", context).isValid());
    assertFalse(new NiFiUrlValidator().validate("url", "", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "https://localhost:8080/nifi", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "https://localhost:8080/nifi,https://localhost:8080/nifi", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "https://localhost:8080/nifi, https://localhost:8080/nifi", context).isValid());
    assertFalse(new NiFiUrlValidator().validate("url", "http://localhost:8080/nifi, https://localhost:8080/nifi", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "http://localhost:8080/nifi,http://localhost:8080/nifi", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "http://localhost:8080/nifi,http://localhost:8080", context).isValid());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) ValidationContext(org.apache.nifi.components.ValidationContext) NiFiUrlValidator(org.apache.nifi.reporting.AbstractSiteToSiteReportingTask.NiFiUrlValidator) Test(org.junit.Test)

Example 25 with StandardPropertyValue

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

the class NotificationServiceManager method buildNotificationContext.

private NotificationContext buildNotificationContext(final ConfiguredNotificationService config) {
    return new NotificationContext() {

        @Override
        public PropertyValue getProperty(final PropertyDescriptor descriptor) {
            final PropertyDescriptor fullPropDescriptor = config.getService().getPropertyDescriptor(descriptor.getName());
            if (fullPropDescriptor == null) {
                return null;
            }
            String configuredValue = config.getProperties().get(fullPropDescriptor.getName());
            if (configuredValue == null) {
                configuredValue = fullPropDescriptor.getDefaultValue();
            }
            return new StandardPropertyValue(configuredValue, null, variableRegistry);
        }

        @Override
        public Map<PropertyDescriptor, String> getProperties() {
            final Map<PropertyDescriptor, String> props = new HashMap<>();
            final Map<String, String> configuredProps = config.getProperties();
            final NotificationService service = config.getService();
            final List<PropertyDescriptor> configuredPropertyDescriptors = new ArrayList<>(service.getPropertyDescriptors());
            // This is needed to capture all dynamic properties
            configuredProps.forEach((key, value) -> {
                PropertyDescriptor propertyDescriptor = config.service.getPropertyDescriptor(key);
                props.put(config.service.getPropertyDescriptor(key), value);
                configuredPropertyDescriptors.remove(propertyDescriptor);
            });
            for (final PropertyDescriptor descriptor : configuredPropertyDescriptors) {
                props.put(descriptor, descriptor.getDefaultValue());
            }
            return props;
        }
    };
}
Also used : NotificationContext(org.apache.nifi.bootstrap.notification.NotificationContext) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) ArrayList(java.util.ArrayList) NotificationService(org.apache.nifi.bootstrap.notification.NotificationService)

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