Search in sources :

Example 1 with AtlasAuthN

use of org.apache.nifi.atlas.security.AtlasAuthN in project nifi by apache.

the class ReportLineageToAtlas method customValidate.

@Override
protected Collection<ValidationResult> customValidate(ValidationContext context) {
    final Collection<ValidationResult> results = new ArrayList<>();
    final boolean isSSLContextServiceSet = context.getProperty(SSL_CONTEXT_SERVICE).isSet();
    final ValidationResult.Builder invalidSSLService = new ValidationResult.Builder().subject(SSL_CONTEXT_SERVICE.getDisplayName()).valid(false);
    parseAtlasUrls(context.getProperty(ATLAS_URLS), input -> {
        final ValidationResult.Builder builder = new ValidationResult.Builder().subject(ATLAS_URLS.getDisplayName()).input(input);
        try {
            final URL url = new URL(input);
            if ("https".equalsIgnoreCase(url.getProtocol()) && !isSSLContextServiceSet) {
                results.add(invalidSSLService.explanation("required by HTTPS Atlas access").build());
            } else {
                results.add(builder.explanation("Valid URI").valid(true).build());
            }
        } catch (Exception e) {
            results.add(builder.explanation("Contains invalid URI: " + e).valid(false).build());
        }
    });
    final String atlasAuthNMethod = context.getProperty(ATLAS_AUTHN_METHOD).getValue();
    final AtlasAuthN atlasAuthN = getAtlasAuthN(atlasAuthNMethod);
    results.addAll(atlasAuthN.validate(context));
    clusterResolverLoader.forEach(resolver -> results.addAll(resolver.validate(context)));
    if (context.getProperty(ATLAS_CONF_CREATE).asBoolean()) {
        Stream.of(ATLAS_CONF_DIR, ATLAS_DEFAULT_CLUSTER_NAME, KAFKA_BOOTSTRAP_SERVERS).filter(p -> !context.getProperty(p).isSet()).forEach(p -> results.add(new ValidationResult.Builder().subject(p.getDisplayName()).explanation("required to create Atlas configuration file.").valid(false).build()));
        validateKafkaProperties(context, results, isSSLContextServiceSet, invalidSSLService);
    }
    return results;
}
Also used : AtlasAuthN(org.apache.nifi.atlas.security.AtlasAuthN) StandardValidators(org.apache.nifi.processor.util.StandardValidators) Arrays(java.util.Arrays) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) URL(java.net.URL) Kerberos(org.apache.nifi.atlas.security.Kerberos) StringUtils(org.apache.commons.lang3.StringUtils) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) PropertyValue(org.apache.nifi.components.PropertyValue) Scope(org.apache.nifi.components.state.Scope) AbstractReportingTask(org.apache.nifi.reporting.AbstractReportingTask) Map(java.util.Map) PROVENANCE_START_POSITION(org.apache.nifi.reporting.util.provenance.ProvenanceEventConsumer.PROVENANCE_START_POSITION) ProvenanceRepository(org.apache.nifi.provenance.ProvenanceRepository) ZoneOffset(java.time.ZoneOffset) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) PROVENANCE_BATCH_SIZE(org.apache.nifi.reporting.util.provenance.ProvenanceEventConsumer.PROVENANCE_BATCH_SIZE) RequiresInstanceClassLoading(org.apache.nifi.annotation.behavior.RequiresInstanceClassLoading) OnUnscheduled(org.apache.nifi.annotation.lifecycle.OnUnscheduled) AtlasServiceException(org.apache.atlas.AtlasServiceException) Collection(java.util.Collection) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) SSLContextService(org.apache.nifi.ssl.SSLContextService) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) AllowableValue(org.apache.nifi.components.AllowableValue) Instant(java.time.Instant) AnalysisContext(org.apache.nifi.atlas.provenance.AnalysisContext) CompleteFlowPathLineage(org.apache.nifi.atlas.provenance.lineage.CompleteFlowPathLineage) Stateful(org.apache.nifi.annotation.behavior.Stateful) List(java.util.List) DynamicProperty(org.apache.nifi.annotation.behavior.DynamicProperty) Stream(java.util.stream.Stream) NiFiFlowAnalyzer(org.apache.nifi.atlas.NiFiFlowAnalyzer) Tags(org.apache.nifi.annotation.documentation.Tags) ClusterResolver(org.apache.nifi.atlas.resolver.ClusterResolver) EventAccess(org.apache.nifi.reporting.EventAccess) ProvenanceEventConsumer(org.apache.nifi.reporting.util.provenance.ProvenanceEventConsumer) StandardAnalysisContext(org.apache.nifi.atlas.provenance.StandardAnalysisContext) CapabilityDescription(org.apache.nifi.annotation.documentation.CapabilityDescription) Basic(org.apache.nifi.atlas.security.Basic) ValidationContext(org.apache.nifi.components.ValidationContext) ClientResponse(com.sun.jersey.api.client.ClientResponse) NIFI_KERBEROS_PRINCIPAL(org.apache.nifi.atlas.reporting.ReportLineageToAtlas.NIFI_KERBEROS_PRINCIPAL) ProcessException(org.apache.nifi.processor.exception.ProcessException) ArrayList(java.util.ArrayList) RegexClusterResolver(org.apache.nifi.atlas.resolver.RegexClusterResolver) NiFiAtlasHook(org.apache.nifi.atlas.NiFiAtlasHook) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) SslConfigs(org.apache.kafka.common.config.SslConfigs) ValidationResult(org.apache.nifi.components.ValidationResult) LinkedHashSet(java.util.LinkedHashSet) PropertyContext(org.apache.nifi.context.PropertyContext) NiFiFlow(org.apache.nifi.atlas.NiFiFlow) Properties(java.util.Properties) NiFiAtlasClient(org.apache.nifi.atlas.NiFiAtlasClient) MalformedURLException(java.net.MalformedURLException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ReportingContext(org.apache.nifi.reporting.ReportingContext) File(java.io.File) SimpleFlowPathLineage(org.apache.nifi.atlas.provenance.lineage.SimpleFlowPathLineage) Consumer(java.util.function.Consumer) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled) KerberosCredentialsService(org.apache.nifi.kerberos.KerberosCredentialsService) AtlasAuthN(org.apache.nifi.atlas.security.AtlasAuthN) NIFI_KERBEROS_KEYTAB(org.apache.nifi.atlas.reporting.ReportLineageToAtlas.NIFI_KERBEROS_KEYTAB) LineageStrategy(org.apache.nifi.atlas.provenance.lineage.LineageStrategy) ClusterResolvers(org.apache.nifi.atlas.resolver.ClusterResolvers) DateTimeFormatter(java.time.format.DateTimeFormatter) ApplicationProperties(org.apache.atlas.ApplicationProperties) OnStopped(org.apache.nifi.annotation.lifecycle.OnStopped) Collections(java.util.Collections) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult) URL(java.net.URL) AtlasServiceException(org.apache.atlas.AtlasServiceException) ProcessException(org.apache.nifi.processor.exception.ProcessException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 2 with AtlasAuthN

use of org.apache.nifi.atlas.security.AtlasAuthN in project nifi by apache.

the class ITNiFiAtlasClient method setup.

@Before
public void setup() {
    // Add your atlas server ip address into /etc/hosts as atlas.example.com
    PropertyContext propertyContext = mock(PropertyContext.class);
    when(propertyContext.getProperty(ReportLineageToAtlas.ATLAS_USER)).thenReturn(new MockPropertyValue("admin"));
    when(propertyContext.getProperty(ReportLineageToAtlas.ATLAS_PASSWORD)).thenReturn(new MockPropertyValue("admin"));
    final AtlasAuthN atlasAuthN = new Basic();
    atlasAuthN.configure(propertyContext);
    atlasClient = new NiFiAtlasClient(atlasAuthN.createClient(new String[] { "http://atlas.example.com:21000/" }));
}
Also used : AtlasAuthN(org.apache.nifi.atlas.security.AtlasAuthN) Basic(org.apache.nifi.atlas.security.Basic) PropertyContext(org.apache.nifi.context.PropertyContext) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) Before(org.junit.Before)

Aggregations

ClientResponse (com.sun.jersey.api.client.ClientResponse)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Instant (java.time.Instant)1 ZoneOffset (java.time.ZoneOffset)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ServiceLoader (java.util.ServiceLoader)1