I want to remove a File, when a Session is terminated, however, when trying to modify a File from the File System, I get a Notes Security Exception.
Here is what I have tried:
File f = getSourceFile();
f.delete(); // java.lang.SecurityException: Zugriff auf die Datei {0} bzw. diese zu ändern ist nicht zulässig (Accessing or modifiying this File is prohibited)
FileUtils.clearFile(f); // java.lang.IllegalStateException: NotesContext is not initialized for the Thread
This is how I retrieve my File:
public File getSourceFile() {
return new File(this.absolutePath);
}
I also tried using doPrivileged but that caused the same IllegalStateException:
AccessController.doPrivileged(new PrivilegedAction() { // java.lang.IllegalStateException: NotesContext is not initialized for the Thread
public Object run() {
File f = getSourceFile();
if(f.exists()){
FileUtil.deleteFile(f);
}
}
});
I guess it would be Possible to reinitialize the NotesContext somehow, but I don't think that would be an elegant solution.
The Stacktraces:
(Illegal State)
java.lang.IllegalStateException: NotesContext not initialized for the thread
at com.ibm.domino.xsp.module.nsf.NotesContext.getCurrent(NotesContext.java:123)
at com.ibm.domino.xsp.module.nsf.ModuleClassLoader$DynamicClassLoader.findClass(ModuleClassLoader.java:438)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:924)
at java.lang.ClassLoader.loadClass(ClassLoader.java:869)
at com.ibm.domino.xsp.module.nsf.ModuleClassLoader$DynamicClassLoader.loadClass(ModuleClassLoader.java:403)
at java.lang.ClassLoader.loadClass(ClassLoader.java:852)
at de.iV.beans.ticket.file.FileWrapper.clear(FileWrapper.java:90)
at de.iV.beans.ticket.Ticket.clearFiles(Ticket.java:155)
at de.iV.session.CustomSessionListener.sessionDestroyed(CustomSessionListener.java:46)
at com.ibm.xsp.application.ApplicationSessionListener.sessionDestroyed(ApplicationSessionListener.java:53)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.notifySessionRemoved(ComponentModule.java:370)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.checkSessionTimeout(ComponentModule.java:239)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.checkTimeout(NSFComponentModule.java:213)
at com.ibm.domino.xsp.module.nsf.NSFService.checkTimeout(NSFService.java:281)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.checkTimeout(LCDEnvironment.java:247)
at com.ibm.designer.runtime.domino.bootstrap.BootstrapEnvironment.tellCommand(BootstrapEnvironment.java:388)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.tell(XspCmdManager.java:92
(Security)
java.lang.SecurityException: Zugriff auf die Datei {0} bzw. diese zu ändern ist nicht zulässig
at lotus.notes.AgentSecurityManager.checkDelete(Unknown Source)
at java.io.File.delete(File.java:1047)
at de.iV.beans.ticket.file.FileWrapper.clear(FileWrapper.java:94)
at de.iV.beans.ticket.Ticket.clearFiles(Ticket.java:155)
at de.iV.session.CustomSessionListener.sessionDestroyed(CustomSessionListener.java:46)
at com.ibm.xsp.application.ApplicationSessionListener.sessionDestroyed(ApplicationSessionListener.java:53)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.notifySessionRemoved(ComponentModule.java:370)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.checkSessionTimeout(ComponentModule.java:239)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.checkTimeout(NSFComponentModule.java:213)
at com.ibm.domino.xsp.module.nsf.NSFService.checkTimeout(NSFService.java:281)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.checkTimeout(LCDEnvironment.java:247)
at com.ibm.designer.runtime.domino.bootstrap.BootstrapEnvironment.tellCommand(BootstrapEnvironment.java:388)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.tell(XspCmdManager.java:92)
I was not able to figure out a workaround.