Skip to content

Commit

Permalink
The most significant changes involve the addition of a new parameter …
Browse files Browse the repository at this point in the history
…`ignoreSslErrors` to the `WebApiConnector` class, `CreateWebApi` method, and `WebApiConnectorFactory` class. This parameter allows the user to choose whether to ignore SSL errors or not. (#300)

1. The `WebApiConnector` class in `WebApiConnector.cs` has been updated to include a new parameter `ignoreSSLErros` in its constructor. This parameter is a boolean that, when set to true, will ignore SSL errors. If `ignoreSSLErros` is set to true, a lambda function is set to the `CertificateCallback` of `ServerCertificateCallback` that always returns true, effectively ignoring any SSL errors.

2. The `CreateWebApi` method in `WebApiConnectorExtensions.cs` has been updated to include a new parameter `ignoreSslErrors` with a default value of false. The `Parameters` property of the `ConnectorAdapter` object returned by the method has been updated to include `ignoreSslErrors`.

3. The `WebApiConnectorFactory` class in `WebApiConnectorFactory.cs` has been updated to handle the new `ignoreSslErrors` parameter. The `WebApiConnector` object returned by the `Create` method now includes `ignoreSslErrors` as a parameter.
  • Loading branch information
PTKu authored Apr 10, 2024
1 parent 941c108 commit 43b428a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public class WebApiConnector : Connector
/// <param name="userName">User name.</param>
/// <param name="password">Password.</param>
/// <param name="customServerCertHandler">Customized server certificate handler.</param>
/// <param name="ignoreSSLErros">When set to true ssl error are ignored.</param>
/// <param name="dbName">Root DB name (AX uses 'TGlobalVariablesDB')</param>
public WebApiConnector(string ipAddress, string userName, string password,
Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool>? customServerCertHandler,
bool ignoreSSLErros,
eTargetProjectPlatform platform = eTargetProjectPlatform.SIMATICAX,
string dbName = "\"TGlobalVariablesDB\"")
{
Expand All @@ -62,6 +64,10 @@ public WebApiConnector(string ipAddress, string userName, string password,
UserName = userName;
UserPassword = password;

if (ignoreSSLErros)
ServerCertificateCallback.CertificateCallback =
(sender, cert, chain, sslPolicyErrors) => true;

var serviceFactory = new ApiStandardServiceFactory();
var client = serviceFactory.GetHttpClient(ipAddress, UserName, UserPassword);
requestHandler = new ApiHttpClientRequestHandler(client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ public static ConnectorAdapter CreateWebApi(this ConnectorAdapterBuilder adapter
/// <param name="userName">User name.</param>
/// <param name="password">Password.</param>
/// <param name="customServerCertHandler">Customized server certificate handler.</param>
/// <param name="ignoreSslErrors">When set to true ssl errors are ignored</param>
/// <param name="dbName">Name of default DB. The DB used to store all data in an AX project is 'TGlobalVariablesDB'.</param>
/// <returns>Connector adapter for WebAPI connection.</returns>
public static ConnectorAdapter CreateWebApi(this ConnectorAdapterBuilder adapter,
string ipAddress, string userName, string password,
Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool>? customServerCertHandler,
bool ignoreSslErrors = false,
eTargetProjectPlatform platform = eTargetProjectPlatform.SIMATICAX,
string dbName = "\"TGlobalVariablesDB\"")
{
return new ConnectorAdapter(typeof(WebApiConnectorFactory))
{ Parameters = new object[] { ipAddress, userName, password, customServerCertHandler, platform, dbName } };
{ Parameters = new object[] { ipAddress, userName, password, customServerCertHandler, ignoreSslErrors, platform, dbName } };
}

public static DateOnly AdjustForLeapDate(this long value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public override Connector CreateConnector(object[] parameters)
(string)parameters[1],
(string)parameters[2],
(Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool>)parameters[3],
(eTargetProjectPlatform)parameters[4],
(string)parameters[5]);
(bool)parameters[4],
(eTargetProjectPlatform)parameters[5],
(string)parameters[6]);
}
}

Expand Down

0 comments on commit 43b428a

Please sign in to comment.