jCIFS can´t authenticate on Mac server - java

I´ve set up a samba server on a Mac with OS X El Capitan.
Then, configured my java project to access this server using jCifs library but I get this error:
jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password
My code is:
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain","username","password");
String path = "smb://ip/filepath";
SmbFile file = new SmbFile(path, auth);
The username I used is the owner of the account in which I set up the server in the Mac and the password is correct.
I tried to access from another Mac and from an android device, both in the same network. I Also tried creating another user account in the server, with no luck.
In google, most of the cases belong to other OS. Besides that, my configuration seems fine.
Any idea? Thanks in advance.

After a deeper research, I found a post in which is told that the smb protocol implementation seems to be broken in OS X (link here: http://www.tweaking4all.com/os-tips-and-tricks/macosx-tips-and-tricks/smbup-mac-os-x-smb-fix/).
The server was set up using the configuration tool provided by the operating system so I tried to reconfigure the server with the same settings than before using other tool (SMBUp) and now I can connect without any problem without having changed the code.

Related

Java Access Network Domain Shared Folder with username and password

I am trying to access a network path to list directory file names, and I should give domain name, username and password to authenticate.
I have tried jcifs library but it's too old and NtlmPasswordAuthentication is deprecated. and it still works with smb version 1. and I have to connect to Windows server.
I found another library that would support the smb version 2.0 and 3.0. and another solution is to run an ftp server and use ftp protocol instead of smb.
the link below would explain everything about the new library :
Accessing SMB2.1 or SMB3 share from Java?

How to connect opc kepware server through a Java program, without the username and the password?

I am trying to connect opc kepware server through a Java program, I want to know what jar files can be used to connect to KepwareserverEx.V5 and what is the code without the use of password and username.
I have referenced http://www.opcconnect.com/uakit.php, and https://github.com/digitalpetri/ua-server-sdk, but it doesn't have anything that doesn't connect without a username and a pawssword. I have a program in vb that connects to kepware using Interop.OPCAutomation.dll file and uses the code:
ConnectedOPCServer = New OPCAutomation.OPCServer
ConnectedOPCServer.Connect("Kepware.KEPServerEX.V5", "")
ConnectedGroup = ConnectedOPCServer.OPCGroups.Add("MPM Group")
ConnectedGroup.UpdateRate = 1000
ConnectedGroup.IsSubscribed = True
ConnectedGroup.IsActive = True
I want to write Java code in a similar way. Searched through the internet to see various examples, but none have the above connection without a username and password not being specified.
First of all, I assume that you have created an "anonymous" and "SecurityPolicy.None" endpoint on KepServerEX.
You refer to digitalpetri's old and server SDK. The new project is called "Milo". I can recommend you take a look at the Milo project's client SDK examples using this link. There is an application of anonymous identity and none security policy.
In terms of jar, you can either build your client-sdk (see example here) or directly download the client-sdk jar from Maven Central.
NB Milo is considered to be in incubation. That is to say, it is not mature yet. Be careful using it in production systems.
Yes that's right. The security policy is none on the KepwareServerEX. I made some permission changes on the server where Kepware exists, so that my localhost computer would be able to talk to the Kepware server host. Provided credentials for my localhost, and able to connect.

Read/write a file with credentials [duplicate]

I have a server where I work with a database and files using a java app.
When I start my app I give a report regarding file access to the server using:
public static boolean folderExists(String folderPath) {
File folderToCheck = new File(folderPath);
return folderToCheck.exists();
}
Every time I start my app (after a fresh restart of my computer)
I get a false response, even though the server is on.
The reason is because I must give an authentication as another user.
What I do is access the server through Windows
where I am being asked for username/password,
and after that I get a true response regarding file access to the server.
Is there a way to give the authentication username/password through Java,
and not through Windows?
Thank you
On Windows 'native' Java IO (e.g. java.io.File) always inherits the security context of the user running the JVM process. For example, you could run the Java app as a Windows service with the correct credentials.
The JCIFS project implements CIFS (the Windows SMB file server protocol) and allows you to directly specify the username/password.
See the API for examples.
I am pretty sure, that there is no way to grant fileaccess by java, without a Windows-Call.
You can call cacls file.log /e /t /p Everyone:f but this will be language-dependent.
I had a similar problem: How to change the file ACL in windows, if I only know the SID?
With Java7 there may be a way to do this.

Reading remote Ubuntu directory using ssh in java?

I want to read the content of a remote directory using java.
The directory is on a machine running Ubuntu. Right clicking on the folder should give the share folder option and its installed samba client for windows sharing, but I don't have any machine running Windows.
I'm looking for a java api library to access the remote directory content?
User will only provide username, password, ip and folder name.
eg [//172.17.0.1/sharefolder/demo/]
Thanks.
For a Samba Share:
Even SAMBA shares in linux use the same protocol as windows shares.
So the post here can help: How can I mount a windows drive in Java?
Basically, you could mount the shared location as a network drive using "net use" command .
You could call this either through windows console, or through a java Process.
For a SFTP location:
If you don't have a problem with calling/using an external command you could use sshfs (either out of java or through Process) to mount the remote directory into a local folder.
See: http://numberformat.wordpress.com/2010/03/01/how-to-mount-a-remote-ssh-filesystem-using-sshfs/
If you want pure java on how to access SFTP,I read that a library called JSch can be used to access SFTP directly from java. See:
http://chrisjordan.ca/post/15052396308/java-sftp
http://jcraft.com/jsch/examples/Sftp.java.html
If it's another type please specify
You might find the The Java CIFS Client Library having the API you need - it is useful for both server and client.
Here is an example taken from their documentation to retrieve a file:
import jcifs.smb.*;
jcifs.Config.setProperty( "jcifs.netbios.wins", "192.168.1.220" );
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain", "username", "password");
SmbFileInputStream in = new SmbFileInputStream("smb://host/c/My Documents/somefile.txt", auth);
byte[] b = new byte[8192];
int n;
while(( n = in.read( b )) > 0 ) {
System.out.write( b, 0, n );
}
For SFTP consider using JSCAPE's Secure FTP Factory. Documentation with code examples can be found here.
jsch-nio is a fully functional unix/linux java FileSystemProvider over ssh.

Java - Access file with user authentication

I have a server where I work with a database and files using a java app.
When I start my app I give a report regarding file access to the server using:
public static boolean folderExists(String folderPath) {
File folderToCheck = new File(folderPath);
return folderToCheck.exists();
}
Every time I start my app (after a fresh restart of my computer)
I get a false response, even though the server is on.
The reason is because I must give an authentication as another user.
What I do is access the server through Windows
where I am being asked for username/password,
and after that I get a true response regarding file access to the server.
Is there a way to give the authentication username/password through Java,
and not through Windows?
Thank you
On Windows 'native' Java IO (e.g. java.io.File) always inherits the security context of the user running the JVM process. For example, you could run the Java app as a Windows service with the correct credentials.
The JCIFS project implements CIFS (the Windows SMB file server protocol) and allows you to directly specify the username/password.
See the API for examples.
I am pretty sure, that there is no way to grant fileaccess by java, without a Windows-Call.
You can call cacls file.log /e /t /p Everyone:f but this will be language-dependent.
I had a similar problem: How to change the file ACL in windows, if I only know the SID?
With Java7 there may be a way to do this.

Categories

Resources