0

Currently I have a java application, which Loads up an xml file, and presents a simple gui for a user to edit specific fields of the xml file. However, this xml will exist on a network path. The application loads and executes just fine as long as the user has already logged into the network location. However, if they have not specifically connected to the location, and are not "logged in", the application will not execute.

Is there any way I can for instance when loading the file, connect to the network path as a specific user?

Thanks for reading. Snippets of code below.

Sample Location (Ip address removed)

private static final String wg01x = "\\\\0.0.0.0\\d$\\Variable_Namedropper_XMLs\\WG01_Variable_NameDropper_XML\\VancInsertionLabelDatelineTC.xml";

Parser Constructor Snip

public Parser(String fp){

    // File Path Of XMl 
    try{
        this.setFilePath(fp);
    }catch(Exception e ){
        e.printStackTrace();
    }
    // Main DOM Object, Uses implicit FilePath 
    this.setDom(this.normalizeDocument());

normalizeDocument()

public Document normalizeDocument(){
     File xmlFile = new File(this.filePath);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder;

        try {
            dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(xmlFile);
            doc.getDocumentElement().normalize();
            return doc;

        }catch(Exception e){
            e.printStackTrace();
        }

Manifest

  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <assemblyIdentity version="1.1.1.1"
    processorArchitecture="X86"
    name="NameDropper_wg01Y.exe"
    type="win32"/>
   <description>NameDropper</description>
   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
     <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
       </requestedPrivileges>
      </security>
    </trustInfo>
   </assembly>  

Edit:: Alternate approaches are also welcome. I should be able to get access/ownership of the network location (possibly)

Busturdust
  • 2,447
  • 24
  • 41

2 Answers2

1

In general this is a bad idea... I'm just putting that out there because it might mess with the metadata or what have you.

But I'll still help because this is interesting. I believe it has to do with the File constructor on your normalizeDocument(). I've never done it myself but I did some searching and I think this might help you out.

Read remote file in java which needs username and password

Community
  • 1
  • 1
Syrrus
  • 79
  • 9
  • Thanks for your response, I will investigate further on that thread. For the issue with messing up metadata, how exactly would that happen? Theoretically I am just grabbing one file for editing, can you elaborate on security concerns if possible? – Busturdust Jun 26 '15 at 18:58
  • For instance, when something is edited usually a bit of data is stored saying who it was edited by, etc.. Additionally, now that you mention it for security concerns: since it's logging in programmatically I can think of many security concerns depending on the application and it's use of course. Then again I may be mistaking your question. – Syrrus Jun 26 '15 at 19:17
0

Although the Thread posted by @Syrrus was helpful and interesting from a conceptual level, I could not get it to work for my purposes.

However, I have come up with a workaround that is working! The updated code is below. The method instead of using Java objects, was to interact with the runtime environment and execute a cmd that connects to the location. The exec string is not properly formated in the example, as I am hiding the user info currently hardcoded into it

public Document normalizeDocument(){ File xmlFile = new File(this.filePath); connectToNetworkLocation();

     public void connectToNetworkLocation(){
       try{
        Process p = Runtime.getRuntime().exec("net use \\\\0.0.0.0\\c$ pword /USER:usr");
        p.waitFor();
        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

        String line;
        while((line = reader.readLine()) != null){
            System.out.println(line);
        }

    }catch(Exception e ){
        e.printStackTrace();
    }
}`
Busturdust
  • 2,447
  • 24
  • 41