Search in sources :

Example 36 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class FileUserGroupProviderTest method setup.

@Before
public void setup() throws IOException {
    // primary tenants
    primaryTenants = new File("target/authorizations/users.xml");
    FileUtils.ensureDirectoryExistAndCanAccess(primaryTenants.getParentFile());
    // restore authorizations
    restoreTenants = new File("target/restore/users.xml");
    FileUtils.ensureDirectoryExistAndCanAccess(restoreTenants.getParentFile());
    properties = mock(NiFiProperties.class);
    when(properties.getRestoreDirectory()).thenReturn(restoreTenants.getParentFile());
    configurationContext = mock(AuthorizerConfigurationContext.class);
    when(configurationContext.getProperty(eq(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE))).thenReturn(new StandardPropertyValue(null, null));
    when(configurationContext.getProperty(eq(FileUserGroupProvider.PROP_TENANTS_FILE))).thenReturn(new StandardPropertyValue(primaryTenants.getPath(), null));
    when(configurationContext.getProperties()).then((invocation) -> {
        final Map<String, String> properties = new HashMap<>();
        final PropertyValue tenantFile = configurationContext.getProperty(FileUserGroupProvider.PROP_TENANTS_FILE);
        if (tenantFile != null) {
            properties.put(FileUserGroupProvider.PROP_TENANTS_FILE, tenantFile.getValue());
        }
        final PropertyValue legacyAuthFile = configurationContext.getProperty(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE);
        if (legacyAuthFile != null) {
            properties.put(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE, legacyAuthFile.getValue());
        }
        int i = 1;
        while (true) {
            final String key = FileUserGroupProvider.PROP_INITIAL_USER_IDENTITY_PREFIX + i++;
            final PropertyValue value = configurationContext.getProperty(key);
            if (value == null) {
                break;
            } else {
                properties.put(key, value.getValue());
            }
        }
        return properties;
    });
    userGroupProvider = new FileUserGroupProvider();
    userGroupProvider.setNiFiProperties(properties);
    userGroupProvider.initialize(null);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) HashMap(java.util.HashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) Before(org.junit.Before)

Example 37 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class CompositeConfigurableUserGroupProvider method onConfigured.

@Override
public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException {
    final PropertyValue configurableUserGroupProviderKey = configurationContext.getProperty(PROP_CONFIGURABLE_USER_GROUP_PROVIDER);
    if (!configurableUserGroupProviderKey.isSet()) {
        throw new AuthorizerCreationException("The Configurable User Group Provider must be set.");
    }
    final UserGroupProvider userGroupProvider = userGroupProviderLookup.getUserGroupProvider(configurableUserGroupProviderKey.getValue());
    if (userGroupProvider == null) {
        throw new AuthorizerCreationException(String.format("Unable to locate the Configurable User Group Provider: %s", configurableUserGroupProviderKey));
    }
    if (!(userGroupProvider instanceof ConfigurableUserGroupProvider)) {
        throw new AuthorizerCreationException(String.format("The Configurable User Group Provider is not configurable: %s", configurableUserGroupProviderKey));
    }
    // Ensure that the ConfigurableUserGroupProvider is not also listed as one of the providers for the CompositeUserGroupProvider
    for (Map.Entry<String, String> entry : configurationContext.getProperties().entrySet()) {
        Matcher matcher = USER_GROUP_PROVIDER_PATTERN.matcher(entry.getKey());
        if (matcher.matches() && !StringUtils.isBlank(entry.getValue())) {
            final String userGroupProviderKey = entry.getValue();
            if (userGroupProviderKey.equals(configurableUserGroupProviderKey.getValue())) {
                throw new AuthorizerCreationException(String.format("Duplicate provider in Composite Configurable User Group Provider configuration: %s", userGroupProviderKey));
            }
        }
    }
    configurableUserGroupProvider = (ConfigurableUserGroupProvider) userGroupProvider;
    // configure the CompositeUserGroupProvider
    super.onConfigured(configurationContext);
}
Also used : Matcher(java.util.regex.Matcher) AuthorizerCreationException(org.apache.nifi.authorization.exception.AuthorizerCreationException) PropertyValue(org.apache.nifi.components.PropertyValue) Map(java.util.Map)

Example 38 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class StandardManagedAuthorizer method onConfigured.

