Search in sources :

Example 6 with AllowableValue

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

the class HtmlDocumentationWriter method writeValidValues.

/**
 * Interrogates a PropertyDescriptor to get a list of AllowableValues, if
 * there are none, nothing is written to the stream.
 *
 * @param xmlStreamWriter the stream writer to use
 * @param property the property to describe
 * @throws XMLStreamException thrown if there was a problem writing to the
 * XML Stream
 */
protected void writeValidValues(XMLStreamWriter xmlStreamWriter, PropertyDescriptor property) throws XMLStreamException {
    if (property.getAllowableValues() != null && property.getAllowableValues().size() > 0) {
        xmlStreamWriter.writeStartElement("ul");
        for (AllowableValue value : property.getAllowableValues()) {
            xmlStreamWriter.writeStartElement("li");
            xmlStreamWriter.writeCharacters(value.getDisplayName());
            if (value.getDescription() != null) {
                writeValidValueDescription(xmlStreamWriter, value.getDescription());
            }
            xmlStreamWriter.writeEndElement();
        }
        xmlStreamWriter.writeEndElement();
    } else if (property.getControllerServiceDefinition() != null) {
        Class<? extends ControllerService> controllerServiceClass = property.getControllerServiceDefinition();
        writeSimpleElement(xmlStreamWriter, "strong", "Controller Service API: ");
        xmlStreamWriter.writeEmptyElement("br");
        xmlStreamWriter.writeCharacters(controllerServiceClass.getSimpleName());
        final List<Class<? extends ControllerService>> implementationList = lookupControllerServiceImpls(controllerServiceClass);
        // Convert it into an array before proceeding
        Class<? extends ControllerService>[] implementations = implementationList.stream().toArray(Class[]::new);
        xmlStreamWriter.writeEmptyElement("br");
        if (implementations.length > 0) {
            final String title = implementations.length > 1 ? "Implementations: " : "Implementation: ";
            writeSimpleElement(xmlStreamWriter, "strong", title);
            iterateAndLinkComponents(xmlStreamWriter, implementations, null, "<br>", controllerServiceClass.getSimpleName());
        } else {
            xmlStreamWriter.writeCharacters("No implementations found.");
        }
    }
}
Also used : AllowableValue(org.apache.nifi.components.AllowableValue) ArrayList(java.util.ArrayList) List(java.util.List) ControllerService(org.apache.nifi.controller.ControllerService)

Example 7 with AllowableValue

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

the class EncryptContent method buildEncryptionMethodAllowableValues.

private static AllowableValue[] buildEncryptionMethodAllowableValues() {
    final EncryptionMethod[] encryptionMethods = EncryptionMethod.values();
    List<AllowableValue> allowableValues = new ArrayList<>(encryptionMethods.length);
    for (EncryptionMethod em : encryptionMethods) {
        allowableValues.add(new AllowableValue(em.name(), em.name(), em.toString()));
    }
    return allowableValues.toArray(new AllowableValue[0]);
}
Also used : AllowableValue(org.apache.nifi.components.AllowableValue) ArrayList(java.util.ArrayList) EncryptionMethod(org.apache.nifi.security.util.EncryptionMethod)

Example 8 with AllowableValue

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

the class EncryptContent method buildKeyDerivationFunctionAllowableValues.

private static AllowableValue[] buildKeyDerivationFunctionAllowableValues() {
    final KeyDerivationFunction[] keyDerivationFunctions = KeyDerivationFunction.values();
    List<AllowableValue> allowableValues = new ArrayList<>(keyDerivationFunctions.length);
    for (KeyDerivationFunction kdf : keyDerivationFunctions) {
        allowableValues.add(new AllowableValue(kdf.name(), kdf.getName(), kdf.getDescription()));
    }
    return allowableValues.toArray(new AllowableValue[0]);
}
Also used : KeyDerivationFunction(org.apache.nifi.security.util.KeyDerivationFunction) AllowableValue(org.apache.nifi.components.AllowableValue) ArrayList(java.util.ArrayList)

Example 9 with AllowableValue

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

the class SSLContextServiceTest method testSSLAlgorithms.

@Test
public void testSSLAlgorithms() throws NoSuchAlgorithmException {
    final AllowableValue[] allowableValues = SSLContextService.buildAlgorithmAllowableValues();
    // we expect TLS, SSL, and all available configured JVM protocols
    final Set<String> expected = new HashSet<>();
    expected.add("SSL");
    expected.add("TLS");
    final String[] supportedProtocols = SSLContext.getDefault().createSSLEngine().getSupportedProtocols();
    expected.addAll(Arrays.asList(supportedProtocols));
    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 10 with AllowableValue

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

the class SSLContextService method buildAlgorithmAllowableValues.

/**
 * Build a set of allowable TLS/SSL protocol algorithms based on JVM configuration.
 *
 * @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");
    supportedProtocols.add("SSL");
    // Determine those provided by the JVM on the system
    try {
        supportedProtocols.addAll(Arrays.asList(SSLContext.getDefault().createSSLEngine().getSupportedProtocols()));
    } catch (NoSuchAlgorithmException e) {
    // ignored as default is used
    }
    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) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) 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