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

Adds ignoreSslErrors to the WebApiConnector class #300

Merged
merged 1 commit into from
Apr 10, 2024
Merged
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 @@ -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
Loading