STATUS_ACCESS_DENIED (0xc0000022): Authentication failed when accessing AWS S3 SMB share with SMB_3_1_1 in Java SMB client - smbj

Getting authentication failed while trying to connect to the AWS S3 SMB path using SMB_3_1_1 of com.hierynomus.smbj client 0.11.5
Public.
Getting below error:
STATUS_ACCESS_DENIED (0xc0000022): Authentication failed for '[username]' using com.hierynomus.smbj.auth.NtlmAuthenticator#4b5189ac
SmbConfig cfg = SmbConfig.builder().withTimeout(120000, TimeUnit.SECONDS)
.withTimeout(120000, TimeUnit.SECONDS)
.withSoTimeout(180000, TimeUnit.SECONDS)
.withMultiProtocolNegotiate(true)
.withSecurityProvider(new JceSecurityProvider(new BouncyCastleProvider()))
.build();
try (SMBClient client = new SMBClient(cfg)){
**connection = client.connect(smbIP);
Session session = connection.authenticate(new AuthenticationContext(smbUserName, smbPassword.toCharArray(), smbDomain));** // from this line getting above exception
DiskShare share = (DiskShare) session.connectShare(smbSharePath);
if(!share.folderExists(destinationFolderName)) {
share.mkdir(destinationFolderName);
}
fileName = destinationFolderName+"\\"+fileName;
f = share.openFile(fileName,
new HashSet<>(Arrays.asList(AccessMask.GENERIC_ALL)),
new HashSet<>(Arrays.asList(FileAttributes.FILE_ATTRIBUTE_NORMAL)),
SMB2ShareAccess.ALL,
SMB2CreateDisposition.FILE_CREATE,
new HashSet<>(Arrays.asList(SMB2CreateOptions.FILE_DIRECTORY_FILE))
);
try(OutputStream os = f.getOutputStream()){
os.write(fileContent);
}catch (Exception e) {
}
}

Related

AWS MSK - Callout timeout exception

I have built a custom Kafka source connector for MSK and it works up to the point the callout happens. It throws a timeout error once it reaches that stage. I have configure the internet access using this tutorial https://docs.aws.amazon.com/msk/latest/developerguide/msk-connect-internet-access.html but it still fails. The custom config source works fine though with AWS Secrets. Below is a sample of the callout and the error I am hitting.
val url = URL("$sforceUrl/sforce/api/salesforce?orgId=$orgId")
val conn = url.openConnection() as HttpURLConnection
conn.setRequestProperty("Authorization", "Bearer $sforceAuthToken")
conn.setRequestProperty("Content-Type", "application/json")
conn.requestMethod = "GET"
val `in` = BufferedReader(InputStreamReader(conn.inputStream))
var output: String?
val response = StringBuilder()
while (`in`.readLine().also { output = it } != null) {
response.append(output)
}
`in`.close()
[Worker-0980ff7f2e26f67dc] java.lang.RuntimeException: java.lang.RuntimeException: java.net.ConnectException: Connection timed out (Connection timed out)

Migrating from WebSphere MQ to Active MQ

