Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Transporteur

macrumors 68030
Original poster
Nov 30, 2008
2,729
3
UK
Hi guys

I'm doing some Java IO stuff at the moment, which is fine if you are working on a single computer with read/write access to every folder.

Assuming that I want to copy a file to a network folder that is mounted using the guest account, is there any option to open the OS X password dialog that asks for the correct username and password in order to get full access to that folder?

I don't want to mount the folders first using the finder, so a solution within my Java program would be nice.
 

Transporteur

macrumors 68030
Original poster
Nov 30, 2008
2,729
3
UK
Unfortunately I'm absolutely not familiar with the Terminal, especially when it comes to implement such commands in my Java code.

Isn't there a command Apple offers to open that Finder dialog that asks for permission to change the folder?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
The "Finder Dialog" is provided by Authorisation Services in OSX. It enables an application to get permission to and then actually perform a privileged action. In a normal OSX app you would just use this. There is no direct Java equivalent as this is platform specific. I would recommend writing a small tool that is OSX native in a native language (like Objective-C) to get access to this.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Authorization Services are normally the "right answer", but in this case the OP wants to get a username and password for a remote system. Escalating to a privileged local account isn't going to buy access to these remote resources. I'm unfamiliar with java gui programming, but i can only assume that there is a form of input that obscures what is being typed with bullets, etc. I would just get the password in there, username in a regular box.

Authorization Services are appropriate for local privilege escalation, and users will know what's going on... but Cyberduck, Transmit, etc. that need to connect to an FTP server just have a panel/text fields for you to enter authentication information.

-Lee
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Ah, yes, I see. I mis-read the original question. Once you get the username and password what are you going to do? Mount manually via a command-line tool?
 

Transporteur

macrumors 68030
Original poster
Nov 30, 2008
2,729
3
UK
I finally found it by accident last night at 4am.

Instead of choosing a file/directory using the java.swing JFileChooser, you have to use java.awt FileDialog.

Not only does it look like Apples native dialog, it supports Apples 'connect as...' feature which is exactly what I am looking for.

Thank you anyway for your support. Appreciate it!
 

Transporteur

macrumors 68030
Original poster
Nov 30, 2008
2,729
3
UK
I didn't know that.
I am not a subscribed developer yet (free though, but that doesn't really count), so it's pretty hard to get proper information, or do I miss a source on the Apple developers site?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
I didn't know that.
I am not a subscribed developer yet (free though, but that doesn't really count), so it's pretty hard to get proper information, or do I miss a source on the Apple developers site?

It's something I remember from way back when people wanted to get the OSX L&F from Java on the Mac on other platforms and it became clear that Sun couldn't do that as Apple had written it/owned the copyright to the Aqua L&F for AWT.
 

Transporteur

macrumors 68030
Original poster
Nov 30, 2008
2,729
3
UK
That definitely makes sense.
I just wasn't aware of that because I'm usually coding with Windows and there isn't any 'connect as...' feature implemented in the AWT FileDialog.

Is there any documentation about Apples own AWT?
 

pikester

macrumors newbie
Feb 27, 2009
27
0
One solution

You can use your own GUI to get a username, password, and (optionally) the domain. You can then pass this information to a Mac utility to mount the drive. Assuming that you are trying to mount a SMB drive (i.e. a Windows mount), you can try something like this:

Code:
// Mount the drive
String[] cmd1 = {"/sbin/mount_smbfs", "//domain;username:password@server/share", "/path/to/dir"};
Process p1 = Runtimee.getRuntime().exec(cmd1);
p1.waitFor();

// Copy the file...

// Unmount
String cmd2 = {"/sbin/umount", "/path/to/dir"};
Process p2 = Runtime.getRuntime().exec(cmd2);
p2.waitFor();

Note: If you don't need the domain, just leave off 'domain;' from the command.
 

Transporteur

macrumors 68030
Original poster
Nov 30, 2008
2,729
3
UK
That's very useful when it comes to port my program to the Windows platform as it's awt does not support the feature.
Thank you very much!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.