How to get a CoreSession within a SecurityPolicy SQLQuery.Transformer.transform()?

I need to access the CoreSession for the Principal passed as a parameter into SQLQuery.Transformer.transform(Principal, SQLQuery). I was hoping that ((NuxeoPrincipal) principal).getModel().getCoreSession() would provide it but it is almost always null. Is there another way besides creating a new CoreSession?

0 votes

2 answers

528 views

ANSWER



No CoreSession is available at this level, because the query transformers are called at a lower-level API level than CoreSession (from the QueryMakers inside VCS).

1 votes



rg1
I need to access specific properties from the principal's UserProfile document from within my query transformer. Do you have a recommendation for how this would best be done?
06/19/2013

What properties do you need to access?
06/20/2013

rg1
My own custom properties.
06/20/2013

The solution would be to update the Principal object directly with the properties you need at login, when the Principal is created. See how the MultiTenantUserManager does it for instance, to use another class than NuxeoPrincipalImpl.
06/20/2013


You can use for instance the following code:

LoginContext loginContext = Framework.login();
RepositoryManager mgr = Framework.getService(RepositoryManager.class);
Repository repository = mgr.getDefaultRepository();
CoreSession session = null;
if (repository != null) {
    session = repository.open();
}
if (session == null) {
    log.error("session is null, exit connect");
}
-1 votes



rg1
I believe your code is creating a new CoreSession which I was hoping to avoid. Instead I would like to access the existing CoreSession already associated with the Principal.
06/12/2013