Solved

java file open with user credentials

Posted on 2008-10-07
2
1,633 Views
Last Modified: 2013-11-23
Is there a way to open a remote file using java by passing in user credentials.My java application is a windows service  and is not able to recoginze mapped drives , so I am using UNC paths, but now if my service login credentials are different than the remote machine where my file is, I cannot access it due to login failure.So i was wonderign if there is a way to open a remote file by checking the credentials of the  remote machine.
Thanks
0
Comment
Question by:res_this
2 Comments
 
LVL 9

Accepted Solution

by:
brunoguimaraes earned 500 total points
Comment Utility
You can use jCifs: http://jcifs.samba.org/src/

The "official" version works only with NTLM authentication (windows 2000, NT, 98). But there is also a Kerberos version (windows 2003, xp, vista) that you can download in the same page.

There are several examples there too.

Here's an example using NTLM authentication (the only one I have worked with):


// to authenticate

InetAddress lInetAddress = InetAddress.getByName("ip address of the computer you're acessing"));

UniAddress lUniAddress = new UniAddress(lInetAddress);

NtlmPasswordAuthentication lNtlmPasswordAuthentication = new NtlmPasswordAuthentication("DOMAIN", "USERNAME", "PASSWORD");

SmbSession.logon(lUniAddress, lNtlmPasswordAuthentication);
 

// to open a file

SmbFile lSmbFile = new SmbFile("smb://path_to_file", lNtlmPasswordAuthentication);

Open in new window

0
 

Author Closing Comment

by:res_this
Comment Utility
Thanks, that was a great answer
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now