Finder password dialog with Java

Discussion in 'Mac Programming' started by Transporteur, Nov 2, 2009.

  1. Transporteur
    Expand Collapse
    macrumors 68030

    Joined:
    Nov 30, 2008
    Location:
    UK
    #1
    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.
     
  2. chown33
    Expand Collapse
    macrumors 604

    Joined:
    Aug 9, 2009
    #2
  3. Transporteur
    Expand Collapse
    thread starter macrumors 68030

    Joined:
    Nov 30, 2008
    Location:
    UK
    #3
    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?
     
  4. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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.
     
  5. chown33
    Expand Collapse
    macrumors 604

    Joined:
    Aug 9, 2009
  6. lee1210
    Expand Collapse
    macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    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
     
  7. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    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?
     
  8. Transporteur
    Expand Collapse
    thread starter macrumors 68030

    Joined:
    Nov 30, 2008
    Location:
    UK
    #8
    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!
     
  9. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #9
    That may be because Apple supply a custom AWT for Mac OSX...
     
  10. Transporteur
    Expand Collapse
    thread starter macrumors 68030

    Joined:
    Nov 30, 2008
    Location:
    UK
    #10
    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?
     
  11. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #11
    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.
     
  12. Transporteur
    Expand Collapse
    thread starter macrumors 68030

    Joined:
    Nov 30, 2008
    Location:
    UK
    #12
    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?
     
  13. pikester
    Expand Collapse
    macrumors newbie

    pikester

    Joined:
    Feb 27, 2009
    #13
    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.
     
  14. Transporteur
    Expand Collapse
    thread starter macrumors 68030

    Joined:
    Nov 30, 2008
    Location:
    UK
    #14
    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!
     

Share This Page