Unable to programmatically delete keystore file

Hi
I'm in the process of writing some junit tests for a Key Management helper class. What I want to do is initialise an empty keystore in setUp, add keys, get keys, delete keys, etc in the testXXX methods and delete the keystore file in tearDown. My tearDown looks like the following but is always failing as f.delete() is returning false (i.e. keystore file was not deleted).
     public void tearDown() {
          File f = new File(JUNIT_KEYSTORE);
          if(f.exists()) {
               if(f.delete() == false) {
                    fail("Unable to delete " + JUNIT_KEYSTORE);
          assertFalse(JUNIT_KEYSTORE + " exists.", new File(JUNIT_KEYSTORE).exists());
     }I'm working on WinXP with 1.4.1_06. When viewing the keystore file properties via explorer it is writeable, and I can delete the file manually. Also I can programatically delete other files, just not keystore files. My suspicion is that since the keystore is seen as such a sensitive and valuable resource that the java security model may be placing some restrictions on what operations can be performed on it through the File class API. However being a relative java.security novice, I would be grateful if someone more enlightened could provide some insight?
Thanks in advance
Rob

Hi
Adding the following lines to tearDown() indicates that the java security model is indeed preventing the keystore file from being deleted as an AccessControlException is being thrown. Note read and write are also blocked.
     FilePermission delete = new FilePermission(JUNIT_KEYSTORE, "delete");
     AccessController.checkPermission(delete);Next question : Is it possible to programmatically enable the 'delete' FilePermission? or can this only be done by adding a suitable entry to java.policy?
Rob

Similar Messages

  • My macbook pro inform that i am running out of disk space. However, I am unable to secure delete those files that are in Trash. Many files in Trash are "locked". how do I secure delete these files in trash

    I am unable to secure delete those files in the Trash. Many files are marked as "locked" Is this way I cannot secure delete these files?

    Can you not just select them and remove the locked flag?

  • Unable to programmatically rename a file using rename()

    I'm using a Javascript that will export as JPG a series of images from an AI file (that part is working fine), then rename them (that part isn't working). Writing and troubleshooting with Extendscript.
    Trying to eliminate as many possible places to go wrong, I came up with the following:
    myfile = new File; myfile = myfile.openDlg();
    var newName = "NEW.ai";
    myfile.rename(newName);
    When run targeting Illustrator, it does nothing.
    When run targeting ExtendScript, for some reason this blasts the file into oblivion, never to be found again.

    Hmmm, although I split the creation of a new file object into two steps, I wouldn't expect that to result in the file dissappearing on the rename step. Must be the difference between openDlg and openDialog...ah! According to the Javascript Reference, openDlg() returns an array while openDialog() returns the file.
    So I was renaming an array of files (even if there was only one file in the array), but since the old script didn't return an error when it ran (it just disappeared the file), it must have successfully written incomplete name data. I probably have a hidden file somewhere for each time the old script errored.
    Mark, it's always wonderful to learn something from you.

  • Unable to delete a file

    I'm unable to delete a a file from the filesystem.
    String fileName = "dummy.xml"
    boolean delete = (new File(fileName)).delete();It's not deleting this file from the filesystem.

    Can anything else delete that file? Is the fileopen?
    I don't know what you mean by can anything else
    delete the file.I mean can you delete the file from the command line, a window, whatever. Is it just Java's delete that is having this problem or is it the file system?
    No this is not opened/or use.How do you know?
    DO I have to specify a path for this. Certainly. How else would Java know which file to delete?
    If yes, please read on ........
    the path where this xml file resides could by
    anywhere in the file system. If it is how do I access
    it since there is no specific location (it is left to
    the user's choise to save the file anywhere he
    wants)Keep the user's choice.

  • I followed your help directions on "Corrupt extension files" under "Unable to install add-ons", foolishly deleting the files you told me to. Now firefox won't open. I tried reinstalling firefox but it still won't open. Now what do I do?

    I was trying to install the SEOQuake add on. After clicking install Firefox would hang up saying the script had timed out and asking if I want to stop it or continue. Didn't matter which option I chose nothing would happen. The only way to stop it was to close Firefox and restart. Tried restarting the computer. Still wouldn't install. Tried installing the Outwit add on and got the same error leading me to conclude it was a problem with Firefox, not the add on. I found this help page <http://support.mozilla.com/en-US/kb/Unable+to+install+add-ons?s=addons+won't+install&as=s> and did everything it told me to. Finally at the end I got to "Corrupt extension files". I foolishly deleted the files you told me to and now Firefox won't even start! I tried reinstalling Firefox and it still won't start. Tried restarting the computer. I have no idea how to get back to where I was let alone install the add ons I wanted to install. Please help. At this point I'd just be happy to be able to get Firefox working.

    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]
    You can use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    Create a new profile as a test to check if your current profile is causing the problems.<br />
    See [[Basic Troubleshooting#Make_a_new_profile|Basic Troubleshooting&#58; Make a new profile]]
    If that new profile works then you can transfer some files from the old profile to that new profile (be careful not to copy corrupted files)<br />
    See http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • Unable to delete a file on application server

    Hello Experts,
    I have gone through  couple of post and sample nothing worked that's the reason Iam posting a query here.
    Please help me with your valuable suggestions.
    I am reading a file from the application server running a BDC program to update my ztable all works fine.
    now i wanted to move this file to another folder thats too working perfectly but now when i try deleting the older one it is not getting deleted.
    I have closed the dataset and checked the authorization that is not a concern but still it is not getting deleted.
    I have pasted the code below.
    For READ and CLOSE dataset it returns subrc as 0 but after delete it returns 4.
    data : mess type string.
    OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT message mess.
    IF SY-SUBRC = 0.
    DO.
        READ DATASET ld_file INTO wa_string.
        if sy-subrc eq 0.
            append wa_string to it_string.
            clear wa_string.
        else.
            exit.
        endif.
      enddo.
      close dataset ld_file.
      delete dataset ld_file.
    else.
    WRITE 'Unable to open source file to move the content'.
    endif.
    Regards,
    Ranjith N

    Hello Mr Ghode,
    Thaking you for your response on my query.
    as you said to handle exception this is what i have done.
    kindly verify the same would be of great help.
    still iam unable to delete the file.  
    OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
      IF SY-SUBRC = 0.
        DO.
          READ DATASET ld_file INTO wa_string.        "LV_LINE is variable to hold line contents being read
          if sy-subrc eq 0.
            append wa_string to it_string.
            clear wa_string.
          else.
            exit.
          endif.
      enddo.
      close dataset ld_file.
      if sy-subrc eq 0.
      try.
        delete dataset ld_file.
        catch CX_dynamic_check into t_ref.
        err_txt = t_ref->get_longtext( ).
    endtry.
    endif.
    endif.
    Regards,
    Ranjith N

  • Unable to delete the file. (Some times deletes and sometime fails to delet)

    Please help me in deleting the file from the temporary location .
    Below is my code
    //Append the session is with filename as there is possibility of having same name of file.
    try{
    boolean isMultipart     = ServletFileUpload.isMultipartContent(request);
              if (isMultipart)
                   // Create a factory for disk-based file items
                   factory = new DiskFileItemFactory();
                            // Create a new file upload handler
                   upload = new ServletFileUpload(factory);
                   // Parse the request
                      List /* FileItem */ items = upload.parseRequest(request);
                           // Process the uploaded items
                   Iterator iter = items.iterator();
    if(strInputFileName.lastIndexOf("\\")== -1)
         strInputFileName = (String)mPropBag.get("TempUploadDirM") + strInputFileName;
      }else
         strInputFileName = (String)mPropBag.get("TempUploadDir") +   strInputFileName.substring(strInputFileName.lastIndexOf("\\"));
    strInputFileName = strInputFileName + "_" + request.getSession().getId();
    uploadedFile     = new File(strInputFileName);
    item.write(uploadedFile);  //// I am Writing the file in this location appened with the session Id because there might //be a  possibility of having same name of file.
    catch(......)
    finally
         uploadedFile.delete();
         uploadedFile = null;
         upload = null;
    }I am unable to delete the file from the temporary location
    some times it is deleting and some times it is not deleting.. I have also tried ...deleteOnExit();

    Make sure you've got no other processes holding onto it (Windows Explorer, for instance) and that you've closed any streams involved with the file. If that fails, try calling System.gc() just before deleting the file. This is a workaround for a bug in certain JVMs on Windows machines

  • Despite my best efforts, I am unable to remove iTunes 11.1.4 from my PC, this being made necessary because the original installation had a flaw and did not load properly. Effor to use the control panel, deleting dll. files, etc. all failed. iTune out??

    Despite my best efforts, I am unable to remove iTunes 11.1.4 from my PC, this being made necessary because the original installation had a flaw and did not load properly. Effor to use the control panel, deleting dll. files, etc. all failed. And, of course, on startup, a window opens with the error and tells me find QTMovie.dll and delete it because this may be the source of the hangup. Also, in trying to delete iTunes, I get the additional message that I must get approval from the System Administrator to take this action. I am the System Administrator.
    Any ideas would be welcomed.
    Thank you.
    James
    <E-mail Edited by Host>

    Thank you for asking this question.  I'm having the same issues. 
    Liz

  • Deleted backup files off seagate free agent disc and placed in trash.  Unable to now remove from trash.

    Deleted backup files off seagate free agent disc and placed in trash.  Unable to now remove from trash.

    Deleted backup files off seagate free agent disc and placed in trash.  Unable to now remove from trash.

  • Unable to move print to preview pane for printing in Lightroom 4.Tried deleting agprefs file and restart with no success! Thanks in advance.

    Unable to move print to preview pane for printing in Lightroom 4.Tried deleting agprefs file and restart with no success! Thanks in advance.

    Sorry to bump this - but does anyone have any idea what could be wrong?

  • Creating keystore file programmatically

    Hi,
    Wondering if you will be able to help me. I would like to find out how you can create a keystore file programmatically without using the keytool command.
    What I'm trying to do is generate KeyPairs for the SSL connections. After the keys are signed, I would like to insert the keys into a new keystore file. Is that possible and if it is do you perhaps know how?
    Thanks
    Julia

    Hi Julia,
    keytool does not allow you to import private keys into a keystore but, I bypassed this problem this way:
    after creating your key pair convert them into the pkcs12 format
    openssl pkcs12 -inkey privatekey.key -in certificate.crt -export -out somename.p12
    fortunately using the following code that was already posted in the forum, you will be able to create a new keystore with your private key :)
    import java.security.*;
    import java.io.*;
    // assumes you are using a 3rd party keystore library
    // for pkcs12 key stores. For some reason, JDK 1.4 won't
    // read pkcs12 files exported from MIE / Netscape
    class Convert {
    static public void main(String[] args) throws Exception {
    try {
    //pkcs12 keystore
    KeyStore ks = KeyStore.getInstance("pkcs12");
    //jks keystore
    KeyStore ks2 = KeyStore.getInstance("jks");
    // load the pkcs12 file
    ks.load(new FileInputStream("C:\\insurance.p12"),"insurance123".toCharArray());
    // load the jks file (have to have an existing one)
    ks2.load(new FileInputStream("C:\\.temp"),"temp123".toCharArray());
    //read the p12 certificate
    java.security.cert.Certificate [] cc = ks.getCertificateChain("1");
    //gets the private key having as alias "1" and as password "insurance123"
    Key k = ks.getKey("1", "insurance123".toCharArray());
    // add to keystore and save
    ks2.setKeyEntry("insurance", k, "insurance123".toCharArray(),cc);
    FileOutputStream out = new FileOutputStream("C:\\newstore.keystore");
    ks2.store(out, "insurance123".toCharArray());
    out.close();
    } catch (Throwable e) { e.printStackTrace(); } }
    } //end of the class
    the following call:
    ks2.load(new FileInputStream("C:\\.temp"),"temp123".toCharArray());
    assumes that you already created a keystore (.temp) having for password : temp123
    Hope this help :)
    KAnis

  • Need Help-SOA 11g File Adapter unable to delete input file and its crashing

    Hi All
    Please find the details below:
    1. We have created a simple SOA composite to Read file from an input directory, archive the file in an archive directory using Inbound File Adapter Read
    and then use Outbound File Adapter Write to move the file to a output directory.
    2. File Adapter needs to delete the file after successful read/retrieval.
    3. We are using the "Use Trigger File" for invoking the file adapter. This is a new feature in SOA 11g
    4. Also we are using the option of reading the file as an attachment as we are not doing any transformation in the composite
    Issue Details_
    1. When the trigger file is put in the input directory for the first time, the File Adapter reads the file, archives it and moves it to the output directory
    2. However it does not delete the input file from the input directory and raises Fatal Exception mentioned below:
    [*2011-01-12T16:55:48.639+05:30] [soa_server1] [WARNING] [] [oracle.soa.adapter] [tid: weblogic.work.j2ee.J2EEWorkManager$WorkWithListener@19c243d]*
    [userId: <anonymous>] [ecid: 0000IptyLrL9_aY5TrL6ic1DBOS_000009,0] [APP: soa-infra] File Adapter FileAdapterTriggerFilePOC PostProcessor::
    Delete failed, the operation will be retried for max of [0] times
    [2011-01-12T16:55:48.639+05:30] [soa_server1] [WARNING] [] [oracle.soa.adapter] [tid: weblogic.work.j2ee.J2EEWorkManager$WorkWithListener@19c243d]
    [userId: <anonymous>] [ecid: 0000IptyLrL9_aY5TrL6ic1DBOS_000009,0] [APP: soa-infra] File Adapter FileAdapterTriggerFilePOC [[
    BINDING.JCA-11042
    File deletion failed.
    File deletion failed.
    File : C:\Dibya\AttachmentTest\InputDir\TestFile3.txt could not be deleted.
    Delete the file and restart server. Contact oracle support if error is not fixable.
    If any one has faced similar issues, kindly provide pointers on how to resolve it.
    Regards,
    Dibya

    Hi,
    Using the file adapter, you can poll from multilple locations...
    Keep the following property in your .jca file
    <property name="DirectorySeparator" value="," />
    While giving the path in File Adapter configuration, keep comma and give the next location....then the file will be picked up from the locations you gave....
    Hope this helps...
    Thanks,
    N

  • Unable to delete a file from the downloads list of...

    i am an e7 user. I was recently downloading a couple of videos at the same time when my phone hanged and had to be restarted. When it did restart, most of the files had to be redownloaded. All except one. The downloads list claims that the file has been saved. The video plays bt isnt completely downloaded.
    The problem now is that i cant delete the video through the file manager. The error msg says web:already in use.. When i tried deleting the file from the downloads list of the web browser, there was a similar msg.
    So how do i remove this file from my phone??
    I tried downloading a couple of file managing softwares bt that didnt really help....
    Solved!
    Go to Solution.

    Retry after clearing the Browser Cache.. If that does not solve.. Reboot the phone and try again...

  • Unable to delete some files

    I have some audio files that appear only in smart lists and not in the library. You can't delete a file from a smart list view (correct me if I'm wrong) so you have to find it in the library to delete it.
    It doesn't appear in the library - so I cannot delete these files.
    I'm not sure how this happened but I have a theory. These all appear to be podcasts. Some are from audible but not all are. I think I may have deleted, or unsubscribed from the podcast in the podcast view but I didn't remove the files first. So it looks like the files are still around but since they are podcasts they don't appear in the library, and since the I'm not subscribed to the podcast they aren't in the podcast list either.
    Is there a way to get rid of these files? I thought of resubscribing to the podcasts but a lot of these I don't even remember what the podcast was.

    You can't delete a file from a smart list view (correct me if I'm wrong)
    Shift Delete.

  • Unable to delete the files from CSV volumes on HyperV Cluster

    Hello There,
    I have a HyperV failover cluster with CSV Volumes recently i moved some of the VMs to another cluster.
    VMs are moved but i still have the VM files on the CSV volumes which are occupying the disk space i tried to delete the VHD files / VM folders which are moved but it doesn't delete the files, please suggest.
    This file when i browse it from  a server and delete the file it disappears but when i revisit the folder i find the files still on the disk, i did try to delete the files directly
    from the server through command line as it is running server core.
    Regards,
    Maqsood
    Maqsood Mohammed Senior Systems Engineer MCITP-Enterprise Admin & ITILv3 Foundation Certified

    HyperV is good about not allowing you to delete files while they are still in use. You can try to reboot host, make sure all parts if your VM moved to the new location. If that VHD is associated with a VM on any host you will not be able to delete
    it. Delete the VM's that may have links to it. Not knowing you configuration could it be a parent disk?  Be carful because if you can't delete it it's likely in use, I've see VHD merge after you delete a VM too preventing you from deleting the files.
    You may just want to wait a day or so and see if it free's up. If it is doing a merge reboot will pause and restart it so you won't be able to remove until the merge is done, once you delete a VM and a merge starts there is no way to tell if it's merging,
    watch the size and timestamp of the VHD is it changing if it is something is using it.

Maybe you are looking for

  • Desktop freezes and hard drives failure

    Hey i faced a recent problem with my Computer, when i log in it freezes/crash i got told its due to my sound drive failuring, i tryed to download HP assistant to upgrade my sound drive but it cames up saying " Error 1719. windows installer service co

  • Recommended transition solution for ISP:s with enterprise customers?

    What would be the recommended solution(s) for ISP:s with enterprises only as customers? It both needs to support IPv6 and at the same time save IPv4 resources. Thanks in advance!

  • IPod classic digital out?

    The next generation of Kenwood car stereos features a "1-Wire" digital connection for the Classic: http://www.kenwood-electronics.co.uk/products/car/cd_receivers/KDC-W5541U/detail s/ The description on the German Kenwood website even says: "The (audi

  • Simultaneous multiple networks under access connections?

    I have two networks at home, one of which uses an ADSL internet connection the 2nd of which serves Network attached storage devices. Each network has a router. I want to use the wireless connection to connect to one network, and the ethernet con, for

  • EA1 - Code formatting "squishes" multiple queries together

    If you have more than 1 query in an SQL Worksheet and you "Format" (CTRL-F7) the query, then it removes all blank lines and bunches all of the queries together. I would have expected it to leave a blank line after each ";" so that the individual quer