Rechte bei Swing Applikation

Grayson

Grünschnabel
Hallo,

ich habe eine Swing Applikation geschrieben. Sie soll als "standalone Applikation" auf verschiedenen Windows-Rechnern und Mac-Rechnern laufen. Mit der Applikation greife ich lesend und schreibend auf eine Konfigurationsdatei im XML-Format zu. Die XML-Datei liegt immer im Benutzerprofil des angemeldeten Benutzers, damit ich die nötigen Rechte habe.

Nur leider funktioniert das so nicht ganz. Ich kriege beim Handling der XML-Datei immer eine AccessControlException. Ok, da habe ich natürlich recheriert und es kann daran liegen das die Applikation nicht signiert wurde. Kurz und bündig--> ich habs signiert und funktioniert immer noch nicht. Da steht zwar immer etwas von HTML, aber das habe ich immer übergangen, da mein Programm ja nicht im Browser laufen soll.

Frage: -Wie kann ich für mein Programm Vollzugriff auf die Dateien im angemeldeten
Benutzerprofil bekommen, ohne die Java-Policy zu verändern?
-Funktioniert die Signatur nur mit offiziellen Zertifikaten von VeriSign oder Thawte?
-Gibt es andere Möglichkeiten die Einstellungen eines Programmes zu verwalten,
bei denen der Stress mit den Zugriffsrechten wegfällt?
-MUSS ich eine eigene Policy-Datei haben?

Viele Grüße
 
Normalerweise haben "Standalone"-Java Programme keine Beschränkungen im Zugriff auf Dateien und/oder Ressourcen. Soweit ich weiß kann die Datei prinzipiell in jedem Verzeichnis liegen, solange der aktuelle Systembenutzer darauf Zugriff hat.

Signiert werden eigentlich nur Applets. Wie sieht denn der Code für den Dateizugriff aus?
 
Das ist die Klasse über die ich auf die XML zugreife.

Code:
public class GUIConfig {
	
	private static Document doc;
	
	public static String getURL(){
		if (loadXML()){
			Element root = doc.getRootElement();
			return root.getChild("URL").getText();
			
		}
		else{
			return "";
		}
	}
	
	public static void setURL(String url){
		String str = System.getProperty("user.home")+"\\config.xml";
		if (loadXML()){
			try{
			Element root = doc.getRootElement();
			root.getChild("URL").setText(url);
			XMLOutputter out = new XMLOutputter();
			out.output(doc, new FileOutputStream(str));
			}
			catch (Exception e){
				e.printStackTrace();
			}
		}
	}
	
	public static String getLanguage(){
		if (loadXML()){
			Element root = doc.getRootElement();
			return root.getChild("Language").getText();
			
		}
		else{
			return "";
		}
	}
	
	public static void setLanguage(String language){
		String str = System.getProperty("user.home")+"\\config.xml";
		if (loadXML()){
			try{
			Element root = doc.getRootElement();
			root.getChild("Language").setText(language);
			XMLOutputter out = new XMLOutputter();
			out.output(doc, new FileOutputStream(str));
			}
			catch (Exception e){
				e.printStackTrace();
			}
		}
	}
	
	public static String getCountry(){
		if (loadXML()){
			Element root = doc.getRootElement();
			return root.getChild("Country").getText();
			
		}
		else{
			return "";
		}
	}
	
	public static void setCountry(String country){
		String str = System.getProperty("user.home")+"\\config.xml";
		if (loadXML()){
			try{
			Element root = doc.getRootElement();
			root.getChild("Country").setText(country);
			XMLOutputter out = new XMLOutputter();
			out.output(doc, new FileOutputStream(str));
			}
			catch (Exception e){
				e.printStackTrace();
			}
		}
	}
	
	public static boolean loadXML(){
		String str = "file:///"+System.getProperty("user.home") + "\\config.xml";
				
		if (doc == null){
			
			SAXBuilder builder = new SAXBuilder();
			try {
				doc = builder.build(str);

				 return true;
			} catch (Exception e) {
				System.out.println("Fehler beim Laden der Konfigurationsdatei");
				return false;
			}
		}
		else
			return true;
	}
	
	public static void createXML(){
		String str = System.getProperty("user.home")+"\\config.xml";
		try{
			Element root = new Element("configuration");
			Document doc = new Document(root);
			root.addContent(new Element("URL"));
			root.addContent(new Element("Language"));
			root.addContent(new Element("Country"));
			Format f = Format.getPrettyFormat();
			XMLOutputter output = new XMLOutputter(f);
			FileOutputStream stream = new FileOutputStream(str);
			output.output(doc,stream);
			}
			catch(Exception e){
				e.printStackTrace();
			}
	}

Das ist die Fehlermeldung die ich bekomme, wenn ich die Jar über die Eingabeaufforderung ausführe.

Code:
java.security.AccessControlException: access denied (java.io.FilePermission C:\D
okumente und Einstellungen\SchwarzK\config.xml write)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkWrite(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at de.cromabase.gui.GUIConfig.setLanguage(GUIConfig.java:62)
        at de.cromabase.gui.SettingsWindow$3.actionPerformed(SettingsWindow.java
:273)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
java.security.AccessControlException: access denied (java.io.FilePermission C:\D
okumente und Einstellungen\SchwarzK\config.xml write)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkWrite(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at de.cromabase.gui.GUIConfig.setCountry(GUIConfig.java:88)
        at de.cromabase.gui.SettingsWindow$3.actionPerformed(SettingsWindow.java
:274)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
java.security.AccessControlException: access denied (java.io.FilePermission C:\D
okumente und Einstellungen\SchwarzK\config.xml write)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkWrite(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at de.cromabase.gui.GUIConfig.setLanguage(GUIConfig.java:62)
        at de.cromabase.gui.SettingsWindow$3.actionPerformed(SettingsWindow.java
:281)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
java.security.AccessControlException: access denied (java.io.FilePermission C:\D
okumente und Einstellungen\SchwarzK\config.xml write)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkWrite(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at de.cromabase.gui.GUIConfig.setCountry(GUIConfig.java:88)
        at de.cromabase.gui.SettingsWindow$3.actionPerformed(SettingsWindow.java
:282)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
java.security.AccessControlException: access denied (java.io.FilePermission C:\D
okumente und Einstellungen\SchwarzK\config.xml write)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkWrite(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at de.cromabase.gui.GUIConfig.setURL(GUIConfig.java:36)
        at de.cromabase.gui.SettingsWindow$3.actionPerformed(SettingsWindow.java
:294)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.security.AccessControlException: acc
ess denied (java.io.FilePermission C:\Dokumente und Einstellungen\SchwarzK\confi
g.xml read)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkRead(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileReader.<init>(Unknown Source)
        at de.cromabase.gui.GUI.main(GUI.java:126)
        at de.cromabase.gui.SettingsWindow$3.actionPerformed(SettingsWindow.java
:301)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

Ich hatte es auch so verstanden das nur bei Applets eine Signierung für den Vollzugriff notwendig ist. Deshalb bin ich grad verwirrt und weiß nicht genau woran es liegt.

Ich will doch einfach nur lesend und schreibend auf die XML im Benutzerprofil zugreifen. :suspekt:
 
Also das ist in der Tat mal seltsam :confused:
Die letzte Exception geht von "de.cromabase.gui.GUI.main(GUI.java:126)" aus.
Evtl. ist die Datei noch von einer anderen Klasse geöffnet und wird gesperrt.
 
Vielleicht liegt es an den URL-Objekten... schon versucht mit normalen Pfaden zu arbeiten?! Nur so ein Gedanke...
 
Zurück