Re: Security Model?

From: Mike Kienenberger (mkienen..laska.net)
Date: Mon May 17 2004 - 16:24:31 EDT

  • Next message: Matt Kerr: "DataContext - invalidateAllObjects ?"

    Mehdi Bennani <mbennan..reebalance.com> wrote:

    > Another approach, simpler probably, would be to append the where clause to
    every single query against a specific objEntity. That would involve
    intercepting the queries to the all objEntity and applying this logic before
    executing the query. Is there a way to intercept the query to an objEntity?
    I was looking at the Observer..

    This is sometimes called a "restricting qualifier." There's recently been
    support for adding such a qualifier to your model, although I haven't used
    it. (1.1M5 and newer?) I don't know if it can be dynamically changed.

    You can also do so programmically by using DataContext's setDelegate()
    method and willPerformSelect().
    This was my implementation. Note that it doesn't work with prefetching.

            public GenericSelectQuery willPerformSelect(
                    DataContext aDataContext,
                    GenericSelectQuery aGenericSelectQuery)
            {
                    if (aGenericSelectQuery instanceof SelectQuery)
                    {
                            SelectQuery aSelectQuery = (SelectQuery)aGenericSelectQuery;
                            Object aSelectQueryRoot = aSelectQuery.getRoot();
                                            
                            if (aSelectQueryRoot instanceof Class)
                            {
                                    Class aClass = (Class)aSelectQueryRoot;
                                            
                                    Expression restrictingQualifer = getRestrictingQualifier(aClass);
                                    if (null != restrictingQualifer)
                                    {
                                            aSelectQuery.andQualifier(restrictingQualifer);
                                            return aSelectQuery;
                                    }
                            }
                            else if (aSelectQueryRoot instanceof ObjEntity)
                            {
                                    ObjEntity anObjEntity = (ObjEntity)aSelectQueryRoot;

                                    Expression restrictingQualifer =
    getRestrictingQualifier(anObjEntity.getJavaClass(anObjEntity.getClass().getClassLoader()));
                                    if (null != restrictingQualifer)
                                    {
                                            aSelectQuery.andQualifier(restrictingQualifer);
                                            return aSelectQuery;
                                    }

                            }
                    }

                    return aGenericSelectQuery;
            }



    This archive was generated by hypermail 2.0.0 : Mon May 17 2004 - 16:23:13 EDT