There was a similar question Procedure to migrate from IBM MQ to ActiveMQ and it was closed, but I will try anyway.
Our customers want to migrate from WebSphere MQ to Active MQ. In above mentioned question it was said that as for JMS such migration in theory will consist in apps re-configuration. Our customers say that their apps use auto-generated .bindings file. So, is it possible to make apps work with Active MQ just by editing .binding file and putting active mq's .jars to java classpath, or some other configuration is required?
To check this , i tried the following
a) Create a WMQ bindings file use JMSAdmin. Once i created a QCF and Queue i was able to send a message via a JMS lookup and send a message.
b) For the AMQ set up to generate a .bindings file , IBM had some sample code to generate the bindings file.
Once this was done i used exactly the same code to send a message and the message was perfectly sent to both AMQ and WMQ
Here is the sample code that i was able to interoperate.
public void sendMessages() {
ConnectionFactory connectionFactory;
Connection con = null;
Session session = null;
MessageProducer producer = null;
//create initial context properties
Properties initialContextProperties = new Properties();
initialContextProperties.put("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
initialContextProperties.put(Context.PROVIDER_URL, "file:/C:/JNDI-Directory/AMQ");
initialContextProperties.setProperty("transport.jms.security.authentication", "none");
try {
InitialContext initialContext = new InitialContext(initialContextProperties);
//create connection factory object
//ivtQCF - created connection factory object in IBM-MQ
connectionFactory = (ConnectionFactory) initialContext.lookup("confact2");
con = connectionFactory.createConnection();
con.start();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
//localq - created queue in IBM-MQ
Destination destination = (Destination) initialContext.lookup("dest");
producer = session.createProducer(destination);
String msg = "SAMPLE MESSAGE PLACED TO QUEUE";
TextMessage textMessage = session.createTextMessage(msg);
producer.send(textMessage);
con.close();
session.close();
producer.close();
} catch (NamingException e) {
throw new RuntimeException("Unable to send jms messages", e);
} catch (JMSException e) {
throw new RuntimeException("Unable to send jms messages", e);
}
}

Apache Http Client 4.5 Authentication Exception when Integrating to ServiceNow

Am trying to connect to my service-now instance using Apache Client 4.5 via a proxy server. Unfortunately the connection is failing with the below exception.
HTTP/1.1 401 Unauthorized
{"error":{"message":"User Not Authenticated","detail":"Required to provide Auth information"},"status":"failure"}
I can understand that this is because of authentication exception, but i did seem to have provide the credential as shown below.
Code Snippet :
public void getRequestWithProxy() throws ClientProtocolException, IOException
{
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope("proxy.xxxx.com", 0000),
new UsernamePasswordCredentials("proxyuser", "proxypassword"));
credsProvider.setCredentials(
new AuthScope("instance.service-now.com", 443),
new UsernamePasswordCredentials("username", "password"));
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider).build();
try {
HttpHost target = new HttpHost("instance.service-now.com", 443, "https");
HttpHost proxy = new HttpHost("proxy.xxxx.com", 0000);
RequestConfig config = RequestConfig.custom()
.setProxy(proxy)
.build();
HttpGet httpget = new HttpGet("/api/now/table/incident");
httpget.setConfig(config);
System.out.println("Executing request " + httpget.getRequestLine() + " to " + target + " via " + proxy);
CloseableHttpResponse response = httpclient.execute(target, httpget);
try {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
I assume that i have access to the URL am accessing, because the same URL "https://instance.service-now.com/api/now/table/incident" when tried in browser works fine using SSO (Single Sing On).
Please help me with what am missing.
Thanks in advance for your help in this.
Thank you.
You stated it was a URL. new AuthScope should be a hostname and not a URL.

Google BigQuery Service Account Credentials using JSON file in C# application

While Creating Service Account for Google BigQuery, There are two key file type. 1. P12 Key File 2. JSON Key File.
I can able to connect Google BigQuery with Service Account Credentials using P12 Key File by using following code.
String serviceAccountEmail = "XXXX#developer.gserviceaccount.com";
var certificate = new X509Certificate2(#"FileName.p12", "Secret Key", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { BigqueryService.Scope.Bigquery, BigqueryService.Scope.BigqueryInsertdata, BigqueryService.Scope.CloudPlatform, BigqueryService.Scope.DevstorageFullControl }
}.FromCertificate(certificate));
BigqueryService Service = new BigqueryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "PROJECT NAME"
});
Now i am trying to connect Service Account Credentials using JSON file type, but i could not get the proper syntax for creating.
How can we connect Google BigQuery with Service Account Credentials using JSON File?
Thanks,
I got the link, Which indicates Service Account Authentication using JSON file in C# application is not yet added in Google BigQuery API, So i would like to close the question.
https://github.com/google/google-api-dotnet-client/issues/533
It is now possible (I used v 1.13.1.0 of Google APIs).
GoogleCredential credential;
using (Stream stream = new FileStream(#"C:\mykey.json", FileMode.Open, FileAccess.Read, FileShare.Read))
{
credential = GoogleCredential.FromStream(stream);
}
string[] scopes = new string[] {
BigqueryService.Scope.Bigquery,
BigqueryService.Scope.CloudPlatform,
};
credential = credential.CreateScoped(scopes);
BaseClientService.Initializer initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = (IConfigurableHttpClientInitializer)credential,
ApplicationName = "My Application",
GZipEnabled = true,
};
BigqueryService service = new BigqueryService(initializer);

Cassia using impersonation and wcf

I am trying to use Cassia with a WCF web service I keep getting "An existing connection was forcibly closed by the remote host". When I try it on a test console application it works fine. This is the code I am using from a sample I found. Anyone ever do this?
public List<ITerminalServicesSession> getTermminalServerSessions(string serverName)
{
ConnectionDetails connection = new ConnectionDetails();
connection.Domain = "DOMAIN";
connection.Server = serverName;
connection.Username = "USER";
connection.Password = "PASSWORD";
using (ImpersonationHelper.Impersonate(connection))
{
using (var server = GetServer(connection.Server))
{
server.Open();
return server.GetSessions().ToList();
}
}
}