Uploaded image for project: 'Shiro'
  1. Shiro
  2. SHIRO-394

PropertiesRealm reloading not working when loading from file

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.2.1
    • 1.2.2
    • Realms
    • None
    • All

    Description

      I use a PropertiesRealm with a file url. This works fine when initially loading the properties file. Yet I was puzzled to find out that reloading does not work.

      I debugged and found the problem:
      First of all the method isFileModified() checks for the lastModified date. Yet this returns 0 if the file does not exist. This is always the case when using the prefix "file:". Therefore the file was never reloaded because the reload file was checking the last modfied date of a file that was never there.

      I have several problems with that:
      1. Frankly speaking has anyone ever tested that stuff? To me it does not look like that and I think Shiro can do better.
      2. The isModified method should react if the file is not existing (any more). Because maybe someone deleted in by accident which causes problems for the next startup.
      3. The initial file loading and the reloading should use the same code. So at least then its clear that if the initial load succeeds so does the reloading.

      The quick fix is pretty straightforward - just remove the prefix "file:" from the resource path::
      private boolean isFileModified() {
      File propertyFile = new File(ResourceUtils.stripPrefix(this.resourcePath));
      long currentLastModified = propertyFile.lastModified();
      if (currentLastModified > this.fileLastModified)

      { this.fileLastModified = currentLastModified; return true; }

      else

      { return false; }

      }

      I will hopefully be able to supply a patch soon.

      Thanks,
      Jan

      Attachments

        Activity

          People

            Unassigned Unassigned
            remast Jan Stamer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: