exceptionfactory commented on code in PR #9813: URL: https://github.com/apache/nifi/pull/9813#discussion_r2034318885
########## nifi-extension-bundles/nifi-standard-bundle/nifi-standard-rules/src/main/java/org/apache/nifi/flowanalysis/rules/RequireServerSSLContextService.java: ########## @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.flowanalysis.rules; + +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.documentation.UseCase; +import org.apache.nifi.flow.VersionedComponent; +import org.apache.nifi.flow.VersionedConfigurableExtension; +import org.apache.nifi.flowanalysis.AbstractFlowAnalysisRule; +import org.apache.nifi.flowanalysis.ComponentAnalysisResult; +import org.apache.nifi.flowanalysis.FlowAnalysisRuleContext; +import org.apache.nifi.util.StringUtils; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; + + +@Tags({"component", "processor", "controller service", "type", "ssl", "tls", "listen"}) +@CapabilityDescription("Produces rule violations for each component (i.e. processors or controller services) having a property " + + "identifying an SSLContextService that is not set.") +@UseCase( + description = "Ensure that an SSL Context has been configured for the specified components. This helps avoid ports being opened for insecure (plaintext, e.g.) communications.", + configuration = """ + To avoid the violation, ensure that the "SSL Context Service" property is set for the specified component(s). + """ +) +public class RequireServerSSLContextService extends AbstractFlowAnalysisRule { + + private final List<String> componentTypes = List.of( + "org.apache.nifi.processors.standard.ListenFTP", + "org.apache.nifi.processors.standard.ListenHTTP", + "org.apache.nifi.processors.standard.ListenTCP", + "org.apache.nifi.processors.standard.ListenSyslog", + "org.apache.nifi.processors.standard.HandleHttpRequest", + "org.apache.nifi.websocket.jetty.JettyWebSocketServer" + ); + + @Override + public Collection<ComponentAnalysisResult> analyzeComponent(VersionedComponent component, FlowAnalysisRuleContext context) { + Collection<ComponentAnalysisResult> results = new HashSet<>(); + + if (component instanceof VersionedConfigurableExtension versionedConfigurableExtension) { + + String encounteredComponentType = versionedConfigurableExtension.getType(); + String encounteredSimpleComponentType = encounteredComponentType.substring(encounteredComponentType.lastIndexOf(".") + 1); + + if (componentTypes.isEmpty() || componentTypes.contains(encounteredComponentType) || componentTypes.contains(encounteredSimpleComponentType)) { Review Comment: This logic can be simplified since `componentTypes` is static: ```suggestion if (componentTypes.contains(encounteredComponentType)) { ``` ########## nifi-extension-bundles/nifi-standard-bundle/nifi-standard-rules/src/main/java/org/apache/nifi/flowanalysis/rules/RequireServerSSLContextService.java: ########## @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.flowanalysis.rules; + +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.documentation.UseCase; +import org.apache.nifi.flow.VersionedComponent; +import org.apache.nifi.flow.VersionedConfigurableExtension; +import org.apache.nifi.flowanalysis.AbstractFlowAnalysisRule; +import org.apache.nifi.flowanalysis.ComponentAnalysisResult; +import org.apache.nifi.flowanalysis.FlowAnalysisRuleContext; +import org.apache.nifi.util.StringUtils; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; + + +@Tags({"component", "processor", "controller service", "type", "ssl", "tls", "listen"}) +@CapabilityDescription("Produces rule violations for each component (i.e. processors or controller services) having a property " + + "identifying an SSLContextService that is not set.") +@UseCase( + description = "Ensure that an SSL Context has been configured for the specified components. This helps avoid ports being opened for insecure (plaintext, e.g.) communications.", + configuration = """ + To avoid the violation, ensure that the "SSL Context Service" property is set for the specified component(s). + """ +) +public class RequireServerSSLContextService extends AbstractFlowAnalysisRule { + + private final List<String> componentTypes = List.of( Review Comment: ```suggestion private static final List<String> componentTypes = List.of( ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
