The Artima Developer Community
Sponsored Link

Java Buzz Forum
Drools Module for ObjectFilter

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
Drools Module for ObjectFilter Posted: Apr 30, 2004 11:05 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: Drools Module for ObjectFilter
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

Started generalizing ObjectFilter a little bit more by seperating out the rule providers. The style seen previous (manual rule implementation) has been moved into ManualRuleProvider, and I added a DroolsRuleProvider which uses Drools rules for access permissions, as follows:

    public void testSlightlyMoreComplexRools() throws Exception
    {
        Filter filter = Filter.instance();
        filter.configure(new DroolsRuleProvider(complex));
        filter.setActor(new Actor());

        Teacher mr_brown = new Teacher("Mr. Brown");
        ClassRoom english = new ClassRoom(mr_brown);
        assertEquals(mr_brown, english.getTeacher());

        ClassRoom maths = new ClassRoom(new Teacher("Mr. White"));
        assertNull(maths.getTeacher());
    }

Which looks pretty similar so far. The configure method was added to allow for plugging rule systems in. The complex argument is a java.net.URL pointing to the Drools ruleset.

The rule set for this example looks like:

<rule-set name="DroolsTest"
    xmlns="http://drools.org/rules"
    xmlns:java="http://drools.org/semantics/java">

    <rule name="Mr. Brown is Friendly">
        <parameter identifier="actor">
            <java:class>org.skife.objectfilter.drools.Actor</java:class>
        </parameter>
        <parameter identifier="response">
            <java:class>org.skife.objectfilter.drools.Response</java:class>
        </parameter>
        <parameter identifier="subject">
            <java:class>org.skife.objectfilter.Teacher</java:class>
        </parameter>

        <java:condition>
            subject.getName().equals("Mr. Brown")
        </java:condition>

        <java:consequence>
            response.setAllowed(true);
        </java:consequence>
    </rule>
    ...
    stuff removed
    ...
</rule-set>

The actor and instance being tested are bother asserted into the working memory (new working memory for each test, awkward, but I don't have a better solution in mind right now, any ideas?), rules are fired, and the response is tested to see if the access should be granted.

The response (which provides a way for the rules to tell the Filter what to do, and defaults to "false" to block access) can probably be moved to the ApplicationData bit of Drools, but I haven't done it yet and am getting sleepy =) I am, also, not fully satisfied with the Actor thing I used for this. In order to distinguish between Actor and Subject in the rule I made the actor a specific class -- this is probably how it w 1000 ill need to be done. Another option I am thinking about is to declare mixin tags for Actor or Subject types, but this seems much more intrusive.

I think for now users just need to be aware that there is no convenient way to distinguish between objects asserted as actors and objects asserted as subjects if their types overlap.

The source tarball for the changes has been posted =) Once again, it doesn't include the AspectJ jars as they are big.

Read: Drools Module for ObjectFilter

Topic: Enterprise Java 2 Security: Building Secure and Robust J2EE Applications - Book Review Previous Topic   Next Topic Topic: Integrating IntelliJ IDEA 4.0 and MacOSX Panther menu

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use