Exception when attempting to authenticate to AD using System.DirectoryServices.Protocols - c#

Want to share with the community a recent exception I encountered after our network folks enabled channel binding on our AD. The change was inspired by KB4520412
My initial code logic was as follows and worked flawlessly up until the recent change.
var cred = new NetworkCredential(credentials.UserId, credentials.Password);
var serverId = new LdapDirectoryIdentifier(host, port);
using var conn = new LdapConnection(serverId, cred);
conn.Bind();
After the change my code started receiving exceptions
"The supplied credential is invalid"
Inner Exception
"80090346: LdapErr: DSID-0C09059A, comment: AcceptSecurityContext error, data 80090346, v3839"
To remedy the exception I changed my code to the below.
using var conn = new LdapConnection(serverId, cred,AuthType.Basic);
conn.SessionOptions.ProtocolVersion = 3;
conn.SessionOptions.SecureSocketLayer = true;
conn.SessionOptions.FastConcurrentBind();
conn.Bind();

Remedied the exception by implementing a change to the session options as follows.
using var conn = new LdapConnection(serverId, cred,AuthType.Basic);
conn.SessionOptions.ProtocolVersion = 3;
conn.SessionOptions.SecureSocketLayer = true;
conn.SessionOptions.FastConcurrentBind();
conn.Bind();

Related

How can I connect to IBM MQ using SSL connection by C# IBMXMSDotnetClient

I am currently able to connect to the IBM MQ server based on jndi binding file with the following c# code
InitialContext ic = null;
IConnectionFactory confac = null;
IConnection conn = null;
ISession sess = null;
IMessageConsumer cons = null;
IDestination dest = null;
try
{
System.Collections.Hashtable env = new System.Collections.Hashtable();
// Set the URL or PATH where the bindings file is located
env[XMSC.IC_URL] = "file://c:/mqbindings/.bindings";
// Initialize the context
ic = new InitialContext(env);
// Lookup for the connection factory name
confac = (IConnectionFactory)ic.Lookup("myconfactoryname");
// Create connection using the details from connection factory
conn = (IConnection)confac.CreateConnection();
// Create an auto ack session
sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
// Lookup for the destination
dest = (IDestination)ic.Lookup("myqueue");
// ... rest of the code - create consumer or producer
}
catch (XMSException xmsE)
{
// Handle exception
}
However, when the SSL enabled in the IBM MQ Server, it fails to connect. Tried setting different properties (like setting XMSC.IC_PROVIDER_URL to the keystores directory/.jp12 file), but does not seem working.
Exception I got:
IBM.XMS.XMSException: 'CWSMQ0006E: An exception was received during the call to the method ConnectionFactory.CreateConnection: CompCode: 2, Reason: 2059.
I also cannot find any sample code on the official site on how this is working.
Any idea or sample code on this (not necessary in great details, at least, give me some ideas how what I need to set)?

VssConnection SP324098: Your browser could not complete the operation

I am using the following code to try and connect to Azure DevOps and to retrieve a list of work item types, however I keep getting this exception:
BrowserFlowException: SP324098: Your browser could not complete the
operation
There doesn't seem to be much information around this exception. Does anyone know what's going on here? I am using Visual Studio 2017, Enterprise Edition updated to latest build on a Windows 10 updated to latest build machine.
VssClientCredentials credentials = new VssClientCredentials();
VssClientHttpRequestSettings settings = new VssClientHttpRequestSettings
{
AllowAutoRedirect = true
};
VssHttpMessageHandler vssHandler = new VssHttpMessageHandler(credentials, settings);
using (VssConnection connection = new VssConnection(this.CollectionUri, credentials, settings))
{
connection.ConnectAsync().SyncResult();
// Create instance of WorkItemTrackingHttpClient using VssConnection
WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();
var workItemTypes = witClient.GetWorkItemTypesAsync(ProjectName).SyncResult(); ; //exception happens here, I see the login box here too
}

Connect Sap B1 hana with C# Application using DI API

