This content has been marked as final.
Show 1 reply
-
1. Re: Migration 2.0.1 -> 2.2.0 and Drools 5?
antibrumm.mfrey0.bluewin.ch Feb 22, 2010 2:42 PM (in response to 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); } } } }