@Override
public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException {
    final PropertyValue accessPolicyProviderKey = configurationContext.getProperty("Access Policy Provider");
    if (!accessPolicyProviderKey.isSet()) {
        throw new AuthorizerCreationException("The Access Policy Provider must be set.");
    }
    accessPolicyProvider = accessPolicyProviderLookup.getAccessPolicyProvider(accessPolicyProviderKey.getValue());
    // ensure the desired access policy provider was found
    if (accessPolicyProvider == null) {
        throw new AuthorizerCreationException(String.format("Unable to locate configured Access Policy Provider: %s", accessPolicyProviderKey));
    }
    userGroupProvider = accessPolicyProvider.getUserGroupProvider();
    // ensure the desired access policy provider has a user group provider
    if (userGroupProvider == null) {
        throw new AuthorizerCreationException(String.format("Configured Access Policy Provider %s does not contain a User Group Provider", accessPolicyProviderKey));
    }
}
Also used : AuthorizerCreationException(org.apache.nifi.authorization.exception.AuthorizerCreationException) PropertyValue(org.apache.nifi.components.PropertyValue)

Example 39 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project kylo by Teradata.

the class MetadataProviderSelectorService method onConfigured.

@OnEnabled
public void onConfigured(final ConfigurationContext context) {
    PropertyValue impl = context.getProperty(IMPLEMENTATION);
    if (impl.getValue().equalsIgnoreCase("REMOTE")) {
        URI uri = URI.create(context.getProperty(CLIENT_URL).getValue());
        String user = context.getProperty(CLIENT_USERNAME).getValue();
        String password = context.getProperty(CLIENT_PASSWORD).getValue();
        MetadataClient client;
        SSLContext sslContext = null;
        if (context.getProperty(SSL_CONTEXT_SERVICE) != null && context.getProperty(SSL_CONTEXT_SERVICE).isSet()) {
            this.sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
            sslContext = this.sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
        }
        if (StringUtils.isEmpty(user)) {
            client = new MetadataClient(uri, sslContext);
        } else {
            client = new MetadataClient(uri, user, password, sslContext);
        }
        this.provider = new MetadataClientProvider(client);
        this.recorder = new MetadataClientRecorder(client);
        this.kyloProvenanceClientProvider = new KyloProvenanceClientProvider(client);
        getSpringContextService(context).ifPresent(springService -> {
            CancelActiveWaterMarkEventConsumer waterMarkConsumer = springService.getBean(CancelActiveWaterMarkEventConsumer.class);
            waterMarkConsumer.addMetadataRecorder(this.recorder);
            FeedInitializationChangeEventConsumer initChangeConsumer = springService.getBean(FeedInitializationChangeEventConsumer.class);
            initChangeConsumer.addMetadataRecorder(this.recorder);
        });
    } else {
        throw new UnsupportedOperationException("Provider implementations not currently supported: " + impl.getValue());
    }
}
Also used : FeedInitializationChangeEventConsumer(com.thinkbiganalytics.nifi.v2.core.feedinit.FeedInitializationChangeEventConsumer) MetadataClient(com.thinkbiganalytics.metadata.rest.client.MetadataClient) SSLContextService(org.apache.nifi.ssl.SSLContextService) PropertyValue(org.apache.nifi.components.PropertyValue) CancelActiveWaterMarkEventConsumer(com.thinkbiganalytics.nifi.v2.core.watermark.CancelActiveWaterMarkEventConsumer) SSLContext(javax.net.ssl.SSLContext) URI(java.net.URI) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 40 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project kylo by Teradata.

the class CreateHDFSFolder method modifyConfig.

@Override
protected void modifyConfig(ProcessContext context, Configuration config) {
    // Set umask once, to avoid thread safety issues doing it in onTrigger
    final PropertyValue umaskProp = context.getProperty(UMASK);
    final short dfsUmask = resolveUMask(umaskProp);
    short oldUmask = Short.parseShort(config.get(FsPermission.UMASK_LABEL), 8);
    if (oldUmask != dfsUmask) {
        FsPermission umask = FsPermission.createImmutable(dfsUmask);
        FsPermission.setUMask(config, umask);
    }
}
Also used : PropertyValue(org.apache.nifi.components.PropertyValue) FsPermission(org.apache.hadoop.fs.permission.FsPermission)

Aggregations

PropertyValue (org.apache.nifi.components.PropertyValue)73 HashMap (java.util.HashMap)29 Test (org.junit.Test)22 StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)21 ComponentLog (org.apache.nifi.logging.ComponentLog)18 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)16 IOException (java.io.IOException)15 Map (java.util.Map)13 FlowFile (org.apache.nifi.flowfile.FlowFile)11 ProcessException (org.apache.nifi.processor.exception.ProcessException)11 MockPropertyValue (org.apache.nifi.util.MockPropertyValue)11 ArrayList (java.util.ArrayList)9 SSLContext (javax.net.ssl.SSLContext)7 Relationship (org.apache.nifi.processor.Relationship)7 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)6 File (java.io.File)5 DynamicRelationship (org.apache.nifi.annotation.behavior.DynamicRelationship)5 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)5 SchemaIdentifier (org.apache.nifi.serialization.record.SchemaIdentifier)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5