WebDAV library that supports Kerberos? - webdav

I want to programmatically read the files of a Kerberos-protected WebDAV server.
I tried adding Kerberos support to Sardine (Java), but it does not seem to work well.
Is there a WebDAV library that supports Kerberos? (any language, preferably open source)

The solution I found to work is using the Sardine method classes that extend HttpRequestBase with Apache HttpClient. You will need to use both the httpclient and httpclient-win
try {
CloseableHttpClient client = WinHttpClients.createDefault();
HttpMove move = new HttpMove(fullSource, fullDestination, false);
CloseableHttpResponse response = client.execute(move);
if (response.getStatusLine().getStatusCode() == 201){
System.out.println("Yay");
}
} catch (Exception e) {
e.printStackTrace();
}
throw new Exception("Unable to move node");
Here are the dependencies used (gradle form)
compile group: 'com.github.lookfirst', name: 'sardine', version:
'5.+'
compile group: 'org.apache.httpcomponents', name: 'httpclient',
version: '4.5.+'
compile group: 'org.apache.httpcomponents', name: 'httpclient-win',
version: '4.5.+'

The transport library need Kerberos support not your WebDAV lib. Try to fix that transport lib. Oracle's URLConnection does that.

Related

dotnet core TopShelf Windows Service fails to start

