Search in sources :

Example 1 with AllowableValue

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

the class TestPutS3Object method testSignerOverrideOptions.

@Test
public void testSignerOverrideOptions() {
    final AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
    final ClientConfiguration config = new ClientConfiguration();
    final PutS3Object processor = new PutS3Object();
    final TestRunner runner = TestRunners.newTestRunner(processor);
    final List<AllowableValue> allowableSignerValues = PutS3Object.SIGNER_OVERRIDE.getAllowableValues();
    final String defaultSignerValue = PutS3Object.SIGNER_OVERRIDE.getDefaultValue();
    for (AllowableValue allowableSignerValue : allowableSignerValues) {
        String signerType = allowableSignerValue.getValue();
        if (!signerType.equals(defaultSignerValue)) {
            runner.setProperty(PutS3Object.SIGNER_OVERRIDE, signerType);
            ProcessContext context = runner.getProcessContext();
            try {
                AmazonS3Client s3Client = processor.createClient(context, credentialsProvider, config);
            } catch (IllegalArgumentException argEx) {
                Assert.fail(argEx.getMessage());
            }
        }
    }
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AllowableValue(org.apache.nifi.components.AllowableValue) TestRunner(org.apache.nifi.util.TestRunner) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ClientConfiguration(com.amazonaws.ClientConfiguration) ProcessContext(org.apache.nifi.processor.ProcessContext) Test(org.junit.Test)

Example 2 with AllowableValue

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

the class ScriptingComponentHelper method createResources.

/**
 * This method creates all resources needed for the script processor to function, such as script engines,
 * script file reloader threads, etc.
 */
public void createResources() {
    descriptors = new ArrayList<>();
    // The following is required for JRuby, should be transparent to everything else.
    // Note this is not done in a ScriptEngineConfigurator, as it is too early in the lifecycle. The
    // setting must be there before the factories/engines are loaded.
    System.setProperty("org.jruby.embed.localvariable.behavior", "persistent");
    // Create list of available engines
    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    List<ScriptEngineFactory> scriptEngineFactories = scriptEngineManager.getEngineFactories();
    if (scriptEngineFactories != null) {
        scriptEngineFactoryMap = new HashMap<>(scriptEngineFactories.size());
        List<AllowableValue> engineList = new LinkedList<>();
        for (ScriptEngineFactory factory : scriptEngineFactories) {
            engineList.add(new AllowableValue(factory.getLanguageName()));
            scriptEngineFactoryMap.put(factory.getLanguageName(), factory);
        }
        // Sort the list by name so the list always looks the same.
        Collections.sort(engineList, (o1, o2) -> {
            if (o1 == null) {
                return o2 == null ? 0 : 1;
            }
            if (o2 == null) {
                return -1;
            }
            return o1.getValue().compareTo(o2.getValue());
        });
        AllowableValue[] engines = engineList.toArray(new AllowableValue[engineList.size()]);
        SCRIPT_ENGINE = new PropertyDescriptor.Builder().name("Script Engine").required(true).description("The engine to execute scripts").allowableValues(engines).defaultValue(engines[0].getValue()).required(true).expressionLanguageSupported(false).build();
        descriptors.add(SCRIPT_ENGINE);
    }
    descriptors.add(ScriptingComponentUtils.SCRIPT_FILE);
    descriptors.add(ScriptingComponentUtils.SCRIPT_BODY);
    descriptors.add(ScriptingComponentUtils.MODULES);
    isInitialized.set(true);
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) AllowableValue(org.apache.nifi.components.AllowableValue) ScriptEngineFactory(javax.script.ScriptEngineFactory) ScriptEngineManager(javax.script.ScriptEngineManager) LinkedList(java.util.LinkedList)

Example 3 with AllowableValue

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

the class EncryptContent method buildWeakCryptoAllowableValues.

private static AllowableValue[] buildWeakCryptoAllowableValues() {
    List<AllowableValue> allowableValues = new ArrayList<>();
    allowableValues.add(new AllowableValue(WEAK_CRYPTO_ALLOWED_NAME, "Allowed", "Operation will not be blocked and no alerts will be presented " + "when unsafe combinations of encryption algorithms and passwords are provided"));
    allowableValues.add(buildDefaultWeakCryptoAllowableValue());
    return allowableValues.toArray(new AllowableValue[0]);
}
Also used : AllowableValue(org.apache.nifi.components.AllowableValue) ArrayList(java.util.ArrayList)

Example 4 with AllowableValue

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

the class RestrictedSSLContextServiceTest method testTLSAlgorithms.

@Test
public void testTLSAlgorithms() {
    final Set<String> expected = new HashSet<>();
    expected.add("TLS");
    expected.add("TLSv1.2");
    final AllowableValue[] allowableValues = RestrictedSSLContextService.buildAlgorithmAllowableValues();
    assertThat(allowableValues, notNullValue());
    assertThat(allowableValues.length, equalTo(expected.size()));
    for (final AllowableValue value : allowableValues) {
        assertTrue(expected.contains(value.getValue()));
    }
}
Also used : AllowableValue(org.apache.nifi.components.AllowableValue) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with AllowableValue

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

the class RestrictedSSLContextService method buildAlgorithmAllowableValues.

/**
 * Build a restricted set of allowable TLS protocol algorithms.
 *
 * @return the computed set of allowable values
 */
static AllowableValue[] buildAlgorithmAllowableValues() {
    final Set<String> supportedProtocols = new HashSet<>();
    /*
         * Prepopulate protocols with generic instance types commonly used
         * see: http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#SSLContext
         */
    supportedProtocols.add("TLS");
    /*
         * Add specifically supported TLS versions
         */
    supportedProtocols.add("TLSv1.2");
    final int numProtocols = supportedProtocols.size();
    // Sort for consistent presentation in configuration views
    final List<String> supportedProtocolList = new ArrayList<>(supportedProtocols);
    Collections.sort(supportedProtocolList);
    final List<AllowableValue> protocolAllowableValues = new ArrayList<>();
    for (final String protocol : supportedProtocolList) {
        protocolAllowableValues.add(new AllowableValue(protocol));
    }
    return protocolAllowableValues.toArray(new AllowableValue[numProtocols]);
}
Also used : AllowableValue(org.apache.nifi.components.AllowableValue) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

AllowableValue (org.apache.nifi.components.AllowableValue)12 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ScriptEngineFactory (javax.script.ScriptEngineFactory)1 ScriptEngineManager (javax.script.ScriptEngineManager)1 Bundle (org.apache.nifi.bundle.Bundle)1 ControllerService (org.apache.nifi.controller.ControllerService)1 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)1 ProcessContext (org.apache.nifi.processor.ProcessContext)1 EncryptionMethod (org.apache.nifi.security.util.EncryptionMethod)1 KeyDerivationFunction (org.apache.nifi.security.util.KeyDerivationFunction)1