1 Reply Latest reply on Feb 22, 2010 2:42 PM by antibrumm.mfrey0.bluewin.ch

    Migration 2.0.1 -> 2.2.0 and Drools 5?

    antibrumm.mfrey0.bluewin.ch

      Hello


      I'm trying to upgrade one of our seam application from version 2.0.1.GA to 2.2.0.GA.


      The upgrading part of the libraries and the little adaptation of coding went like a charm until i reached the Drools part. I've realized that the s:hasPermission method has changed quite a lot. And the method does not behave at all as it was before. (Why is the method with 3.. parameters not deprecated btw?)


      Now i'm trying to adapt our restrictions to the new method with only 2 parameters, but in the old version we where able to inject additional objects into the workingmemory.


      Here's an example what is done in this application:




      #{s:hasPermission('scope','isAdmin', user, scope)}
      





      So my questiong is how do i get this migrated? I've tried to add some facthandles myself with routing all permission checks through a component and call the hasPermission(x,y) method after but i think i'm on the wrong track here.




      #{customPermissions.hasPermission('scope','isAdmin', user, scope)}
      




      Method:



           public boolean hasPermission(String target, String action, Object obj1, Object obj2) {
                FactHandle fh1 = null;
                FactHandle fh2 = null;
                try {
                     fh1 = securityRulesWorkingMemory.insert(obj1);
                     fh2 = securityRulesWorkingMemory.insert(obj2);
      
                     return identity.hasPermission(target, action);
                      } finally {
                     if (fh1 != null) {
                          securityRulesWorkingMemory.retract(fh1);
                     }
                     if (fh2 != null) {
                          securityRulesWorkingMemory.retract(fh2);
                     }
                }
      





      I haven't found a way yet how to migrate this properly and could use some help.


      Thanks alot for your help!

        • 1. Re: Migration 2.0.1 -> 2.2.0 and Drools 5?
          antibrumm.mfrey0.bluewin.ch

          Just to let you know that i solved it for now. I was working with an injected workingmemory which was not the session one. So here's the whole class.


          I know it's not the most performant way of doing it but at least it helps me going on with the migration...


          If anyone would have a better way of doing it please let me know!


          (We used the multiple hasPermission methods because it seems that EL is not able to map methods with varargs yet.)


          @Name("customPermissions")
          public class CustomPermissions {
          
               @In
               private Identity identity;
          
               private RuleBasedPermissionResolver ruleBasedPermissionResolver;
          
               private StatefulSession getSecurityContext() {
                    if (ruleBasedPermissionResolver == null) {
                         ruleBasedPermissionResolver = (RuleBasedPermissionResolver) Component.getInstance(RuleBasedPermissionResolver.class,
                                   ScopeType.SESSION);
                    }
                    return ruleBasedPermissionResolver.getSecurityContext();
               }
          
               public boolean hasPermission(String name, String action, Object obj1) {
                    List<FactHandle> handles = insert(obj1);
                    try {
                         return identity.hasPermission(name, action);
                    } finally {
                         retract(handles);
                    }
               }
          
               public boolean hasPermission(String name, String action, Object obj1, Object obj2) {
                    List<FactHandle> handles = insert(obj1, obj2);
                    try {
                         return identity.hasPermission(name, action);
                    } finally {
                         retract(handles);
                    }
               }
          
               public boolean hasPermission(String name, String action, Object obj1, Object obj2, Object obj3) {
                    List<FactHandle> handles = insert(obj1, obj2, obj3);
                    try {
                         return identity.hasPermission(name, action);
                    } finally {
                         retract(handles);
                    }
                  }
          
               private List<FactHandle> insert(Object... objects) {
                    StatefulSession securityRulesWorkingMemory = getSecurityContext();
                    List<FactHandle> handles = new ArrayList<FactHandle>();
                    for (Object obj : objects) {
                         handles.add(securityRulesWorkingMemory.insert(obj));
                    }
                    return handles;
               }
          
               private void retract(List<FactHandle> handles) {
                    StatefulSession securityRulesWorkingMemory = getSecurityContext();
                    for (FactHandle handle : handles) {
                         if (handle != null) {
                              securityRulesWorkingMemory.retract(handle);
                         }
                    }
               }
          }