Java Access Network Domain Shared Folder with username and password - java

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?

Related

Access secondary hard drive from IP in Java application in Apache Tomcat 8.0

I have a Java web application that has to access a file in a hard drive different than the one the application is installed in.
I have the address configured in my Web.xml, this data is accessed from the Java code.
<param-value>//USERNAME:PASSWORD#IP_ADDRESS/HARD_DRIVE_LETTER/FOLDER_NAME/</param-value>
USERNAME: User of the computer I want to access to
PASSWORD: Password of the mentioned user
IP_ADDRESS: Internet Protocol v4 Address of the Computer
HARD_DRIVE_LETTER: I want to access to J: hard drive
FOLDER_NAME: Name of the folder I want to access
I have tried this way with no result:
<param-value>//USERNAME:PASSWORD#127.0.0.1/J:/Documents/</param-value>
I have been able to use this URL locally because my test computer had only one Hard Drive:
<param-value>//USERNAME:PASSWORD#127.0.0.1/Documents/</param-value>
So I could access the files in C:\Documents with this method with no problem.
Now, I had to export my application to a different computer, so I had to install Apache Tomcat 8.0 (Version 8.0.30) in that computer, in Hard Drive I:
And the data that my application has to access is stored in Hard Drive J:
How can I properly entry the right URL to access the data from my application?
I managed to solve my own problem.
The issue was that I was not writing properly the name of the hard drive I wanted to access.
To know the real name (or shared name) of a resource, I had to search here:
Right click on Windows logo or Start button
Choose "Manage Equipment"
System Tools > Shared Folders > Shared Resources
Here you can see the promer "Resource Name" with its "Folder Access Route"
So, to access drive J:, I had to type the IP address of the computer + "/" + "J$"
<param-value>//USERNAME:PASSWORD#IP_ADDRESS/J$/FOLDER_NAME/</param-value>
In my code, I used SMBFile to access the file, so I had to create a String adding "smb:" to the beginning of that parameter:
String fileAddress = "smb:" + fileLocationParam;
Where I obtained "fileLocationParam" from the Web.xml
This way, I was able to access the file using SMBFile

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.

How to authenticate to sql server as Windows User from java application? [duplicate]

I am currently investigating how to make a connection to a SQL Server database from my Java EE web application using Windows Authentication instead of SQL Server authentication. I am running this app off of Tomcat 6.0, and am utilizing the Microsoft JDBC driver. My connection properties file looks as follows:
dbDriver = com.microsoft.sqlserver.jdbc.SQLServerDriver
dbUser = user
dbPass = password
dbServer = localhost:1433;databaseName=testDb
dbUrl = jdbc:sqlserver://localhost:1433
I have zero problems with connecting to a SQL Server database in this fashion when using SQL Server authentication.
Is there any way I can retrieve the credentials of the user's Windows Authentication and use that authentication for SQL Server?
UPDATE: I know in ASP.net there is a way to set up Windows Authentication for access to the webapp, which is exactly what I am looking for, except I want to pass that token off to SQL Server for access to the database.
I do not think one can push the user credentials from the browser to the database (and does it makes sense ? I think not)
But if you want to use the credentials of the user running Tomcat to connect to SQL Server then you can use Microsoft's JDBC Driver.
Just build your JDBC URL like this:
jdbc:sqlserver://localhost;integratedSecurity=true;
And copy the appropriate DLL to Tomcat's bin directory (sqljdbc_auth.dll provided with the driver)
MSDN > Connecting to SQL Server with the JDBC Driver > Building the Connection URL
look at
http://jtds.sourceforge.net/faq.html#driverImplementation
What is the URL format used by jTDS?
The URL format for jTDS is:
jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;...]]
...
domain
Specifies the Windows domain to authenticate in. If present and the user name and password are provided, jTDS uses Windows (NTLM) authentication instead of the usual SQL Server authentication (i.e. the user and password provided are the domain user and password). This allows non-Windows clients to log in to servers which are only configured to accept Windows authentication.
If the domain parameter is present but no user name and password are provided, jTDS uses its native Single-Sign-On library and logs in with the logged Windows user's credentials (for this to work one would obviously need to be on Windows, logged into a domain, and also have the SSO library installed -- consult README.SSO in the distribution on how to do this).
This actually works for me:
Per the README.SSO that comes with the jtdsd distribution:
In order for Single Sign On to work, jTDS must be able to load the native SPPI library ntlmauth.dll. Place this DLL anywhere in the system path (defined by the PATH system variable) and you're all set.
I placed it in my jre/bin folder
I configured a port dedicated the sql server instance (2302) to alleviate the need for an instance name - just something I do. lportal is my database name.
jdbc.default.url=jdbc:jtds:sqlserver://192.168.0.147:2302/lportal;useNTLMv2=true;domain=mydomain.local
Unless you have some really compelling reason not to, I suggest ditching the MS JDBC driver.
Instead, use the jtds jdbc driver. Read the README.SSO file in the jtds distribution on how to configure for single-sign-on (native authentication) and where to put the native DLL to ensure it can be loaded by the JVM.
I was having issue with connecting to MS SQL 2005 using Windows Authentication. I was able to solve the issue with help from this and other forums. Here is what I did:
Install the JTDS driver
Do not use the "domain= " property in the jdbc:jtds:://[:][/][;=[;...]] string
Install the ntlmauth.dll in c:\windows\system32 directory (registration of the dll was not required) on the web server machine.
Change the logon identity for the Apache Tomcat service to a domain User with access to the SQL database server (it was not necessary for the user to have access to the dbo.master).
My environment:
Windows XP clinet hosting Apache Tomcat 6 with MS SQL 2005 backend on Windows 2003

jCIFS can´t authenticate on Mac server

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.

Running web application on local host

I wrote a web-application which is using java library SOCIAL AUTH for oauth .
For this i need to generate a secret with oauth provider like google,twitter .
while generating the key i gave the location of site eg: www.xyz.com .
Now these oauth provider are retuning their response at the location www.xyz.com
But i want to test my application on localhost wheather is going fine or not.So while runnning on localhost oauth provider is coming as null .
IS there any way by which i can use do by which i can say my tomcat to take the properties or response from www.xyz.com .So that it ll be able to read the response coming from oauth provider
One trick for these types of situations is to temporarily change your /etc/hosts file (if you're on Linux or Mac) so that www.xyz.com points to your localhost. That is, put the following line in the file:
127.0.0.1 www.xyz.com
Then, when the remote site redirects you back to www.xyz.com, that will resolve to localhost. You just have to remember to comment out this line in /etc/hosts whenever you want to access the real production system.
(You can do the same thing on Windows, but I can't remember where the equivalent of /etc/hosts is on Windows, and I don't have access to a Windows box right now.)

Categories

Resources