NIFI-11098 Deprecated ProcessContext encrypt and decrypt methods

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #6891.
This commit is contained in:
exceptionfactory 2023-01-25 20:19:32 -06:00 committed by Pierre Villard
parent 97cb3c4eaa
commit d60f541d7e
No known key found for this signature in database
GPG Key ID: F92A93B30C07C6D5
3 changed files with 19 additions and 0 deletions

View File

@ -99,18 +99,22 @@ public interface ProcessContext extends PropertyContext, ClusterContext {
* Encrypts the given value using the password provided in the NiFi * Encrypts the given value using the password provided in the NiFi
* Properties * Properties
* *
* @deprecated Processors should not depend on framework encryption operations
* @param unencrypted plaintext value * @param unencrypted plaintext value
* @return encrypted value * @return encrypted value
*/ */
@Deprecated
String encrypt(String unencrypted); String encrypt(String unencrypted);
/** /**
* Decrypts the given value using the password provided in the NiFi * Decrypts the given value using the password provided in the NiFi
* Properties * Properties
* *
* @deprecated Processors should not depend on framework encryption operations
* @param encrypted the encrypted value * @param encrypted the encrypted value
* @return the plaintext value * @return the plaintext value
*/ */
@Deprecated
String decrypt(String encrypted); String decrypt(String encrypted);
/** /**

View File

@ -25,6 +25,8 @@ import org.apache.nifi.connectable.Connectable;
import org.apache.nifi.connectable.Connection; import org.apache.nifi.connectable.Connection;
import org.apache.nifi.controller.ControllerService; import org.apache.nifi.controller.ControllerService;
import org.apache.nifi.controller.ControllerServiceLookup; import org.apache.nifi.controller.ControllerServiceLookup;
import org.apache.nifi.deprecation.log.DeprecationLogger;
import org.apache.nifi.deprecation.log.DeprecationLoggerFactory;
import org.apache.nifi.encrypt.PropertyEncryptor; import org.apache.nifi.encrypt.PropertyEncryptor;
import org.apache.nifi.expression.AttributeValueDecorator; import org.apache.nifi.expression.AttributeValueDecorator;
import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.flowfile.FlowFile;
@ -52,10 +54,13 @@ public class ConnectableProcessContext implements ProcessContext {
private final PropertyEncryptor propertyEncryptor; private final PropertyEncryptor propertyEncryptor;
private final StateManager stateManager; private final StateManager stateManager;
private final DeprecationLogger deprecationLogger;
public ConnectableProcessContext(final Connectable connectable, final PropertyEncryptor propertyEncryptor, final StateManager stateManager) { public ConnectableProcessContext(final Connectable connectable, final PropertyEncryptor propertyEncryptor, final StateManager stateManager) {
this.connectable = connectable; this.connectable = connectable;
this.propertyEncryptor = propertyEncryptor; this.propertyEncryptor = propertyEncryptor;
this.stateManager = stateManager; this.stateManager = stateManager;
this.deprecationLogger = DeprecationLoggerFactory.getLogger(connectable.getClass());
} }
@Override @Override
@ -224,11 +229,13 @@ public class ConnectableProcessContext implements ProcessContext {
@Override @Override
public String decrypt(String encrypted) { public String decrypt(String encrypted) {
deprecationLogger.warn("ProcessContext.decrypt() should be replaced an alternative implementation");
return propertyEncryptor.decrypt(encrypted); return propertyEncryptor.decrypt(encrypted);
} }
@Override @Override
public String encrypt(String unencrypted) { public String encrypt(String unencrypted) {
deprecationLogger.warn("ProcessContext.encrypt() should be replaced an alternative implementation");
return propertyEncryptor.encrypt(unencrypted); return propertyEncryptor.encrypt(unencrypted);
} }

View File

@ -36,6 +36,8 @@ import org.apache.nifi.controller.PropertyConfiguration;
import org.apache.nifi.controller.PropertyConfigurationMapper; import org.apache.nifi.controller.PropertyConfigurationMapper;
import org.apache.nifi.controller.lifecycle.TaskTermination; import org.apache.nifi.controller.lifecycle.TaskTermination;
import org.apache.nifi.controller.service.ControllerServiceProvider; import org.apache.nifi.controller.service.ControllerServiceProvider;
import org.apache.nifi.deprecation.log.DeprecationLogger;
import org.apache.nifi.deprecation.log.DeprecationLoggerFactory;
import org.apache.nifi.encrypt.PropertyEncryptor; import org.apache.nifi.encrypt.PropertyEncryptor;
import org.apache.nifi.parameter.ParameterLookup; import org.apache.nifi.parameter.ParameterLookup;
import org.apache.nifi.processor.exception.TerminatedTaskException; import org.apache.nifi.processor.exception.TerminatedTaskException;
@ -62,6 +64,7 @@ public class StandardProcessContext implements ProcessContext, ControllerService
private final NodeTypeProvider nodeTypeProvider; private final NodeTypeProvider nodeTypeProvider;
private final Map<PropertyDescriptor, String> properties; private final Map<PropertyDescriptor, String> properties;
private final String annotationData; private final String annotationData;
private final DeprecationLogger deprecationLogger;
public StandardProcessContext(final ProcessorNode processorNode, final ControllerServiceProvider controllerServiceProvider, final PropertyEncryptor propertyEncryptor, public StandardProcessContext(final ProcessorNode processorNode, final ControllerServiceProvider controllerServiceProvider, final PropertyEncryptor propertyEncryptor,
@ -89,6 +92,9 @@ public class StandardProcessContext implements ProcessContext, ControllerService
this.taskTermination = taskTermination; this.taskTermination = taskTermination;
this.nodeTypeProvider = nodeTypeProvider; this.nodeTypeProvider = nodeTypeProvider;
this.annotationData = annotationData; this.annotationData = annotationData;
final Class<?> componentClass = processorNode.getComponentClass();
final Class<?> loggerClass = componentClass == null ? getClass() : componentClass;
this.deprecationLogger = DeprecationLoggerFactory.getLogger(loggerClass);
properties = Collections.unmodifiableMap(propertyValues); properties = Collections.unmodifiableMap(propertyValues);
@ -227,12 +233,14 @@ public class StandardProcessContext implements ProcessContext, ControllerService
@Override @Override
public String encrypt(final String unencrypted) { public String encrypt(final String unencrypted) {
verifyTaskActive(); verifyTaskActive();
deprecationLogger.warn("ProcessContext.encrypt() should be replaced an alternative implementation");
return propertyEncryptor.encrypt(unencrypted); return propertyEncryptor.encrypt(unencrypted);
} }
@Override @Override
public String decrypt(final String encrypted) { public String decrypt(final String encrypted) {
verifyTaskActive(); verifyTaskActive();
deprecationLogger.warn("ProcessContext.decrypt() should be replaced an alternative implementation");
return propertyEncryptor.decrypt(encrypted); return propertyEncryptor.decrypt(encrypted);
} }