Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PDI-13846] REST step should have option to accept self-signed certs for HTTPS #9797

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@
documentationUrl = "mk-95pdia003/pdi-transformation-steps/rest-client-step", name = "Rest.name",
description = "Rest.description", categoryDescription = "Rest.category" )
public class RestMeta extends BaseStepMeta implements StepMetaInterface {

private static final String ATT_APPLICATION_TYPE = "applicationType";
private static final String ATT_HTTP_PASSWORD = "httpPassword";
private static final String ATT_METHOD = "method";
private static final String ATT_URL = "url";
private static final String ATT_URL_IN_FIELD = "urlInField";
private static final String ATT_DYNAMIC_METHOD = "dynamicMethod";
private static final String ATT_METHOD_FIELD_NAME = "methodFieldName";
private static final String ATT_URL_FIELD = "urlField";
private static final String ATT_BODY_FIELD = "bodyField";
private static final String ATT_HTTP_LOGIN = "httpLogin";
private static final String ATT_PROXY_HOST = "proxyHost";
private static final String ATT_PROXY_PORT = "proxyPort";
private static final String ATT_TRUST_STORE_PASSWORD = "trustStorePassword";
private static final String ATT_PREEMPTIVE = "preemptive";
private static final String ATT_TRUST_STORE_FILE = "trustStoreFile";
private static final String ATT_IGNORE_SSL = "ignoreSsl";

private static Class<?> PKG = RestMeta.class; // for i18n purposes, needed by Translator2!!

public static final String[] APPLICATION_TYPES = new String[] {
Expand All @@ -68,6 +86,7 @@ public class RestMeta extends BaseStepMeta implements StepMetaInterface {
public static final String APPLICATION_TYPE_SVG_XML = "SVG XML";
public static final String APPLICATION_TYPE_TEXT_XML = "TEXT XML";


private String applicationType;

public static final String[] HTTP_METHODS = new String[] { "GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "PATCH"};
Expand Down Expand Up @@ -351,10 +370,19 @@ public void setFieldName( String resultName ) {
this.fieldName = resultName;
}

/**
* Setter
*
* @param ignoreSsl
* ignoreSsl is used to say that all SSL certificates are trusted.
*/
public boolean isIgnoreSsl() {
return ignoreSsl;
}

/**
* @return Returns the ignoreSsl value.
*/
public void setIgnoreSsl(boolean ignoreSsl) {
this.ignoreSsl = ignoreSsl;
}
Expand Down Expand Up @@ -409,6 +437,7 @@ public void setDefault() {
this.dynamicMethod = false;
this.methodFieldName = null;
this.preemptive = false;
this.ignoreSsl = false;
this.trustStoreFile = null;
this.trustStorePassword = null;
this.applicationType = APPLICATION_TYPE_TEXT_PLAIN;
Expand Down Expand Up @@ -447,26 +476,27 @@ public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterf
@Override
public String getXML() {
StringBuilder retval = new StringBuilder();
retval.append( " " ).append( XMLHandler.addTagValue( "applicationType", applicationType ) );
retval.append( " " ).append( XMLHandler.addTagValue( "method", method ) );
retval.append( " " ).append( XMLHandler.addTagValue( "url", url ) );
retval.append( " " ).append( XMLHandler.addTagValue( "urlInField", urlInField ) );
retval.append( " " ).append( XMLHandler.addTagValue( "dynamicMethod", dynamicMethod ) );
retval.append( " " ).append( XMLHandler.addTagValue( "methodFieldName", methodFieldName ) );

retval.append( " " ).append( XMLHandler.addTagValue( "urlField", urlField ) );
retval.append( " " ).append( XMLHandler.addTagValue( "bodyField", bodyField ) );
retval.append( " " ).append( XMLHandler.addTagValue( "httpLogin", httpLogin ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_APPLICATION_TYPE, applicationType ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_METHOD, method ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_URL, url ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_URL_IN_FIELD, urlInField ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_DYNAMIC_METHOD, dynamicMethod ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_METHOD_FIELD_NAME, methodFieldName ) );

retval.append( " " ).append( XMLHandler.addTagValue( ATT_URL_FIELD, urlField ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_BODY_FIELD, bodyField ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_HTTP_LOGIN, httpLogin ) );
retval.append( " " ).append(
XMLHandler.addTagValue( "httpPassword", Encr.encryptPasswordIfNotUsingVariables( httpPassword ) ) );
XMLHandler.addTagValue( ATT_HTTP_PASSWORD, Encr.encryptPasswordIfNotUsingVariables( httpPassword ) ) );

retval.append( " " ).append( XMLHandler.addTagValue( "proxyHost", proxyHost ) );
retval.append( " " ).append( XMLHandler.addTagValue( "proxyPort", proxyPort ) );
retval.append( " " ).append( XMLHandler.addTagValue( "preemptive", preemptive ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_PROXY_HOST, proxyHost ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_PROXY_PORT, proxyPort ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_PREEMPTIVE, preemptive ) );

retval.append( " " ).append( XMLHandler.addTagValue( "trustStoreFile", trustStoreFile ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_TRUST_STORE_FILE, trustStoreFile ) );
retval.append( " " ).append( XMLHandler.addTagValue( ATT_IGNORE_SSL, ignoreSsl ) );
retval.append( " " ).append(
XMLHandler.addTagValue( "trustStorePassword", Encr.encryptPasswordIfNotUsingVariables( trustStorePassword ) ) );
XMLHandler.addTagValue( ATT_TRUST_STORE_PASSWORD, Encr.encryptPasswordIfNotUsingVariables( trustStorePassword ) ) );

retval.append( " <headers>" ).append( Const.CR );
for ( int i = 0, len = ( headerName != null ? headerName.length : 0 ); i < len; i++ ) {
Expand Down Expand Up @@ -507,25 +537,26 @@ public String getXML() {

private void readData( Node stepnode, List<? extends SharedObjectInterface> databases ) throws KettleXMLException {
try {
applicationType = XMLHandler.getTagValue( stepnode, "applicationType" );
method = XMLHandler.getTagValue( stepnode, "method" );
url = XMLHandler.getTagValue( stepnode, "url" );
urlInField = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "urlInField" ) );
methodFieldName = XMLHandler.getTagValue( stepnode, "methodFieldName" );

dynamicMethod = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "dynamicMethod" ) );
urlField = XMLHandler.getTagValue( stepnode, "urlField" );
bodyField = XMLHandler.getTagValue( stepnode, "bodyField" );
httpLogin = XMLHandler.getTagValue( stepnode, "httpLogin" );
httpPassword = Encr.decryptPasswordOptionallyEncrypted( XMLHandler.getTagValue( stepnode, "httpPassword" ) );

proxyHost = XMLHandler.getTagValue( stepnode, "proxyHost" );
proxyPort = XMLHandler.getTagValue( stepnode, "proxyPort" );
preemptive = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "preemptive" ) );

trustStoreFile = XMLHandler.getTagValue( stepnode, "trustStoreFile" );
applicationType = XMLHandler.getTagValue( stepnode, ATT_APPLICATION_TYPE );
method = XMLHandler.getTagValue( stepnode, ATT_METHOD );
url = XMLHandler.getTagValue( stepnode, ATT_URL );
urlInField = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, ATT_URL_IN_FIELD ) );
methodFieldName = XMLHandler.getTagValue( stepnode, ATT_METHOD_FIELD_NAME );