I have a dotnet core console application build to connect to a Sql Service Broker instance to monitor table changes.
The app monitors one table that is updated from an ERP system and then publishes messages to our bus.
It runs fine when running as a console application, or debugging in my IDE.
I am having an issue when using TopShelf to configure it as a windows service.
Here is the entry point:
private static void Main(string[] args)
{
RegisterComponents();
var serviceHost = HostFactory.Run(sc =>
{
sc.Service<ISalesOrderMonitorService>(s =>
{
var sqlListener = _container.ResolveNamed<SqlDependencyEx>(ListenerKey.SalesOrder);
var changeHandler = _container.Resolve<ISalesOrderChangeHandler>();
var listenerConfig = _container.ResolveNamed<ListenerConfiguration>(ListenerKey.SalesOrder);
var logger = _container.Resolve<ILogger<SalesOrder>>();
s.ConstructUsing(f =>
new SalesOrderMonitorService(sqlListener, changeHandler, listenerConfig, logger));
s.WhenStarted(tc => tc.Start());
s.WhenStopped(tc => tc.Stop());
});
});
var exitCode = (int) Convert.ChangeType(serviceHost, serviceHost.GetType());
Environment.ExitCode = exitCode;
}
The "worker" class:
public abstract class ServiceBase<T, TZ> : IService<T>
where T : IChangeHandler
{
protected readonly IChangeHandler ChangeHandler;
protected readonly SqlDependencyEx Listener;
protected readonly ListenerConfiguration ListenerConfiguration;
protected readonly ILogger<TZ> Logger;
protected ServiceBase(SqlDependencyEx listener, IChangeHandler changeHandler,
ListenerConfiguration listenerConfiguration, ILogger<TZ> logger)
{
Logger = logger;
ListenerConfiguration = listenerConfiguration;
Listener = listener;
ChangeHandler = changeHandler;
}
public virtual void Start()
{
try
{
Listener.TableChanged += (o, e) => ChangeHandler.Process(e);
Listener.Start();
Logger.LogDebug(
$"Listening to changes on the {ListenerConfiguration.Table} table in the {ListenerConfiguration.Database} database");
}
catch (Exception e)
{
Logger.LogError(e, e.Message);
throw;
}
}
public virtual void Stop()
{
Listener.Stop();
}
Install through TopShelf is no problem:
c:>{ServiceName}.exe install -username "serviceAccount" -password "superSecret" -servicename "ServiceName" -servicedescription "Description" -displayname "Service DisplayName" --autostart
When I go to start the service - I get this:
This is misleading because the event viewer shows this:
This is happening way faster than 30 seconds. This is definitely related to how I am configuring TopShelf.
As stated - the application works just fine when run "debug" or even as just an exe console.
I got it figured out. Actually both comments from #DotNetPadawan and #Lex Li indirectly got me there.
For starters - enabling the remote debugger clued me in that my appsetting.json was not being read into my IConfiguration. That was really confusing because everything works fine running locally with a debugger or even just starting the exe.
The link Lex Li points out did not provide the answer - however that article had this reference:
Host and Deploy aspnetcore as a Windows Service
It was here that I found this little nugget:
The current working directory returned by calling GetCurrentDirectory for a Windows Service is the C:\WINDOWS\system32 folder. The system32 folder isn't a suitable location to store a service's files (for example, settings files). Use one of the following approaches to maintain and access a service's assets and settings files.
The link explains how to conditionally set the current directory if the app is running as a service.
var isConsole = args.Contains("-mode:console");
if (!isConsole)
{
var pathToExe = Process.GetCurrentProcess().MainModule?.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
Directory.SetCurrentDirectory(pathToContentRoot);
}
Putting this out there for anyone else that runs into this problem.
Admittedly - netcore 3.0 is likely the better way to go - but I don't have the bandwidth to upgrade everything is this repo (lots of shared stuff) to 3.0. I needed to get this working.

System.MissingMethodException When Sending Email using MailKit In Xamarin.Forms

I am trying to use the MailKit library to send email in Xamarin.Forms. However, I am getting the following exception when execution hits the ConnectAsync() method:
System.MissingMethodException: string[] string.Split(char,System.StringSplitOptions) occurred
Has anyone encountered this before. I am unaware of any missing methods.
Following is my code in .net standard project:
using MailKit.Net.Smtp;
using MimeKit;
using MimeKit.Text;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
public async Task SendAsync(EmailMessage emailMessage)
{
try
{
var message = new MimeMessage();
message.To.Add(new MailboxAddress("Recipient", "xamapp#icloud.com"));
message.From.Add(new MailboxAddress("Sender", "xamapp.no.reply#gmail.com"));
message.Subject = "Test!!";
message.Body = new TextPart(TextFormat.Html)
{
Text = "Test message"
};
using (var emailClient = new SmtpClient())
{
await emailClient.ConnectAsync("smtp.gmail.com", 465, true);
emailClient.AuthenticationMechanisms.Remove("XOAUTH2");
await emailClient.AuthenticateAsync("username", "password");
await emailClient.SendAsync(message);
emailClient.Disconnect(true);
}
}
catch (SmtpCommandException ex)
{
Debug.WriteLine($"Error sending email: {ex.Message}");
Debug.WriteLine($"StatusCode: {ex.StatusCode}");
}
catch (SmtpProtocolException ex)
{
Debug.WriteLine($"Protocol error while sending email: {ex.Message}");
}
}
Sounds like your Xamarin.Forms project is pulling in mismatched .NET framework versions of libraries (probably the wrong MimeKit and/or MailKit framework versions).
Check to see which exact MimeKit and MailKit assemblies your build is pulling in from the nuget packages. In case you aren't familiar with how nugets work, each nuget can contain multiple copies of the library that is built for different frameworks.
For example, the MimeKit nuget has assemblies built for the following frameworks:
netstandard1.3
netstandard1.6
netstandard2.0
Xamarin.Android
Xamarin.iOS
net45
portable-net45+win8 (Profile7)
portable-net45+win8+wpa81 (Profile111)
And the MailKit nuget contains assemblies built for the following frameworks:
netstandard1.3
netstandard1.6
netstandard2.0
Xamarin.Android
Xamarin.iOS
net45
portable-net45+win81+wpa81 (Profile32)
Make sure that your project is pulling in the netstandard2.0 assemblies for both nugets and not a mix and match.

Building JVM for Scala 2_11

This is a question about the project https://github.com/DiUS/pact-jvm.
Problem
When I am validating pacts I need to be able to use client side authentication, as the providers actually require client side authentication. I'll prefix what I am saying with a declaration that I am not very familiar with groovy: I mostly program in scala, java or javascript. Having looked at the code I think that client side authentication is not currently supported, so I'd like to make a pull request with that support in it.
What I've done so far
I have managed to get Https working with a truststore: I copied the HttpTarget and created a HttpsTarget, and in the HttpsTarget specified the truststore in the providerinfo. Unfortunately looking at the code there doesn't seem to be a way of specifying the client certificate, so I need to change the providerinfo class to be able to specify where it is (in the same way the the truststore is provided).
My problem is that I've got the code compiling using the advice in the 'for contributors', but when I publish locally, I am only publishing for scala version 2_12. Because of version issues and binary incompatibilities between scala versions, I need to publish to scala 2_11. My skills with gradle are even less than my skills with groovy. I've done a search for all the references to scalaVersion, and found that there is quite a lot of logic around it, but I've not managed to track down where it is specified.
Question
If I can use client side authentication with the current pact validator could you let me know. If not, could you tell me how to publish the project with support for scala 2_11?
Thanks
In the end I made my own Http Target. My need is to run from Junit, not the general case, and this is good enough:
public class HttpsTarget extends HttpTarget {
public HttpsTarget(final int port) {
super("https", "localhost", port, "/", false);
}
static class HttpsClientFactory implements IHttpClientFactory {
#NotNull
#Override
public CloseableHttpClient newClient(Object o) {
SSLContext sslContext = // put here code to make ssl context
CloseableHttpClient httpClient = HttpClients
.custom()
.setSSLContext(sslContext)
.build();
return httpClient;
}
}
#Override
public void testInteraction(final String consumerName, final Interaction interaction, PactSource source) {
ProviderInfo provider = getProviderInfo(source);
ConsumerInfo consumer = new ConsumerInfo(consumerName);
ProviderVerifier verifier = setupVerifier(interaction, provider, consumer);
Map<String, Object> failures = new HashMap<>();
ProviderClient client = new ProviderClient(provider, new HttpsClientFactory());
verifier.verifyResponseFromProvider(provider, interaction, interaction.getDescription(), failures, client);
reportTestResult(failures.isEmpty(), verifier);
try {
if (!failures.isEmpty()) {
verifier.displayFailures(failures);
throw getAssertionError(failures);
}
} finally {
verifier.finialiseReports();
}
}
}

Not Able to get Alfresco 4.2 repository session in Java CMIS

I want to get session for Alfresco 4.2.1 Repository. But i am not getting below Exception
Exception in thread "main" org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException: Cannot access "https://test.uk.corplan.net/alfresco/api/-default-/public/cmis/versions/1.1/atom": handshake alert: unrecognized_name
at org.apache.chemistry.opencmis.client.bindings.spi.http.DefaultHttpInvoker.invoke(DefaultHttpInvoker.java:228)
at org.apache.chemistry.opencmis.client.bindings.spi.http.DefaultHttpInvoker.invokeGET(DefaultHttpInvoker.java:55)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.read(AbstractAtomPubService.java:615)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.getRepositoriesInternal(AbstractAtomPubService.java:782)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.RepositoryServiceImpl.getRepositoryInfos(RepositoryServiceImpl.java:65)
at org.apache.chemistry.opencmis.client.bindings.impl.RepositoryServiceImpl.getRepositoryInfos(RepositoryServiceImpl.java:88)
at org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.getRepositories(SessionFactoryImpl.java:133)
at org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.getRepositories(SessionFactoryImpl.java:111)
at com.rave.utils.GetAlfrescoSession.getalfrescosession(GetAlfrescoSession.java:42)
at com.rave.utils.GetAlfrescoSession.main(GetAlfrescoSession.java:18)Caused by: javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name
at sun.security.ssl.ClientHandshaker.handshakeAlert(Unknown Source)
at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
at org.apache.chemistry.opencmis.client.bindings.spi.http.DefaultHttpInvoker.invoke(DefaultHttpInvoker.java:203)
I have written below code to get the session. but i am not getting whats wrong here.
import java.util.HashMap;
import java.util.Map;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
public class GetAlfrescoSession {
public static void main(String[] args) {
getalfrescosession();
}
public static Session getalfrescosession() {
Map<String, String> parameter = new HashMap<String, String>();
parameter.put(SessionParameter.USER, "admin");
parameter.put(SessionParameter.PASSWORD, "admin");
parameter.put(SessionParameter.ATOMPUB_URL,
"https://test.uk.corplan.net/alfresco/api/-default-/public/cmis/versions/1.1/atom");
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
SessionFactory factory = SessionFactoryImpl.newInstance();
Session session = factory.getRepositories(parameter).get(0).createSession();
return session;
}
}
Can anyone please help me?
Thanks in Advance...
I believe that the URL that you use is compatible only with Alfresco 5.x. If you use Alfresco 4.2.x, you need to use an other URL. Just open the page:
http://<your alfresco>/alfresco/s/cmis/index
And you should get all details related to your instance. The URL of the CMIS repo should be:
http://<your alfresco>/alfresco/cmisatom
This has nothing to do with Alfresco or OpenCMIS. SSL is no set up correctly on the server.
See this answer:
SSL handshake alert: unrecognized_name error since upgrade to Java 1.7.0
I just installed the latest Alfresco 4.2.x and I checked the URL:
http://127.0.0.1:8080/alfresco/s/cmis/index
Then, I clicked on the link highlighted in the screenshot called AtomPub Service Document and the URL of the CMIS service is:
http://127.0.0.1:8080/alfresco/cmisatom
Be aware that Alfresco 4.2 supports only CMIS 1.0 and not CMIS 1.1.
I've run into this issue before on version 5.1 and what fixed it for me was the following setup:
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();
// user credentials
parameters.put(SessionParameter.USER, "username");
parameters.put(SessionParameter.PASSWORD, "password");
// connection settings
parameters.put(SessionParameter.ATOMPUB_URL, "https://someurl.com/alfresco/cmisatom");
parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameters.put(SessionParameter.REPOSITORY_ID, "IMPORTANT! the repository id must be defined here");
// create session
Session session = factory.createSession(parameters);
If you're using version 4.2 you need to verify that you connection endpoints and the version of CMIS you're using are are compatible.

I need some help on SFTP file transfer using loadrunner 11

There is a project that will involve sftp file transfers to a server. I have tried using ftp protocol and chose winscp.exe - sftp as my program to record. There were events being recorded however there is nothing generated after I finished recording.
If ftp protocol is not the answer to sftp file transfers can anybody give me some insight or tips on how I can do loadtests using LR on sftp file transfers?
I am using Loadrunner 11 for this.
Thanks in advance.
LoadRunner FTP Protocol doesn't support SFTP. It only supports FTP and FTPS (FTP over SSL). You could try to load-test an SFTP server using PuTTY' psftp tool or similar console client and C funcions like popen/write/read, which are available in any LoadRunner C script regardless of protocol. You might use CVuser Protocol to write such script.
Check this old but still somewhat useful forum discussion for further information.
Not everything can be recorded. Some have to be programmed. Seek an API solution for sftp which runs in C, VB, JavaScript or Java, all of which may be implemented in LoadRunner
You can do sftp using Java vuser protocol. You need to write java code to transfer files. The following code snippet might be helpful.
import lrapi.lr;
import com.jcraft.jsch.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Actions
{
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession("userId", "HOST",PORT);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword("Password");
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
sftpChannel.cd("Directory to upload files");
System.out.println("Connection Established");
File file = new File("Local folder to upload files");
sftpChannel.put(new FileInputStream(file),file.getName());
sftpChannel.exit();
session.disconnect();
}
catch (JSchException e)
{
e.printStackTrace();
}
return 0;
}
public int end() throws Throwable {
return 0;
}//end of end
}

Resources