I am Trying to Connect MY Sap B1 HANA on C# Web Based Application using DI API but my connection is giving me error. Here is Error Screenshot Failed to Connect SLD,make Sure Your SLD Server is Available and Connected. Any Relevant Help would be Appreciated.
try{
oCompany.CompanyDB = "***";
oCompany.Server = "***";
oCompany.LicenseServer = "***:30015";
oCompany.SLDServer = "***:40000"; //
oCompany.DbUserName = "****"; //
oCompany.DbPassword = "****"; //
oCompany.UserName = "****"; //
oCompany.Password = "****"; //
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
oCompany.UseTrusted = false;
int res = oCompany.Connect();
string errMsg = oCompany.GetLastErrorDescription();
int ErrNo = oCompany.GetLastErrorCode();
if (ErrNo != 0)
{
value1 = errMsg;
return errMsg;
}
else {
value1 = "Succes Connection To Sap B1 Hana";
return value1;
}
You must include the port number in the server. Usually, the port number is 30015.
you can also use below mention code.
SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
oCompany = (SAPbobsCOM.Company)Application.SBO_Application.Company.GetDICompany();
The following connection code should get you a step further:
// The actual database host
// With HANA the single-tenancy port 30015 needs to be provided together with the host (not so with MSSQL)
// When using HANA multi-tenancy the instance is prefixed and the port changed: INSTANCE#DB-HOST:30013
// OR the correct instance port needs to be provided, eg. DB-HOST:30017
sboCompany.Server = "DB-HOST:30015";
// The company database/schema name
// With MSSQL the instance is provided here like: INSTANCE\DB_NAME
sboCompany.CompanyDB = "SCHEMA";
// SLDServer is the new LicenseServer, don't forget the port with HANA
// Be aware: use either hostname or IP of SLD everywhere
sboCompany.SLDServer = "SLD-HOST:40000";
// Hell knows why the version needs to be provided for MSSQL...
sboCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
// DB credentials when using MSSQL authentication or HANA
sboCompany.UseTrusted = false;
sboCompany.DbUserName = "SYSTEM";
sboCompany.DbPassword = "password";
// SBO credentials
sboCompany.UserName = "manager";
sboCompany.Password = "password";
The next problems might be missing or wrong HANA drivers... your journey just began ;-)

Why i can't initialize quartz.net adoJobStore with oracle?

I'm trying to setup quartz.net AdoJobStore with oracle.
I have a valid schema with tables for quartz.
But every time i'm facing the same Exception "Could not Initialize DataSource: default" at the last line of this code.
NameValueCollection properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "TestScheduler";
properties["quartz.scheduler.instanceId"] = "instance_one";
properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
properties["quartz.jobStore.useProperties"] = "true";
properties["quartz.jobStore.dataSource"] = "default";
properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
properties["quartz.dataSource.default.connectionString"] = "Data Source=//192.168.0.221:1521/ESPDB;User Id=quartz;Password=quartz";
properties["quartz.dataSource.default.provider"] = "OracleODP-20";
//
ISchedulerFactory schedulerFactory = new StdSchedulerFactory(properties);
IScheduler scheduler = await schedulerFactory.GetScheduler();
Same exception i was faced when i'm trying to use config file.
I'm using version 3.0 of quartz.
Try to modify last property as follows
properties["quartz.dataSource.default.provider"] = "OracleODP";
It worked for me.
I think OracleODP-20 could be the old value of Oracle data provider for previous version of Quartz.net as you can read here.

How to issue SSH command

I am using C# with SSH.NET.
I want to issue a PWD command but could not find any documentation or help. I do not know how to use 'SshClient' class.
Update:
I also tried experimenting with SshClient class using the below code but it does nothing, neither any error nor any exception.
ConnectionInfo ConnNfo = new ConnectionInfo("FTPHost", 22, "FTPUser",
new AuthenticationMethod[]{
// Pasword based Authentication
new PasswordAuthenticationMethod("FTPUser","FTPPass")
}
);
using (var ssh = new SshClient(ConnNfo))
{
ssh.Connect();
if (ssh.IsConnected)
{
string comm = "pwd";
using (var cmd = ssh.CreateCommand(comm))
{
var returned = cmd.Execute();
var output = cmd.Result;
var err = cmd.Error;
var stat = cmd.ExitStatus;
}
}
ssh.Disconnect();
}
Nothing happens. Neither an error nor an exception. On Visual Studio console, i get the below output.
*SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #152199'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server:
'ChannelFailureMessage': 'SSH_MSG_CHANNEL_FAILURE : #0'.*
At ssh.RunCommand method call the program goes in some sleep state (or waits for around 1 minute). sshCommand.Result and sshCommand.Error variables are empty.
Here's a quick example - one way to do it.
string host = "myhost";
string user = "root";
string pwd = "#secret#!"; // Don't use hardcoded plain-text passwords if possible - for demonstration only.
using (PasswordAuthenticationMethod auth = new PasswordAuthenticationMethod(user, pwd))
{
ConnectionInfo connection = new ConnectionInfo(host, user, auth);
using (var ssh = new SshClient(connection))
{
ssh.Connect();
SshCommand sshCommand = ssh.RunCommand("pwd");
Console.WriteLine("Command execution result: {0}", sshCommand.Result);
}
}
Note that if you specify an invalid command (e.g. "pwdxxxx"), you won't get an exception, but an error that will be stored in the SshCommand.Error string.
Note also that this uses SSH PasswordAuthentication, which may not be enabled in your SSH config.
Try looking into the documentation of SSH.NET:
SSH.NET at CodePlex
Code sample for executing a command (recommended)
Help file.CHM

Categories

Resources