dynamicMethod = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, ATT_DYNAMIC_METHOD ) );
urlField = XMLHandler.getTagValue( stepnode, ATT_URL_FIELD );
bodyField = XMLHandler.getTagValue( stepnode, ATT_BODY_FIELD );
httpLogin = XMLHandler.getTagValue( stepnode, ATT_HTTP_LOGIN );
httpPassword = Encr.decryptPasswordOptionallyEncrypted( XMLHandler.getTagValue( stepnode, ATT_HTTP_PASSWORD ) );

proxyHost = XMLHandler.getTagValue( stepnode, ATT_PROXY_HOST );
proxyPort = XMLHandler.getTagValue( stepnode, ATT_PROXY_PORT );
preemptive = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, ATT_PREEMPTIVE ) );

ignoreSsl = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, ATT_IGNORE_SSL ) );
trustStoreFile = XMLHandler.getTagValue( stepnode, ATT_TRUST_STORE_FILE );
trustStorePassword =
Encr.decryptPasswordOptionallyEncrypted( XMLHandler.getTagValue( stepnode, "trustStorePassword" ) );
Encr.decryptPasswordOptionallyEncrypted( XMLHandler.getTagValue( stepnode, ATT_TRUST_STORE_PASSWORD ) );

Node headernode = XMLHandler.getSubNode( stepnode, "headers" );
int nrheaders = XMLHandler.countNodes( headernode, "header" );
Expand Down Expand Up @@ -563,27 +594,28 @@ private void readData( Node stepnode, List<? extends SharedObjectInterface> data
@Override
public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ) throws KettleException {
try {
applicationType = rep.getStepAttributeString( id_step, "applicationType" );
method = rep.getStepAttributeString( id_step, "method" );
url = rep.getStepAttributeString( id_step, "url" );
urlInField = rep.getStepAttributeBoolean( id_step, "urlInField" );

methodFieldName = rep.getStepAttributeString( id_step, "methodFieldName" );
dynamicMethod = rep.getStepAttributeBoolean( id_step, "dynamicMethod" );
urlField = rep.getStepAttributeString( id_step, "urlField" );
bodyField = rep.getStepAttributeString( id_step, "bodyField" );
httpLogin = rep.getStepAttributeString( id_step, "httpLogin" );
applicationType = rep.getStepAttributeString( id_step, ATT_APPLICATION_TYPE );
method = rep.getStepAttributeString( id_step, ATT_METHOD );
url = rep.getStepAttributeString( id_step, ATT_URL );
urlInField = rep.getStepAttributeBoolean( id_step, ATT_URL_IN_FIELD );

methodFieldName = rep.getStepAttributeString( id_step, ATT_METHOD_FIELD_NAME );
dynamicMethod = rep.getStepAttributeBoolean( id_step, ATT_DYNAMIC_METHOD );
urlField = rep.getStepAttributeString( id_step, ATT_URL_FIELD );
bodyField = rep.getStepAttributeString( id_step, ATT_BODY_FIELD );
httpLogin = rep.getStepAttributeString( id_step, ATT_HTTP_LOGIN );
httpPassword =
Encr.decryptPasswordOptionallyEncrypted( rep.getStepAttributeString( id_step, "httpPassword" ) );
Encr.decryptPasswordOptionallyEncrypted( rep.getStepAttributeString( id_step, ATT_HTTP_PASSWORD ) );

proxyHost = rep.getStepAttributeString( id_step, "proxyHost" );
proxyPort = rep.getStepAttributeString( id_step, "proxyPort" );
proxyHost = rep.getStepAttributeString( id_step, ATT_PROXY_HOST );
proxyPort = rep.getStepAttributeString( id_step, ATT_PROXY_PORT );

trustStoreFile = rep.getStepAttributeString( id_step, "trustStoreFile" );
ignoreSsl = "Y".equalsIgnoreCase( rep.getStepAttributeString( id_step, ATT_IGNORE_SSL) );
trustStoreFile = rep.getStepAttributeString( id_step, ATT_TRUST_STORE_FILE );
trustStorePassword =
Encr.decryptPasswordOptionallyEncrypted( rep.getStepAttributeString( id_step, "trustStorePassword" ) );
Encr.decryptPasswordOptionallyEncrypted( rep.getStepAttributeString( id_step, ATT_TRUST_STORE_PASSWORD ) );

preemptive = rep.getStepAttributeBoolean( id_step, "preemptive" );
preemptive = rep.getStepAttributeBoolean( id_step, ATT_PREEMPTIVE );
int nrheaders = rep.countNrStepAttributes( id_step, "header_field" );
int nrparams = rep.countNrStepAttributes( id_step, "parameter_field" );
int nrmatrixparams = rep.countNrStepAttributes( id_step, "matrix_parameter_field" );
Expand Down Expand Up @@ -615,27 +647,28 @@ public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, Lis
@Override
public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ) throws KettleException {
try {
rep.saveStepAttribute( id_transformation, id_step, "applicationType", applicationType );
rep.saveStepAttribute( id_transformation, id_step, "method", method );
rep.saveStepAttribute( id_transformation, id_step, "url", url );
rep.saveStepAttribute( id_transformation, id_step, "methodFieldName", methodFieldName );

rep.saveStepAttribute( id_transformation, id_step, "dynamicMethod", dynamicMethod );
rep.saveStepAttribute( id_transformation, id_step, "urlInField", urlInField );
rep.saveStepAttribute( id_transformation, id_step, "urlField", urlField );
rep.saveStepAttribute( id_transformation, id_step, "bodyField", bodyField );
rep.saveStepAttribute( id_transformation, id_step, "httpLogin", httpLogin );
rep.saveStepAttribute( id_transformation, id_step, "httpPassword", Encr
rep.saveStepAttribute( id_transformation, id_step, ATT_APPLICATION_TYPE, applicationType );
rep.saveStepAttribute( id_transformation, id_step, ATT_METHOD, method );
rep.saveStepAttribute( id_transformation, id_step, ATT_URL, url );
rep.saveStepAttribute( id_transformation, id_step, ATT_METHOD_FIELD_NAME, methodFieldName );

rep.saveStepAttribute( id_transformation, id_step, ATT_DYNAMIC_METHOD, dynamicMethod );
rep.saveStepAttribute( id_transformation, id_step, ATT_URL_IN_FIELD, urlInField );
rep.saveStepAttribute( id_transformation, id_step, ATT_URL_FIELD, urlField );
rep.saveStepAttribute( id_transformation, id_step, ATT_BODY_FIELD, bodyField );
rep.saveStepAttribute( id_transformation, id_step, ATT_HTTP_LOGIN, httpLogin );
rep.saveStepAttribute( id_transformation, id_step, ATT_HTTP_PASSWORD, Encr
.encryptPasswordIfNotUsingVariables( httpPassword ) );

rep.saveStepAttribute( id_transformation, id_step, "proxyHost", proxyHost );
rep.saveStepAttribute( id_transformation, id_step, "proxyPort", proxyPort );
rep.saveStepAttribute( id_transformation, id_step, ATT_PROXY_HOST, proxyHost );
rep.saveStepAttribute( id_transformation, id_step, ATT_PROXY_PORT, proxyPort );

rep.saveStepAttribute( id_transformation, id_step, "trustStoreFile", trustStoreFile );
rep.saveStepAttribute( id_transformation, id_step, "trustStorePassword", Encr
rep.saveStepAttribute( id_transformation, id_step, ATT_IGNORE_SSL, ignoreSsl );
rep.saveStepAttribute( id_transformation, id_step, ATT_TRUST_STORE_FILE, trustStoreFile );
rep.saveStepAttribute( id_transformation, id_step, ATT_TRUST_STORE_PASSWORD, Encr
.encryptPasswordIfNotUsingVariables( trustStorePassword ) );

rep.saveStepAttribute( id_transformation, id_step, "preemptive", preemptive );
rep.saveStepAttribute( id_transformation, id_step, ATT_PREEMPTIVE, preemptive );
for ( int i = 0; i < headerName.length; i++ ) {
rep.saveStepAttribute( id_transformation, id_step, i, "header_field", headerField[i] );
rep.saveStepAttribute( id_transformation, id_step, i, "header_name", headerName[i] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@
private FormData fdbTrustStoreFile;
private FormData fdlTrustStoreFile, fdTrustStoreFile;

private Label wlIgnoreSSL;

Check warning on line 182 in plugins/rest/core/src/main/java/org/pentaho/di/ui/trans/steps/rest/RestDialog.java

View check run for this annotation

HitachiVantaraSonarQube / Pentaho Data Integration Sonarqube Results

plugins/rest/core/src/main/java/org/pentaho/di/ui/trans/steps/rest/RestDialog.java#L182

Remove the "wlIgnoreSSL" field and declare it as a local variable in the relevant methods.
private FormData fdlIgnoreSSL;

Check warning on line 183 in plugins/rest/core/src/main/java/org/pentaho/di/ui/trans/steps/rest/RestDialog.java

View check run for this annotation

HitachiVantaraSonarQube / Pentaho Data Integration Sonarqube Results

plugins/rest/core/src/main/java/org/pentaho/di/ui/trans/steps/rest/RestDialog.java#L183

Remove the "fdlIgnoreSSL" field and declare it as a local variable in the relevant methods.
private Button wIgnoreSSL;
private FormData fdIgnoreSSL;

Check warning on line 185 in plugins/rest/core/src/main/java/org/pentaho/di/ui/trans/steps/rest/RestDialog.java

View check run for this annotation

HitachiVantaraSonarQube / Pentaho Data Integration Sonarqube Results

plugins/rest/core/src/main/java/org/pentaho/di/ui/trans/steps/rest/RestDialog.java#L185

Remove the "fdIgnoreSSL" field and declare it as a local variable in the relevant methods.


private boolean gotPreviousFields = false;

private Button wMatrixGet;
Expand Down Expand Up @@ -301,6 +307,7 @@
fdUrlInField.right = new FormAttachment( 100, 0 );
wUrlInField.setLayoutData( fdUrlInField );
wUrlInField.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
input.setChanged();
activeUrlInfield();
Expand Down Expand Up @@ -360,7 +367,7 @@
wMethod.setLayoutData( fdMethod );
wMethod.setItems( RestMeta.HTTP_METHODS );
wMethod.addSelectionListener( new SelectionAdapter() {

@Override
public void widgetSelected( SelectionEvent e ) {
setMethod();
}
Expand All @@ -383,6 +390,7 @@
fdMethodInField.right = new FormAttachment( 100, 0 );
wMethodInField.setLayoutData( fdMethodInField );
wMethodInField.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
input.setChanged();
activeMethodInfield();
Expand Down Expand Up @@ -474,7 +482,7 @@
wApplicationType.setLayoutData( fdApplicationType );
wApplicationType.setItems( RestMeta.APPLICATION_TYPES );
wApplicationType.addSelectionListener( new SelectionAdapter() {

@Override
public void widgetSelected( SelectionEvent e ) {
input.setChanged();
}
Expand Down Expand Up @@ -673,6 +681,7 @@
fdPreemptive.right = new FormAttachment( 100, 0 );
wPreemptive.setLayoutData( fdPreemptive );
wPreemptive.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
input.setChanged();
}
Expand Down Expand Up @@ -837,6 +846,29 @@
fdSSLTrustStore.top = new FormAttachment( gHttpAuth, margin );
gSSLTrustStore.setLayoutData( fdSSLTrustStore );

// Trust all certificate?
wlIgnoreSSL = new Label( gSSLTrustStore, SWT.RIGHT );
wlIgnoreSSL.setText( BaseMessages.getString( PKG, "RestDialog.IgnoreSSL.Label" ) );
props.setLook( wlIgnoreSSL );
fdlIgnoreSSL = new FormData();
fdlIgnoreSSL.left = new FormAttachment( 0, 0 );
fdlIgnoreSSL.top = new FormAttachment( wTrustStorePassword, margin );
fdlIgnoreSSL.right = new FormAttachment( middle, -margin );
wlIgnoreSSL.setLayoutData( fdlIgnoreSSL );
wIgnoreSSL = new Button( gSSLTrustStore, SWT.CHECK );
props.setLook( wIgnoreSSL );
wIgnoreSSL.setToolTipText( BaseMessages.getString( PKG, "RestDialog.IgnoreSSL.Tooltip" ) );
fdIgnoreSSL = new FormData();
fdIgnoreSSL.left = new FormAttachment( middle, 0 );
fdIgnoreSSL.top = new FormAttachment( wTrustStorePassword, margin );
wIgnoreSSL.setLayoutData( fdIgnoreSSL );
wIgnoreSSL.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( SelectionEvent e ) {
input.setChanged();
}
} );

// END HTTP AUTH GROUP
// ////////////////////////

Expand Down Expand Up @@ -1321,6 +1353,8 @@
if ( input.getTrustStorePassword() != null ) {
wTrustStorePassword.setText( input.getTrustStorePassword() );
}
wIgnoreSSL.setSelection(input.isIgnoreSsl());

if ( input.getResponseHeaderFieldName() != null ) {
wResponseHeader.setText( input.getResponseHeaderFieldName() );
}
Expand Down Expand Up @@ -1390,6 +1424,7 @@

input.setTrustStoreFile( wTrustStoreFile.getText() );
input.setTrustStorePassword( wTrustStorePassword.getText() );
input.setIgnoreSsl(wIgnoreSSL.getSelection());
input.setApplicationType( wApplicationType.getText() );
stepname = wStepname.getText(); // return value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ RestDialog.ProxyHost.Tooltip=Proxy Host
Rest.Exception.ErrorFindingField=Error finding field [{0}] in incoming stream\!
RestDialog.ColumnInfo.Name=Name
RestDialog.TrustStoreFile.Label=Trust store file
RestDialog.IgnoreSSL.Label=Trust all certificates
RestDialog.IgnoreSSL.Tooltip=When active, the REST Client will bypass SSL validation. This is not recommended but can be useful for testing scenarios
Rest.Log.ResponseTime=Response time (milliseconds)\: [{0}] for [{1}]
RestDialog.FailedToGetFields.DialogTitle=Error
RestMeta.CheckResult.UrlfieldMissing=URL field is missing\!
Expand Down
Loading