-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Interceptors to set a security context
PostPosted: Thu Oct 04, 2007 11:23 am 
Newbie

Joined: Tue Aug 14, 2007 9:39 am
Posts: 1
We have a requirment for partitioning data for certain clients via horizontal database partitioning - in other words we do not mix data in a table amongst clients so it is partitioned. How Oracle figures out which partition you need to query against is with a generic id (for our POC we call it Bank ID as shown in the code below).

The issue that we have is that we need to set a context on the actual Connection that Hibernate is going to use - as shown in the code below. The context essentially talks to a Policy Enforcement Point and gets the WHERE predicate for use (e.g. where bank id like so-and-so) this would get appended to the original sql query sent by Hibernate to Oracle and oracle VPD could then direct to the proper partition.

However this is a bit of a pain - as the goal is to make this as transaparent as possible, so we thought we could use an interceptor to force the setting of this context. However we have not identified any way of getting a handle on the session via an interceptor - is there a way?

Perhaps there is an easier way of accomplishing this setting of the context outside of interceptors?

Thanks in advance.

Hibernate version:
3.2.2 GA

Mapping documents:
Mapping problem not the issue - rather an architectural type of issues

Full stack trace of any exception that occurs:
none

Name and version of the database you are using:
Oracle 10g

Code between sessionFactory.openSession() and session.close():
Code:
SessionFactory factory = new Configuration().configure().buildSessionFactory();
        Session session = factory.openSession();
        Transaction tx = session.beginTransaction();

        // get handle to Connection from hibernate session
        Connection myConnection = session.connection();

        try
        {

            // *** set security context - username
            CallableStatement cs1 = myConnection.prepareCall("{call secpck.setsecctx(?,?)}");
            cs1.setString(1, "jdoe");
            cs1.setString(2, "test=test");
            cs1.execute();

            // execute hibernate query
            Criteria crit = session.createCriteria(Partition.class);
            List<Partition> partitions = crit.setMaxResults(10).list();
            tx.commit();

            for (Partition p : partitions)
            {
                System.out.println("ID:" + p.getId() + " Bank ID:" + p.getBankId() + " Timestamp:"
                    + p.getTimestamp().getTimeInMillis());
            }
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }

        session.close();
        factory.close();


[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.