Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

Tomcat 5.5.15 running as a service or manually started... and trying to read a File

Thread view: 
ccjjharmon@gmail.com - 24 Mar 2006 21:20 GMT
In a java bean, I am attempting to read a File object, which is a
mapped drive (X:\\) on a Windows 2003 Server. What I am trying to do is
read a file from this mapped drive.

Running Tomcat 5.5.15, with JRE 1.5.0_06.

When I have Tomcat started as a Windows service, the .canRead() method
returns false.

When I have Tomcat started manually (command-line), the .canRead()
method returns true. When I start it, I am logged into the server via
Remote Desktop as my network account login.

The mapped drive is setup under my login, and my login has read+write
privileges on this share.

Initially I figured this would occur when the Tomcat service is left
alone to "run-as" Local System, but even when I changed it to run as my
network account login, this still occurs.

I can't figure it out. Any ideas?

Code snippet:

    String dir = "X:\\";
    File theDir = new File(dir);
    if (!theDir.canRead()) throw new Exception("cannot read from the
share");

Thanks in advance!

Chris Harmon
ccjjharmon@gmail.com - 24 Mar 2006 21:28 GMT
I just checked to see if I have it read from a local drive's folder,
and change the security on this folder what will happen. Here is the
results (only tested on the problem scenario of running as a service):

When service is running as local system, canRead() returns true when it
has system account with read privileges. When system account does not
have read privileges, canRead() returns false.

When service is running as my network account, canRead() returns true
when my network account has read privileges. When it does not have read
privileges, canRead() returns false.

End result: it worked as I expected. But apparently this issue only
appears when dealing with mapped drives???

If this is the case, what is the recommended procedure for reading
Files from remote file servers? Assuming there is no per-se server
(like an FTP server or WWW server) on this remote file server....

Chris Harmon
Juha Laiho - 26 Mar 2006 07:31 GMT
ccjjharmon@gmail.com said:
>In a java bean, I am attempting to read a File object, which is a
>mapped drive (X:\\) on a Windows 2003 Server. What I am trying to do is
>read a file from this mapped drive.
[...]
>When I have Tomcat started as a Windows service, the .canRead() method
>returns false.
>
>When I have Tomcat started manually (command-line), the .canRead()
>method returns true. When I start it, I am logged into the server via
>Remote Desktop as my network account login.

Hmm.. just a thought (and I'm not too familiar with Windows), it
might well be that the drive mappings are only done when you do an
interactive login - so, when you're just running a service, the
drive is not mapped.

You might try using the UNC file paths (so,
\\servername\share\path\file.ext ).
Signature

Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
        PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)

ccjjharmon@gmail.com - 27 Mar 2006 13:52 GMT
Juha,

That was the first thing I came across in the newsgroups to try - using
the UNC path instead of the mapped drive. Unfortunately, I couldn't get
it to work at all... checking newsgroups again, I haven't tried using
runtime.exec() to make sure the drive is mapped...

But in all honesty, using the UNC path would be the more desirable
option in case the server (and/or share) changes I would rather be able
to dynamically deal with this change without needing to ensure the
mapped drive is changed also. Par for the course of this, it would be
*great* to know how I can provide the username and password to connect
to the UNC file path... but as far as I can tell, this isn't possible.

I believe it probably is some "quirk" that a Windows Java programmer
would quickly identify and know what they do to get past this... any
Windows Java programmers out there to chime in?

I am likely going to call a professor that is teaching an advanced Java
class I am taking (to get up to speed quicker on Java technology) - if
I get anywhere, I will post the news.

I am still hoping someone has some idea of what I can do though.

Chris
Chris Uppal - 27 Mar 2006 14:25 GMT
> But in all honesty, using the UNC path would be the more desirable
> option in case the server (and/or share) changes I would rather be able
> to dynamically deal with this change without needing to ensure the
> mapped drive is changed also. Par for the course of this, it would be
> *great* to know how I can provide the username and password to connect
> to the UNC file path... but as far as I can tell, this isn't possible.

I think you have to specify these as part of the service defintion, not of the
UNC filename.

Some stuff from MS:
http://msdn.microsoft.com/library/en-us/dllproc/base/service_user_accounts.asp

And this link may help (it's talking about a completely different service, but
the issues are the same):

http://www.monitorware.com/Common/en/FAQ/UNC-Path-Does-Not-Work-For-MWProducts.php

   -- chris
ccjjharmon@gmail.com - 27 Mar 2006 15:05 GMT
I found it.... I had actually saved a link to a Sun forums thread about
this topic, but had forgot about it.... the thread is available at:

http://forum.java.sun.com/thread.jspa?threadID=695024&tstart=0

The key point? UNC works, but you have to use it with URI when
specifying new File(). What I was doing was using the File()
constructor using String as a parameter. What I needed to do was use a
URI object as a parameter! Someone posted some sample code that worked
for this guy, and it worked for me too. Here's the sample code that did
it:

URI myURI = new URI( "file://///server_one/images/unitMaps" );
File myFile = new File( myURI );

Newsgroups are just grand :) especially when posters include sample
code!! ;)

I still have Tomcat running as Local System, but I must specify the
share to have Everyone with sufficient access. Obviously to properly
secure the share, I would want to have a specific domain user created,
and have the share configured with the desired access, and run Tomcat
as this domain user... that's for later.

Cheers! And thanks for the comments.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.