-->
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.  [ 2 posts ] 
Author Message
 Post subject: Multi Tenant resolving to wrong Tenant
PostPosted: Mon Oct 01, 2012 9:19 am 
Newbie

Joined: Mon Oct 01, 2012 7:22 am
Posts: 2
Hello.
I'm facing a problem implementing a Multi Tenant application with Hibernate 4.1.7 and EJB using GlassFish 3.1.2.
There's currently a class that implements org.hibernate.context.spi.CurrentTenantIdentifierResolver which identifies the logged in tenant fetching the logged in user with this code:
Code:
@Override
    public String resolveCurrentTenantIdentifier() {
        try {
            SessionContext context = ServiceLocator.locate(SessionEjbContext.class).getSessionContext();
                       
            String userName = context.getCallerPrincipal().getName();

            AppLogger.info("current tenant identifier [" + userName + "]");

            return userName;
        } catch (Throwable e) {
            AppLogger.info("erro lookup");
        }

        return "default";
    }

The SessionContext.class is implemented as such
Code:
@Stateful
@SessionScoped
public class SessionEjbContext {

    @Resource
    private SessionContext sessionContext;

    public SessionContext getSessionContext() {
        return sessionContext;
    }
}

The id is then provided to the class that extends org.hibernate.service.jdbc.connections.spi.AbstractMultiTenantConnectionProvider which implements the method ConnectionProvider selectConnectionProvider(String tenantIdentifier) and must return a c3p0 ConnectionProvider object to use.

The real problem is this:
When the user user1 autheticates the system, the db connection is resolved ok.
But when the user2 authenticates, the method ConnectionProvider selectConnectionProvider(String tenantIdentifier) receives as parameter user1, and not user2, leading us to select the same database as user1.

The EntityManager is implemented with the PersistenceContextType.EXTENDED annotation, is that causing the problem?
Any help is appreciated. If you need more details to help me out here, let me know.


Top
 Profile  
 
 Post subject: Re: Multi Tenant resolving to wrong Tenant
PostPosted: Wed Oct 03, 2012 7:37 am 
Newbie

Joined: Mon Oct 01, 2012 7:22 am
Posts: 2
Up!
So, what you guys think about it.
Is that some bug detected using EJB, JPA and Hibernate using a Java EE Server?
I got my app stuck on that issue, trying to resolve but no hope. The tenant identifier is not getting resolved correctly.
Thanks


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

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.