2 Replies Latest reply on Apr 1, 2009 9:39 AM by vk101

    Very strange behavior with rules file

      Very strange behavior being observed with rules:


      rule Correct
      when
        identity : Identity()
      then
        System.out.println("Value of loggedIn is " + identity.isLoggedIn());
      end;
      
      rule UnexpectedOne
      when
        identity : Identity(loggedIn == false)
      then
        System.out.println("This means loggedIn is false");
      end;
      
      rule UnexpectedTwo
      when
        identity : Identity(loggedIn == true)
      then
        System.out.println("Should be output");
      end;



      The output is the following:


      Value of loggedIn is true
      This means loggedIn is false




      In the same moment, it sees loggedIn as true, then as false (when in fact it really is true). This is happening because the isLoggedIn() method of Identity is only executed once (for rule Correct)!


      That means for rule UnexpectedOne and UnexpectedTwo, it's not even executing the method. I created a subclass of RuleBasedIdentity and added a getLoggedIn() which simply calls through to isLoggedIn(), figuring that maybe the is- naming was causing it, but that didn't change anything.


      What's causing this?


      (I put the Identity into working memory at the end of my authenticate method, then I run identity.getSecurityContext().fireAllRules() in my org.jboss.seam.security.postAuthenticate event listener.)

        • 1. Re: Very strange behavior with rules file
          swd847

          What happens if you use the mvel dialect? Does it work then?(Put dialect mvel on the line after 'rule UnexpectedOne')


          • 2. Re: Very strange behavior with rules file

            Unfortunately, explicitly declaring mvel as the dialect doesn't change anything. However, the following does work:



            rule AnotherCorrect
            when
              identity : Identity()
              eval(identity.loggedIn)
            then
              System.out.println("This means loggedIn is true");
            end;




            The above rule is fired and the message is printed to the console, as expected. Why in the world does the first (below) not work but the second (below) work? According to the documentation and examples, both should work. The only thing in my security.drl that you don't see is a package declaration and the necessary imports - nothing more.


              identity : Identity(loggedIn == true)





              identity : Identity()
              eval(identity.loggedIn)



            Am I doing something wrong here, or is this as unexpected for you to see as it is for me? The file compiles fine, so I'm sure there's no problem with the syntax - what could be going on?